Documentation
¶
Index ¶
- Variables
- type AccountType
- type Adapter
- type GothAccount
- type GothCsrfToken
- type GothSession
- type GothUser
- type GothVerificationToken
- type UnimplementedAdapter
- func (a *UnimplementedAdapter) CreateSession(_ context.Context, userID uuid.UUID, expires time.Time) (GothSession, error)
- func (a *UnimplementedAdapter) CreateUser(_ context.Context, user GothUser) (GothUser, error)
- func (a *UnimplementedAdapter) CreateVerificationToken(_ context.Context, erficationToken GothVerificationToken) (GothVerificationToken, error)
- func (a *UnimplementedAdapter) DeleteSession(_ context.Context, sessionToken string) error
- func (a *UnimplementedAdapter) DeleteUser(_ context.Context, id uuid.UUID) error
- func (a *UnimplementedAdapter) GetSession(_ context.Context, sessionToken string) (GothSession, error)
- func (a *UnimplementedAdapter) GetUser(_ context.Context, id uuid.UUID) (GothUser, error)
- func (a *UnimplementedAdapter) GetUserByAccount(_ context.Context, provider string, providerAccountID string) (GothUser, error)
- func (a *UnimplementedAdapter) GetUserByEmail(_ context.Context, email string) (GothUser, error)
- func (a *UnimplementedAdapter) LinkAccount(_ context.Context, accountID, userID uuid.UUID) error
- func (a *UnimplementedAdapter) RefreshSession(_ context.Context, session GothSession) (GothSession, error)
- func (a *UnimplementedAdapter) UnlinkAccount(_ context.Context, accountID, userID uuid.UUID) error
- func (a *UnimplementedAdapter) UpdateSession(_ context.Context, session GothSession) (GothSession, error)
- func (a *UnimplementedAdapter) UpdateUser(_ context.Context, user GothUser) (GothUser, error)
- func (a *UnimplementedAdapter) UseVerficationToken(_ context.Context, identifier string, token string) (GothVerificationToken, error)
Constants ¶
This section is empty.
Variables ¶
var ErrUnimplemented = errors.New("not implemented")
ErrUnimplemented is returned when a method is not implemented.
Functions ¶
This section is empty.
Types ¶
type AccountType ¶
type AccountType string
AccountType represents the type of an account.
const ( // AccountTypeOAuth2 represents an OAuth2 account type. AccountTypeOAuth2 AccountType = "oauth2" // AccountTypeOIDC represents an OIDC account type. AccountTypeOIDC AccountType = "oidc" // AccountTypeSAML represents a SAML account type. AccountTypeSAML AccountType = "saml" // AccountTypeEmail represents an email account type. AccountTypeEmail AccountType = "email" // AccountTypeWebAuthn represents a WebAuthn account type. AccountTypeWebAuthn AccountType = "webauthn" )
type Adapter ¶
type Adapter interface {
// CreateUser creates a new user.
CreateUser(ctx context.Context, user GothUser) (GothUser, error)
// GetUser retrieves a user by ID.
GetUser(ctx context.Context, id uuid.UUID) (GothUser, error)
// GetUserByEmail retrieves a user by email.
GetUserByEmail(ctx context.Context, email string) (GothUser, error)
// UpdateUser updates a user.
UpdateUser(ctx context.Context, user GothUser) (GothUser, error)
// DeleteUser deletes a user by ID.
DeleteUser(ctx context.Context, id uuid.UUID) error
// LinkAccount links an account to a user.
LinkAccount(ctx context.Context, accountID, userID uuid.UUID) error
// UnlinkAccount unlinks an account from a user.
UnlinkAccount(ctx context.Context, accountID, userID uuid.UUID) error
// CreateSession creates a new session.
CreateSession(ctx context.Context, userID uuid.UUID, expires time.Time) (GothSession, error)
// GetSession retrieves a session by session token.
GetSession(ctx context.Context, sessionToken string) (GothSession, error)
// UpdateSession updates a session.
UpdateSession(ctx context.Context, session GothSession) (GothSession, error)
// RefreshSession refreshes a session.
RefreshSession(ctx context.Context, session GothSession) (GothSession, error)
// DeleteSession deletes a session by session token.
DeleteSession(ctx context.Context, sessionToken string) error
// CreateVerificationToken creates a new verification token.
CreateVerificationToken(ctx context.Context, verficationToken GothVerificationToken) (GothVerificationToken, error)
// UseVerficationToken uses a verification token.
UseVerficationToken(ctx context.Context, identifier string, token string) (GothVerificationToken, error)
}
Adapter is an interface that defines the methods for interacting with the underlying data storage.
type GothAccount ¶ added in v1.2.1
type GothAccount struct {
// ID is the unique identifier of the account.
ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;column:id;default:gen_random_uuid();"`
// Type is the type of the account.
Type AccountType `json:"type" validate:"required"`
// Provider is the provider of the account.
Provider string `json:"provider" validate:"required"`
// ProviderAccountID is the account ID in the provider.
ProviderAccountID *string `json:"provider_account_id"`
// RefreshToken is the refresh token of the account.
RefreshToken *string `json:"refresh_token"`
// AccessToken is the access token of the account.
AccessToken *string `json:"access_token"`
// ExpiresAt is the expiry time of the account.
ExpiresAt *time.Time `json:"expires_at"`
// TokenType is the token type of the account.
TokenType *string `json:"token_type"`
// Scope is the scope of the account.
Scope *string `json:"scope"`
// IDToken is the ID token of the account.
IDToken *string `json:"id_token"`
// SessionState is the session state of the account.
SessionState string `json:"session_state"`
// UserID is the user ID of the account.
UserID *uuid.UUID `json:"user_id"`
// User is the user of the account.
User GothUser `json:"user" gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE"`
// CreatedAt is the creation time of the account.
CreatedAt time.Time `json:"created_at"`
// UpdatedAt is the update time of the account.
UpdatedAt time.Time `json:"updated_at"`
// DeletedAt is the deletion time of the account.
DeletedAt gorm.DeletedAt `json:"deleted_at"`
}
GothAccount represents an account in a third-party identity provider.
type GothCsrfToken ¶ added in v1.2.5
type GothCsrfToken struct {
// ID is the unique identifier of the CSRF token.
ID uuid.UUID `json:"id" gorm:"primaryKey;unique;type:uuid;column:id;default:gen_random_uuid()"`
// Token is the unique identifier of the token.
Token string `json:"token"`
// ExpiresAt is the expiry time of the token.
ExpiresAt time.Time `json:"expires_at"`
// CreatedAt is the creation time of the token.
CreatedAt time.Time `json:"created_at"`
// UpdatedAt is the update time of the token.
UpdatedAt time.Time `json:"updated_at"`
// DeletedAt is the deletion time of the token.
DeletedAt gorm.DeletedAt `json:"deleted_at"`
}
GothCsrfToken is a CSRF token for a user
func (GothCsrfToken) HasExpired ¶ added in v1.2.14
func (c GothCsrfToken) HasExpired() bool
HasExpired returns true if the session has expired.
func (GothCsrfToken) IsValid ¶ added in v1.2.14
func (c GothCsrfToken) IsValid(token string) bool
IsValid returns true if the token is valid.
type GothSession ¶ added in v1.2.1
type GothSession struct {
// ID is the unique identifier of the session.
ID uuid.UUID `json:"id" gorm:"primaryKey;unique;type:uuid;column:id;default:gen_random_uuid()"`
// SessionToken is the token of the session.
SessionToken string `json:"session_token"`
// CsrfToken is the CSRF token of the session.
CsrfToken GothCsrfToken `json:"csrf_token"`
// CsrfTokenID is the CSRF token ID of the session.
CsrfTokenID uuid.UUID `json:"csrf_token_id"`
// UserID is the user ID of the session.
UserID uuid.UUID `json:"user_id"`
// User is the user of the session.
User GothUser `json:"user"`
// ExpiresAt is the expiry time of the session.
ExpiresAt time.Time `json:"expires_at"`
// CreatedAt is the creation time of the session.
CreatedAt time.Time `json:"created_at"`
// UpdatedAt is the update time of the session.
UpdatedAt time.Time `json:"updated_at"`
// DeletedAt is the deletion time of the session.
DeletedAt gorm.DeletedAt `json:"deleted_at"`
}
GothSession is a session for a user.
func (*GothSession) GetCsrfToken ¶ added in v1.2.5
func (s *GothSession) GetCsrfToken() GothCsrfToken
GetCsrfToken returns the CSRF token.
func (*GothSession) GetUser ¶ added in v1.2.15
func (s *GothSession) GetUser() GothUser
GetUser returns the user of the session.
func (*GothSession) IsValid ¶ added in v1.2.1
func (s *GothSession) IsValid() bool
IsValid returns true if the session is valid.
type GothUser ¶ added in v1.2.1
type GothUser struct {
// ID is the unique identifier of the user.
ID uuid.UUID `json:"id" gorm:"primaryKey;unique;type:uuid;column:id;default:gen_random_uuid()"`
// Name is the name of the user.
Name string `json:"name" validate:"required,max=255"`
// Email is the email of the user.
Email string `json:"email" gorm:"unique" validate:"required,email"`
// EmailVerified is true if the email is verified.
EmailVerified *bool `json:"email_verified"`
// Image is the image URL of the user.
Image *string `json:"image" validate:"url"`
// Password is the password of the user.
Accounts []GothAccount `json:"accounts" gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE"`
// Sessions are the sessions of the user.
Sessions []GothSession `json:"sessions" gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE"`
// CreatedAt is the creation time of the user.
CreatedAt time.Time `json:"created_at"`
// UpdatedAt is the update time of the user.
UpdatedAt time.Time `json:"updated_at"`
// DeletedAt is the deletion time of the user.
DeletedAt gorm.DeletedAt `json:"deleted_at"`
}
GothUser is a user of the application.
type GothVerificationToken ¶ added in v1.2.1
type GothVerificationToken struct {
// Token is the unique identifier of the token.
Token string `json:"token" gorm:"primaryKey"`
// Identifier is the identifier of the token.
Identifier string `json:"identifier"`
// ExpiresAt is the expiry time of the token.
ExpiresAt time.Time `json:"expires_at"`
// CreatedAt is the creation time of the token.
CreatedAt time.Time `json:"created_at"`
// UpdatedAt is the update time of the token.
UpdatedAt time.Time `json:"updated_at"`
// DeletedAt is the deletion time of the token.
DeletedAt gorm.DeletedAt `json:"deleted_at"`
}
GothVerificationToken is a verification token for a user
type UnimplementedAdapter ¶
type UnimplementedAdapter struct{}
UnimplementedAdapter is an adapter that does not implement any of the methods.
func (*UnimplementedAdapter) CreateSession ¶
func (a *UnimplementedAdapter) CreateSession(_ context.Context, userID uuid.UUID, expires time.Time) (GothSession, error)
CreateSession creates a new session.
func (*UnimplementedAdapter) CreateUser ¶
CreateUser creates a new user.
func (*UnimplementedAdapter) CreateVerificationToken ¶
func (a *UnimplementedAdapter) CreateVerificationToken(_ context.Context, erficationToken GothVerificationToken) (GothVerificationToken, error)
CreateVerificationToken creates a new verification token.
func (*UnimplementedAdapter) DeleteSession ¶
func (a *UnimplementedAdapter) DeleteSession(_ context.Context, sessionToken string) error
DeleteSession deletes a session by session token.
func (*UnimplementedAdapter) DeleteUser ¶
DeleteUser deletes a user by ID.
func (*UnimplementedAdapter) GetSession ¶
func (a *UnimplementedAdapter) GetSession(_ context.Context, sessionToken string) (GothSession, error)
GetSession retrieves a session by session token.
func (*UnimplementedAdapter) GetUserByAccount ¶
func (a *UnimplementedAdapter) GetUserByAccount(_ context.Context, provider string, providerAccountID string) (GothUser, error)
GetUserByAccount retrieves a user by account.
func (*UnimplementedAdapter) GetUserByEmail ¶
GetUserByEmail retrieves a user by email.
func (*UnimplementedAdapter) LinkAccount ¶
LinkAccount links an account to a user.
func (*UnimplementedAdapter) RefreshSession ¶
func (a *UnimplementedAdapter) RefreshSession(_ context.Context, session GothSession) (GothSession, error)
RefreshSession refreshes a session.
func (*UnimplementedAdapter) UnlinkAccount ¶
UnlinkAccount unlinks an account from a user.
func (*UnimplementedAdapter) UpdateSession ¶
func (a *UnimplementedAdapter) UpdateSession(_ context.Context, session GothSession) (GothSession, error)
UpdateSession updates a session.
func (*UnimplementedAdapter) UpdateUser ¶
UpdateUser updates a user.
func (*UnimplementedAdapter) UseVerficationToken ¶
func (a *UnimplementedAdapter) UseVerficationToken(_ context.Context, identifier string, token string) (GothVerificationToken, error)
UseVerficationToken uses a verification token.