adapters

package
v1.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2024 License: MIT Imports: 6 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnimplemented = errors.New("not implemented")

ErrUnimplemented is returned when a method is not implemented.

Functions

func DefaultCsrfTokenGenerator added in v1.2.5

func DefaultCsrfTokenGenerator() (string, error)

DefaultCsrfTokenGenerator generates a new CSRF token.

func StringPtr

func StringPtr(s string) *string

StringPtr returns a pointer to the string value passed in.

func TimePtr

func TimePtr(t time.Time) *time.Time

TimePtr returns a pointer to the time value passed in.

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 CsrfTokenGenerator added in v1.2.5

type CsrfTokenGenerator func() (string, error)

CsrfTokenGenerator is a function that generates a CSRF token.

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

type GothRole added in v1.2.4

type GothRole struct {
	// ID is the unique identifier of the role.
	ID uuid.UUID `json:"id" gorm:"primaryKey;unique;type:uuid;column:id;default:gen_random_uuid()"`
	// Name is the name of the role.
	Name string `json:"name" validate:"required,min=3,max=255"`
	// Description is the description of the role.
	Description string `json:"description" validate:"max=255"`
	// TeamID is the team ID of the role.
	TeamID uuid.UUID `json:"team_id"`
	// Team is the team of the role.
	Team GothTeam `json:"team"`
	// CreatedAt is the creation time of the role.
	CreatedAt time.Time `json:"created_at"`
	// UpdatedAt is the update time of the role.
	UpdatedAt time.Time `json:"updated_at"`
	// DeletedAt is the deletion time of the role.
	DeletedAt gorm.DeletedAt `json:"deleted_at"`
}

GothRole is a role in the application.

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() string

GetCsrfToken returns the CSRF token.

func (*GothSession) IsValid added in v1.2.1

func (s *GothSession) IsValid() bool

IsValid returns true if the session is valid.

type GothTeam added in v1.2.4

type GothTeam struct {
	// ID is the unique identifier of the team.
	ID uuid.UUID `json:"id" gorm:"primaryKey;unique;type:uuid;column:id;default:gen_random_uuid()"`
	// Name is the name of the team.
	Name string `json:"name" validate:"required,max=255"`
	// Slug is the slug of the team.
	Slug string `json:"slug" validate:"required,min=3,max=255"`
	// Description is the description of the team.
	Description string `json:"description" validate:"max=255"`
	// Users are the users in the team.
	Users []GothUser `json:"users" gorm:"many2many:goth_team_users"`
	// Roles are the roles in the team.
	Roles []GothRole `json:"roles" gorm:"foreignKey:TeamID;constraint:OnDelete:CASCADE"`
	// CreatedAt is the creation time of the team.
	CreatedAt time.Time `json:"created_at"`
	// UpdatedAt is the update time of the team.
	UpdatedAt time.Time `json:"updated_at"`
	// DeletedAt is the deletion time of the team.
	DeletedAt gorm.DeletedAt `json:"deleted_at"`
}

GothTeam is a team in the application.

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"`
	// Teams are the teams the user is a member of.
	Teams *[]GothTeam `json:"teams" gorm:"many2many:goth_team_users"`
	// 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.

func (GothUser) TeamBySlug added in v1.2.4

func (u GothUser) TeamBySlug(slug string) GothTeam

TeamBySlug is returning the team with the given ID.

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

func (a *UnimplementedAdapter) CreateUser(_ context.Context, user GothUser) (GothUser, error)

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

func (a *UnimplementedAdapter) DeleteUser(_ context.Context, id uuid.UUID) error

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) GetUser

GetUser retrieves a user by ID.

func (*UnimplementedAdapter) GetUserByAccount

func (a *UnimplementedAdapter) GetUserByAccount(_ context.Context, provider string, providerAccountID string) (GothUser, error)

GetUserByAccount retrieves a user by account.

func (*UnimplementedAdapter) GetUserByEmail

func (a *UnimplementedAdapter) GetUserByEmail(_ context.Context, email string) (GothUser, error)

GetUserByEmail retrieves a user by email.

func (*UnimplementedAdapter) LinkAccount

func (a *UnimplementedAdapter) LinkAccount(_ context.Context, accountID, userID uuid.UUID) error

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

func (a *UnimplementedAdapter) UnlinkAccount(_ context.Context, accountID, userID uuid.UUID) error

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

func (a *UnimplementedAdapter) UpdateUser(_ context.Context, user GothUser) (GothUser, error)

UpdateUser updates a user.

func (*UnimplementedAdapter) UseVerficationToken

func (a *UnimplementedAdapter) UseVerficationToken(_ context.Context, identifier string, token string) (GothVerificationToken, error)

UseVerficationToken uses a verification token.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL