Documentation
¶
Index ¶
- Constants
- type AuthUser
- type Github
- func (p Github) AuthUrl() string
- func (p Github) BuildAuthUrl(state string, opts ...oauth2.AuthCodeOption) string
- func (p Github) Client(token *oauth2.Token) *http.Client
- func (p Github) ClientId() string
- func (p Github) ClientSecret() string
- func (p Github) Context() context.Context
- func (p Github) DisplayName() string
- func (p *Github) FetchAuthUser(token *oauth2.Token) (*AuthUser, error)
- func (p Github) FetchRawUserData(token *oauth2.Token) ([]byte, error)
- func (p Github) FetchToken(code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
- func (p Github) PKCE() bool
- func (p Github) RedirectUrl() string
- func (p Github) Scopes() []string
- func (p Github) SetAuthUrl(url string)
- func (p Github) SetClientId(clientId string)
- func (p Github) SetClientSecret(secret string)
- func (p Github) SetContext(ctx context.Context)
- func (p Github) SetDisplayName(displayName string)
- func (p Github) SetPKCE(enable bool)
- func (p Github) SetRedirectUrl(url string)
- func (p Github) SetScopes(scopes []string)
- func (p Github) SetTokenUrl(url string)
- func (p Github) SetUserApiUrl(url string)
- func (p Github) TokenUrl() string
- func (p Github) UserApiUrl() string
- type Provider
- type VK
- func (p VK) AuthUrl() string
- func (p VK) BuildAuthUrl(state string, opts ...oauth2.AuthCodeOption) string
- func (p VK) Client(token *oauth2.Token) *http.Client
- func (p VK) ClientId() string
- func (p VK) ClientSecret() string
- func (p VK) Context() context.Context
- func (p VK) DisplayName() string
- func (p *VK) FetchAuthUser(token *oauth2.Token) (*AuthUser, error)
- func (p VK) FetchRawUserData(token *oauth2.Token) ([]byte, error)
- func (p VK) FetchToken(code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
- func (p VK) PKCE() bool
- func (p VK) RedirectUrl() string
- func (p VK) Scopes() []string
- func (p VK) SetAuthUrl(url string)
- func (p VK) SetClientId(clientId string)
- func (p VK) SetClientSecret(secret string)
- func (p VK) SetContext(ctx context.Context)
- func (p VK) SetDisplayName(displayName string)
- func (p VK) SetPKCE(enable bool)
- func (p VK) SetRedirectUrl(url string)
- func (p VK) SetScopes(scopes []string)
- func (p VK) SetTokenUrl(url string)
- func (p VK) SetUserApiUrl(url string)
- func (p VK) TokenUrl() string
- func (p VK) UserApiUrl() string
- type Yandex
- func (p Yandex) AuthUrl() string
- func (p Yandex) BuildAuthUrl(state string, opts ...oauth2.AuthCodeOption) string
- func (p Yandex) Client(token *oauth2.Token) *http.Client
- func (p Yandex) ClientId() string
- func (p Yandex) ClientSecret() string
- func (p Yandex) Context() context.Context
- func (p Yandex) DisplayName() string
- func (p *Yandex) FetchAuthUser(token *oauth2.Token) (*AuthUser, error)
- func (p Yandex) FetchRawUserData(token *oauth2.Token) ([]byte, error)
- func (p Yandex) FetchToken(code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
- func (p Yandex) PKCE() bool
- func (p Yandex) RedirectUrl() string
- func (p Yandex) Scopes() []string
- func (p Yandex) SetAuthUrl(url string)
- func (p Yandex) SetClientId(clientId string)
- func (p Yandex) SetClientSecret(secret string)
- func (p Yandex) SetContext(ctx context.Context)
- func (p Yandex) SetDisplayName(displayName string)
- func (p Yandex) SetPKCE(enable bool)
- func (p Yandex) SetRedirectUrl(url string)
- func (p Yandex) SetScopes(scopes []string)
- func (p Yandex) SetTokenUrl(url string)
- func (p Yandex) SetUserApiUrl(url string)
- func (p Yandex) TokenUrl() string
- func (p Yandex) UserApiUrl() string
Constants ¶
const NameGithub string = "github"
NameGithub is the unique name of the Github provider.
const NameVK string = "vk"
NameVK is the unique name of the VK provider.
const NameYandex string = "yandex"
NameYandex is the unique name of the Yandex provider.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthUser ¶
type AuthUser struct {
Id string `json:"id"`
Name string `json:"name"`
Username string `json:"username"`
Email string `json:"email"`
AvatarUrl string `json:"avatarUrl"`
AccessToken string `json:"accessToken"`
RefreshToken string `json:"refreshToken"`
Expiry types.DateTime `json:"expiry"`
RawUser map[string]any `json:"rawUser"`
}
AuthUser defines a standardized oauth2 user data structure.
type Github ¶
type Github struct {
// contains filtered or unexported fields
}
Github allows authentication via Github OAuth2.
func NewGithubProvider ¶
func NewGithubProvider() *Github
NewGithubProvider creates new Github provider instance with some defaults.
func (Github) AuthUrl ¶
func (p Github) AuthUrl() string
AuthUrl implements Provider.AuthUrl() interface method.
func (Github) BuildAuthUrl ¶
func (p Github) BuildAuthUrl(state string, opts ...oauth2.AuthCodeOption) string
BuildAuthUrl implements Provider.BuildAuthUrl() interface method.
func (Github) ClientId ¶
func (p Github) ClientId() string
ClientId implements Provider.ClientId() interface method.
func (Github) ClientSecret ¶
func (p Github) ClientSecret() string
ClientSecret implements Provider.ClientSecret() interface method.
func (Github) DisplayName ¶
func (p Github) DisplayName() string
DisplayName implements Provider.DisplayName() interface method.
func (*Github) FetchAuthUser ¶
FetchAuthUser returns an AuthUser instance based the Github's user api.
API reference: https://docs.github.com/en/rest/reference/users#get-the-authenticated-user
func (Github) FetchRawUserData ¶
FetchRawUserData implements Provider.FetchRawUserData() interface method.
func (Github) FetchToken ¶
FetchToken implements Provider.FetchToken() interface method.
func (Github) RedirectUrl ¶
func (p Github) RedirectUrl() string
RedirectUrl implements Provider.RedirectUrl() interface method.
func (Github) Scopes ¶
func (p Github) Scopes() []string
Scopes implements Provider.Scopes() interface method.
func (Github) SetAuthUrl ¶
func (p Github) SetAuthUrl(url string)
SetAuthUrl implements Provider.SetAuthUrl() interface method.
func (Github) SetClientId ¶
func (p Github) SetClientId(clientId string)
SetClientId implements Provider.SetClientId() interface method.
func (Github) SetClientSecret ¶
func (p Github) SetClientSecret(secret string)
SetClientSecret implements Provider.SetClientSecret() interface method.
func (Github) SetContext ¶
SetContext implements Provider.SetContext() interface method.
func (Github) SetDisplayName ¶
func (p Github) SetDisplayName(displayName string)
SetDisplayName implements Provider.SetDisplayName() interface method.
func (Github) SetPKCE ¶
func (p Github) SetPKCE(enable bool)
SetPKCE implements Provider.SetPKCE() interface method.
func (Github) SetRedirectUrl ¶
func (p Github) SetRedirectUrl(url string)
SetRedirectUrl implements Provider.SetRedirectUrl() interface method.
func (Github) SetScopes ¶
func (p Github) SetScopes(scopes []string)
SetScopes implements Provider.SetScopes() interface method.
func (Github) SetTokenUrl ¶
func (p Github) SetTokenUrl(url string)
SetTokenUrl implements Provider.SetTokenUrl() interface method.
func (Github) SetUserApiUrl ¶
func (p Github) SetUserApiUrl(url string)
SetUserApiUrl implements Provider.SetUserApiUrl() interface method.
func (Github) TokenUrl ¶
func (p Github) TokenUrl() string
TokenUrl implements Provider.TokenUrl() interface method.
func (Github) UserApiUrl ¶
func (p Github) UserApiUrl() string
UserApiUrl implements Provider.UserApiUrl() interface method.
type Provider ¶
type Provider interface {
// Context returns the context associated with the provider (if any).
Context() context.Context
// SetContext assigns the specified context to the current provider.
SetContext(ctx context.Context)
// PKCE indicates whether the provider can use the PKCE flow.
PKCE() bool
// SetPKCE toggles the state whether the provider can use the PKCE flow or not.
SetPKCE(enable bool)
// DisplayName usually returns provider name as it is officially written
// and it could be used directly in the UI.
DisplayName() string
// SetDisplayName sets the provider's display name.
SetDisplayName(displayName string)
// Scopes returns the provider access permissions that will be requested.
Scopes() []string
// SetScopes sets the provider access permissions that will be requested later.
SetScopes(scopes []string)
// ClientId returns the provider client's app ID.
ClientId() string
// SetClientId sets the provider client's ID.
SetClientId(clientId string)
// ClientSecret returns the provider client's app secret.
ClientSecret() string
// SetClientSecret sets the provider client's app secret.
SetClientSecret(secret string)
// RedirectUrl returns the end address to redirect the user
// going through the OAuth flow.
RedirectUrl() string
// SetRedirectUrl sets the provider's RedirectUrl.
SetRedirectUrl(url string)
// AuthUrl returns the provider's authorization service url.
AuthUrl() string
// SetAuthUrl sets the provider's AuthUrl.
SetAuthUrl(url string)
// TokenUrl returns the provider's token exchange service url.
TokenUrl() string
// SetTokenUrl sets the provider's TokenUrl.
SetTokenUrl(url string)
// UserApiUrl returns the provider's user info api url.
UserApiUrl() string
// SetUserApiUrl sets the provider's UserApiUrl.
SetUserApiUrl(url string)
// Client returns an http client using the provided token.
Client(token *oauth2.Token) *http.Client
// BuildAuthUrl returns a URL to the provider's consent page
// that asks for permissions for the required scopes explicitly.
BuildAuthUrl(state string, opts ...oauth2.AuthCodeOption) string
// FetchToken converts an authorization code to token.
FetchToken(code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
// FetchRawUserData requests and marshalizes into `result` the
// the OAuth user api response.
FetchRawUserData(token *oauth2.Token) ([]byte, error)
// FetchAuthUser is similar to FetchRawUserData, but normalizes and
// marshalizes the user api response into a standardized AuthUser struct.
FetchAuthUser(token *oauth2.Token) (user *AuthUser, err error)
}
Provider defines a common interface for an OAuth2 client.
func NewProviderByName ¶
NewProviderByName returns a new preconfigured provider instance by its name identifier.
type VK ¶
type VK struct {
// contains filtered or unexported fields
}
VK allows authentication via VK OAuth2.
func NewVKProvider ¶
func NewVKProvider() *VK
NewVKProvider creates new VK provider instance with some defaults.
func (VK) AuthUrl ¶
func (p VK) AuthUrl() string
AuthUrl implements Provider.AuthUrl() interface method.
func (VK) BuildAuthUrl ¶
func (p VK) BuildAuthUrl(state string, opts ...oauth2.AuthCodeOption) string
BuildAuthUrl implements Provider.BuildAuthUrl() interface method.
func (VK) ClientId ¶
func (p VK) ClientId() string
ClientId implements Provider.ClientId() interface method.
func (VK) ClientSecret ¶
func (p VK) ClientSecret() string
ClientSecret implements Provider.ClientSecret() interface method.
func (VK) DisplayName ¶
func (p VK) DisplayName() string
DisplayName implements Provider.DisplayName() interface method.
func (*VK) FetchAuthUser ¶
FetchAuthUser returns an AuthUser instance based on VK's user api.
API reference: https://dev.vk.com/method/users.get
func (VK) FetchRawUserData ¶
FetchRawUserData implements Provider.FetchRawUserData() interface method.
func (VK) FetchToken ¶
FetchToken implements Provider.FetchToken() interface method.
func (VK) RedirectUrl ¶
func (p VK) RedirectUrl() string
RedirectUrl implements Provider.RedirectUrl() interface method.
func (VK) Scopes ¶
func (p VK) Scopes() []string
Scopes implements Provider.Scopes() interface method.
func (VK) SetAuthUrl ¶
func (p VK) SetAuthUrl(url string)
SetAuthUrl implements Provider.SetAuthUrl() interface method.
func (VK) SetClientId ¶
func (p VK) SetClientId(clientId string)
SetClientId implements Provider.SetClientId() interface method.
func (VK) SetClientSecret ¶
func (p VK) SetClientSecret(secret string)
SetClientSecret implements Provider.SetClientSecret() interface method.
func (VK) SetContext ¶
SetContext implements Provider.SetContext() interface method.
func (VK) SetDisplayName ¶
func (p VK) SetDisplayName(displayName string)
SetDisplayName implements Provider.SetDisplayName() interface method.
func (VK) SetPKCE ¶
func (p VK) SetPKCE(enable bool)
SetPKCE implements Provider.SetPKCE() interface method.
func (VK) SetRedirectUrl ¶
func (p VK) SetRedirectUrl(url string)
SetRedirectUrl implements Provider.SetRedirectUrl() interface method.
func (VK) SetScopes ¶
func (p VK) SetScopes(scopes []string)
SetScopes implements Provider.SetScopes() interface method.
func (VK) SetTokenUrl ¶
func (p VK) SetTokenUrl(url string)
SetTokenUrl implements Provider.SetTokenUrl() interface method.
func (VK) SetUserApiUrl ¶
func (p VK) SetUserApiUrl(url string)
SetUserApiUrl implements Provider.SetUserApiUrl() interface method.
func (VK) TokenUrl ¶
func (p VK) TokenUrl() string
TokenUrl implements Provider.TokenUrl() interface method.
func (VK) UserApiUrl ¶
func (p VK) UserApiUrl() string
UserApiUrl implements Provider.UserApiUrl() interface method.
type Yandex ¶
type Yandex struct {
// contains filtered or unexported fields
}
Yandex allows authentication via Yandex OAuth2.
func NewYandexProvider ¶
func NewYandexProvider() *Yandex
NewYandexProvider creates new Yandex provider instance with some defaults.
func (Yandex) AuthUrl ¶
func (p Yandex) AuthUrl() string
AuthUrl implements Provider.AuthUrl() interface method.
func (Yandex) BuildAuthUrl ¶
func (p Yandex) BuildAuthUrl(state string, opts ...oauth2.AuthCodeOption) string
BuildAuthUrl implements Provider.BuildAuthUrl() interface method.
func (Yandex) ClientId ¶
func (p Yandex) ClientId() string
ClientId implements Provider.ClientId() interface method.
func (Yandex) ClientSecret ¶
func (p Yandex) ClientSecret() string
ClientSecret implements Provider.ClientSecret() interface method.
func (Yandex) DisplayName ¶
func (p Yandex) DisplayName() string
DisplayName implements Provider.DisplayName() interface method.
func (*Yandex) FetchAuthUser ¶
FetchAuthUser returns an AuthUser instance based on Yandex's user api.
API reference: https://yandex.ru/dev/id/doc/en/user-information#response-format
func (Yandex) FetchRawUserData ¶
FetchRawUserData implements Provider.FetchRawUserData() interface method.
func (Yandex) FetchToken ¶
FetchToken implements Provider.FetchToken() interface method.
func (Yandex) RedirectUrl ¶
func (p Yandex) RedirectUrl() string
RedirectUrl implements Provider.RedirectUrl() interface method.
func (Yandex) Scopes ¶
func (p Yandex) Scopes() []string
Scopes implements Provider.Scopes() interface method.
func (Yandex) SetAuthUrl ¶
func (p Yandex) SetAuthUrl(url string)
SetAuthUrl implements Provider.SetAuthUrl() interface method.
func (Yandex) SetClientId ¶
func (p Yandex) SetClientId(clientId string)
SetClientId implements Provider.SetClientId() interface method.
func (Yandex) SetClientSecret ¶
func (p Yandex) SetClientSecret(secret string)
SetClientSecret implements Provider.SetClientSecret() interface method.
func (Yandex) SetContext ¶
SetContext implements Provider.SetContext() interface method.
func (Yandex) SetDisplayName ¶
func (p Yandex) SetDisplayName(displayName string)
SetDisplayName implements Provider.SetDisplayName() interface method.
func (Yandex) SetPKCE ¶
func (p Yandex) SetPKCE(enable bool)
SetPKCE implements Provider.SetPKCE() interface method.
func (Yandex) SetRedirectUrl ¶
func (p Yandex) SetRedirectUrl(url string)
SetRedirectUrl implements Provider.SetRedirectUrl() interface method.
func (Yandex) SetScopes ¶
func (p Yandex) SetScopes(scopes []string)
SetScopes implements Provider.SetScopes() interface method.
func (Yandex) SetTokenUrl ¶
func (p Yandex) SetTokenUrl(url string)
SetTokenUrl implements Provider.SetTokenUrl() interface method.
func (Yandex) SetUserApiUrl ¶
func (p Yandex) SetUserApiUrl(url string)
SetUserApiUrl implements Provider.SetUserApiUrl() interface method.
func (Yandex) TokenUrl ¶
func (p Yandex) TokenUrl() string
TokenUrl implements Provider.TokenUrl() interface method.
func (Yandex) UserApiUrl ¶
func (p Yandex) UserApiUrl() string
UserApiUrl implements Provider.UserApiUrl() interface method.