Documentation ¶
Index ¶
- type AuthProvider
- type AuthService
- func (a *AuthService) Auhenticate(ctx context.Context, opts *entity.AuthUserOptions) (*entity.Auth, error)
- func (a *AuthService) CreateAuth(ctx context.Context, auth *entity.Auth) error
- func (a *AuthService) DeleteAuth(ctx context.Context, id int64) error
- func (a *AuthService) FindAuthByID(ctx context.Context, id int64) (*entity.Auth, error)
- func (a *AuthService) FindAuths(ctx context.Context, filter service.AuthFilter) (entity.Auths, int, error)
- type GithubProvider
- type LocalProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthProvider ¶
type AuthProvider interface { // Auhenticate returns the user from the auth provider. // May returns err if something went wrong. Auhenticate(ctx context.Context, opts *entity.AuthUserOptions) (*entity.Auth, error) // GetAuthURL returns the auth url, nil if not supported. GetOAuthConfig() *oauth2.Config // Source returns the source of the auth provider. Source() string }
AuthProvider is the interface for the auth provider.
type AuthService ¶
type AuthService struct {
// contains filtered or unexported fields
}
Auth is the auth service. Contains the supported providers. Contains the underlying auth service. maybe a sql db. Implements service.AuthService interface.
func NewAuth ¶
func NewAuth(authService service.AuthService, userService service.UserService, conf config.AuthListConfig) *AuthService
NewAuth creates a new Auth instance
func (*AuthService) Auhenticate ¶
func (a *AuthService) Auhenticate(ctx context.Context, opts *entity.AuthUserOptions) (*entity.Auth, error)
Auhenticate authenticates the user with the given auth source and options. Each provider has its own options and implements its validation.
func (*AuthService) CreateAuth ¶
CreateAuth creates a new auth. If is attached to a user, links the auth to the user, otherwise creates a new user. On success, the auth.ID is set.
func (*AuthService) DeleteAuth ¶
func (a *AuthService) DeleteAuth(ctx context.Context, id int64) error
DeleteAuth deletes an auth. Do not delete underlying user.
func (*AuthService) FindAuthByID ¶
FindAuthByID returns a single auth by its id.
type GithubProvider ¶
type GithubProvider struct {
// contains filtered or unexported fields
}
GithubProvider is the Github implementation of AuthProvider.
func NewGithubProvider ¶
func NewGithubProvider(config config.AuthConfig, authService service.AuthService) *GithubProvider
NewGithubProvider returns a new GithubProvider.
func (*GithubProvider) Auhenticate ¶
func (p *GithubProvider) Auhenticate(ctx context.Context, opts *entity.AuthUserOptions) (*entity.Auth, error)
Auhenticate implements oauth2 for github. AuthUserOptions.AuthCode is required to exchange for tokens.
func (*GithubProvider) GetOAuthConfig ¶
func (p *GithubProvider) GetOAuthConfig() *oauth2.Config
GetConfig returns the oauth2.Config for the provider.
func (*GithubProvider) Source ¶
func (p *GithubProvider) Source() string
Source returns the source of the provider.
type LocalProvider ¶
type LocalProvider struct {
// contains filtered or unexported fields
}
LocalProvider implements the AuthProvider interface for local authentication.
func NewLocalProvider ¶
func NewLocalProvider(authService service.AuthService, userService service.UserService) *LocalProvider
NewLocalProvider returns a new LocalProvider.
func (*LocalProvider) Auhenticate ¶
func (p *LocalProvider) Auhenticate(ctx context.Context, opts *entity.AuthUserOptions) (*entity.Auth, error)
Auhenticate returns the user from local auth. Requires a user passed through opts.User.
func (*LocalProvider) GetOAuthConfig ¶
func (p *LocalProvider) GetOAuthConfig() *oauth2.Config
GetConfig returns the oauth2.Config for the provider.
Local provider does not use oauth2.
func (*LocalProvider) Source ¶
func (p *LocalProvider) Source() string
Source returns the source of the provider.