Documentation
¶
Overview ¶
Package gae provides Google Cloud Datastore implementations of oneauth store interfaces. It is designed for deployment on Google Cloud Platform and supports multi-tenancy through Datastore namespaces.
Datastore Kinds ¶
The package uses the following Datastore kinds:
- User: User accounts with profile data
- Identity: Email/phone identities linked to users
- Channel: Authentication channels (local, google, github, etc.)
- AuthToken: Verification and password reset tokens
- RefreshToken: Long-lived refresh tokens for API access
- APIKey: Long-lived API keys for programmatic access
Namespacing ¶
All stores support Datastore namespaces for multi-tenant applications. Pass a namespace when creating stores to isolate data between tenants:
userStore := gae.NewUserStore(client, "tenant-123") tokenStore := gae.NewRefreshTokenStore(client, "tenant-123")
Usage ¶
client, _ := datastore.NewClient(ctx, projectID) userStore := gae.NewUserStore(client, "") // default namespace refreshTokenStore := gae.NewRefreshTokenStore(client, "") apiKeyStore := gae.NewAPIKeyStore(client, "")
Index ¶
- Constants
- type APIKeyEntity
- type APIKeyStore
- func (s *APIKeyStore) CreateAPIKey(userID, name string, scopes []string, expiresAt *time.Time) (string, *oa.APIKey, error)
- func (s *APIKeyStore) GetAPIKeyByID(keyID string) (*oa.APIKey, error)
- func (s *APIKeyStore) ListUserAPIKeys(userID string) ([]*oa.APIKey, error)
- func (s *APIKeyStore) RevokeAPIKey(keyID string) error
- func (s *APIKeyStore) UpdateAPIKeyLastUsed(keyID string) error
- func (s *APIKeyStore) ValidateAPIKey(fullKey string) (*oa.APIKey, error)
- func (s *APIKeyStore) WithContext(ctx context.Context) *APIKeyStore
- type AuthTokenEntity
- type ChannelEntity
- type ChannelStore
- func (s *ChannelStore) GetChannel(provider string, identityKey string, createIfMissing bool) (*oa.Channel, bool, error)
- func (s *ChannelStore) GetChannelsByIdentity(identityKey string) ([]*oa.Channel, error)
- func (s *ChannelStore) SaveChannel(channel *oa.Channel) error
- func (s *ChannelStore) WithContext(ctx context.Context) *ChannelStore
- type GAEUser
- type IdentityEntity
- type IdentityStore
- func (s *IdentityStore) GetIdentity(identityType, identityValue string, createIfMissing bool) (*oa.Identity, bool, error)
- func (s *IdentityStore) GetUserIdentities(userId string) ([]*oa.Identity, error)
- func (s *IdentityStore) MarkIdentityVerified(identityType, identityValue string) error
- func (s *IdentityStore) SaveIdentity(identity *oa.Identity) error
- func (s *IdentityStore) SetUserForIdentity(identityType, identityValue string, newUserId string) error
- func (s *IdentityStore) WithContext(ctx context.Context) *IdentityStore
- type RefreshTokenEntity
- type RefreshTokenStore
- func (s *RefreshTokenStore) CleanupExpiredTokens() error
- func (s *RefreshTokenStore) CreateRefreshToken(userID, clientID string, deviceInfo map[string]any, scopes []string) (*oa.RefreshToken, error)
- func (s *RefreshTokenStore) GetRefreshToken(token string) (*oa.RefreshToken, error)
- func (s *RefreshTokenStore) GetUserTokens(userID string) ([]*oa.RefreshToken, error)
- func (s *RefreshTokenStore) RevokeRefreshToken(token string) error
- func (s *RefreshTokenStore) RevokeTokenFamily(family string) error
- func (s *RefreshTokenStore) RevokeUserTokens(userID string) error
- func (s *RefreshTokenStore) RotateRefreshToken(oldToken string) (*oa.RefreshToken, error)
- func (s *RefreshTokenStore) WithContext(ctx context.Context) *RefreshTokenStore
- type TokenStore
- func (s *TokenStore) CreateToken(userID, email string, tokenType oa.TokenType, expiryDuration time.Duration) (*oa.AuthToken, error)
- func (s *TokenStore) DeleteToken(token string) error
- func (s *TokenStore) DeleteUserTokens(userID string, tokenType oa.TokenType) error
- func (s *TokenStore) GetToken(token string) (*oa.AuthToken, error)
- func (s *TokenStore) WithContext(ctx context.Context) *TokenStore
- type UserEntity
- type UserStore
Constants ¶
const ( KindUser = "User" KindIdentity = "Identity" KindChannel = "Channel" KindAuthToken = "AuthToken" KindRefreshToken = "RefreshToken" KindAPIKey = "APIKey" )
Kind constants for Datastore entities
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIKeyEntity ¶
type APIKeyEntity struct {
Key *datastore.Key `datastore:"__key__"` // Key is the KeyID
KeyHash string `datastore:"key_hash,noindex"`
UserID string `datastore:"user_id"`
Name string `datastore:"name"`
Scopes []byte `datastore:"scopes,noindex"` // JSON encoded
CreatedAt time.Time `datastore:"created_at"`
ExpiresAt time.Time `datastore:"expires_at,omitempty"`
HasExpiry bool `datastore:"has_expiry"`
LastUsedAt time.Time `datastore:"last_used_at"`
RevokedAt time.Time `datastore:"revoked_at,omitempty"`
Revoked bool `datastore:"revoked"`
}
APIKeyEntity is the Datastore entity for API keys
type APIKeyStore ¶
type APIKeyStore struct {
// contains filtered or unexported fields
}
APIKeyStore implements oa.APIKeyStore using Google Cloud Datastore
func NewAPIKeyStore ¶
func NewAPIKeyStore(client *datastore.Client, namespace string) *APIKeyStore
NewAPIKeyStore creates a new Datastore-backed APIKeyStore
func (*APIKeyStore) CreateAPIKey ¶
func (*APIKeyStore) GetAPIKeyByID ¶
func (s *APIKeyStore) GetAPIKeyByID(keyID string) (*oa.APIKey, error)
func (*APIKeyStore) ListUserAPIKeys ¶
func (s *APIKeyStore) ListUserAPIKeys(userID string) ([]*oa.APIKey, error)
func (*APIKeyStore) RevokeAPIKey ¶
func (s *APIKeyStore) RevokeAPIKey(keyID string) error
func (*APIKeyStore) UpdateAPIKeyLastUsed ¶
func (s *APIKeyStore) UpdateAPIKeyLastUsed(keyID string) error
func (*APIKeyStore) ValidateAPIKey ¶
func (s *APIKeyStore) ValidateAPIKey(fullKey string) (*oa.APIKey, error)
func (*APIKeyStore) WithContext ¶
func (s *APIKeyStore) WithContext(ctx context.Context) *APIKeyStore
type AuthTokenEntity ¶
type AuthTokenEntity struct {
Key *datastore.Key `datastore:"__key__"`
Type oa.TokenType `datastore:"type"`
UserID string `datastore:"user_id"`
Email string `datastore:"email"`
CreatedAt time.Time `datastore:"created_at"`
ExpiresAt time.Time `datastore:"expires_at"`
}
AuthTokenEntity is the Datastore entity for verification/reset tokens
func AuthTokenToEntity ¶
func AuthTokenToEntity(t *oa.AuthToken, key *datastore.Key) *AuthTokenEntity
func (*AuthTokenEntity) ToAuthToken ¶
func (e *AuthTokenEntity) ToAuthToken() *oa.AuthToken
type ChannelEntity ¶
type ChannelEntity struct {
Key *datastore.Key `datastore:"__key__"`
Provider string `datastore:"provider"`
IdentityKey string `datastore:"identity_key"`
Credentials []byte `datastore:"credentials,noindex"` // JSON encoded
Profile []byte `datastore:"profile,noindex"` // JSON encoded
CreatedAt time.Time `datastore:"created_at"`
UpdatedAt time.Time `datastore:"updated_at"`
}
ChannelEntity is the Datastore entity for authentication channels Key format: Provider + ":" + IdentityKey
type ChannelStore ¶
type ChannelStore struct {
// contains filtered or unexported fields
}
ChannelStore implements oa.ChannelStore using Google Cloud Datastore
func NewChannelStore ¶
func NewChannelStore(client *datastore.Client, namespace string) *ChannelStore
NewChannelStore creates a new Datastore-backed ChannelStore
func (*ChannelStore) GetChannel ¶
func (*ChannelStore) GetChannelsByIdentity ¶
func (s *ChannelStore) GetChannelsByIdentity(identityKey string) ([]*oa.Channel, error)
func (*ChannelStore) SaveChannel ¶
func (s *ChannelStore) SaveChannel(channel *oa.Channel) error
func (*ChannelStore) WithContext ¶
func (s *ChannelStore) WithContext(ctx context.Context) *ChannelStore
type GAEUser ¶
type GAEUser struct {
UserID string `json:"user_id"`
Active bool `json:"is_active"`
UserProfile map[string]any `json:"profile"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
GAEUser implements the oa.User interface
type IdentityEntity ¶
type IdentityEntity struct {
Key *datastore.Key `datastore:"__key__"`
Type string `datastore:"type"`
Value string `datastore:"value"`
UserID string `datastore:"user_id"`
Verified bool `datastore:"verified"`
CreatedAt time.Time `datastore:"created_at"`
}
IdentityEntity is the Datastore entity for identities Key format: Type + ":" + Value
func IdentityToEntity ¶
func IdentityToEntity(i *oa.Identity, key *datastore.Key) *IdentityEntity
func (*IdentityEntity) ToIdentity ¶
func (e *IdentityEntity) ToIdentity() *oa.Identity
type IdentityStore ¶
type IdentityStore struct {
// contains filtered or unexported fields
}
IdentityStore implements oa.IdentityStore using Google Cloud Datastore
func NewIdentityStore ¶
func NewIdentityStore(client *datastore.Client, namespace string) *IdentityStore
NewIdentityStore creates a new Datastore-backed IdentityStore
func (*IdentityStore) GetIdentity ¶
func (*IdentityStore) GetUserIdentities ¶
func (s *IdentityStore) GetUserIdentities(userId string) ([]*oa.Identity, error)
func (*IdentityStore) MarkIdentityVerified ¶
func (s *IdentityStore) MarkIdentityVerified(identityType, identityValue string) error
func (*IdentityStore) SaveIdentity ¶
func (s *IdentityStore) SaveIdentity(identity *oa.Identity) error
func (*IdentityStore) SetUserForIdentity ¶
func (s *IdentityStore) SetUserForIdentity(identityType, identityValue string, newUserId string) error
func (*IdentityStore) WithContext ¶
func (s *IdentityStore) WithContext(ctx context.Context) *IdentityStore
type RefreshTokenEntity ¶
type RefreshTokenEntity struct {
Key *datastore.Key `datastore:"__key__"` // Key is the token hash
UserID string `datastore:"user_id"`
ClientID string `datastore:"client_id,omitempty"`
DeviceInfo []byte `datastore:"device_info,noindex"` // JSON encoded
Family string `datastore:"family"`
Generation int `datastore:"generation"`
Scopes []byte `datastore:"scopes,noindex"` // JSON encoded
CreatedAt time.Time `datastore:"created_at"`
ExpiresAt time.Time `datastore:"expires_at"`
LastUsedAt time.Time `datastore:"last_used_at"`
RevokedAt time.Time `datastore:"revoked_at,omitempty"`
Revoked bool `datastore:"revoked"`
}
RefreshTokenEntity is the Datastore entity for refresh tokens
type RefreshTokenStore ¶
type RefreshTokenStore struct {
// contains filtered or unexported fields
}
RefreshTokenStore implements oa.RefreshTokenStore using Google Cloud Datastore
func NewRefreshTokenStore ¶
func NewRefreshTokenStore(client *datastore.Client, namespace string) *RefreshTokenStore
NewRefreshTokenStore creates a new Datastore-backed RefreshTokenStore
func (*RefreshTokenStore) CleanupExpiredTokens ¶
func (s *RefreshTokenStore) CleanupExpiredTokens() error
func (*RefreshTokenStore) CreateRefreshToken ¶
func (s *RefreshTokenStore) CreateRefreshToken(userID, clientID string, deviceInfo map[string]any, scopes []string) (*oa.RefreshToken, error)
func (*RefreshTokenStore) GetRefreshToken ¶
func (s *RefreshTokenStore) GetRefreshToken(token string) (*oa.RefreshToken, error)
func (*RefreshTokenStore) GetUserTokens ¶
func (s *RefreshTokenStore) GetUserTokens(userID string) ([]*oa.RefreshToken, error)
func (*RefreshTokenStore) RevokeRefreshToken ¶
func (s *RefreshTokenStore) RevokeRefreshToken(token string) error
func (*RefreshTokenStore) RevokeTokenFamily ¶
func (s *RefreshTokenStore) RevokeTokenFamily(family string) error
func (*RefreshTokenStore) RevokeUserTokens ¶
func (s *RefreshTokenStore) RevokeUserTokens(userID string) error
func (*RefreshTokenStore) RotateRefreshToken ¶
func (s *RefreshTokenStore) RotateRefreshToken(oldToken string) (*oa.RefreshToken, error)
func (*RefreshTokenStore) WithContext ¶
func (s *RefreshTokenStore) WithContext(ctx context.Context) *RefreshTokenStore
type TokenStore ¶
type TokenStore struct {
// contains filtered or unexported fields
}
TokenStore implements oa.TokenStore using Google Cloud Datastore
func NewTokenStore ¶
func NewTokenStore(client *datastore.Client, namespace string) *TokenStore
NewTokenStore creates a new Datastore-backed TokenStore
func (*TokenStore) CreateToken ¶
func (*TokenStore) DeleteToken ¶
func (s *TokenStore) DeleteToken(token string) error
func (*TokenStore) DeleteUserTokens ¶
func (s *TokenStore) DeleteUserTokens(userID string, tokenType oa.TokenType) error
func (*TokenStore) WithContext ¶
func (s *TokenStore) WithContext(ctx context.Context) *TokenStore
type UserEntity ¶
type UserEntity struct {
Key *datastore.Key `datastore:"__key__"`
IsActive bool `datastore:"is_active"`
Profile []byte `datastore:"profile,noindex"` // JSON encoded
CreatedAt time.Time `datastore:"created_at"`
UpdatedAt time.Time `datastore:"updated_at"`
}
UserEntity is the Datastore entity for users
type UserStore ¶
type UserStore struct {
// contains filtered or unexported fields
}
UserStore implements oa.UserStore using Google Cloud Datastore
func NewUserStore ¶
NewUserStore creates a new Datastore-backed UserStore