auth

package
v0.0.0-...-1746241 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 13 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const NameGithub string = "github"

NameGithub is the unique name of the Github provider.

View Source
const NameVK string = "vk"

NameVK is the unique name of the VK provider.

View Source
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) Client

func (p Github) Client(token *oauth2.Token) *http.Client

Client implements Provider.Client() 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) Context

func (p Github) Context() context.Context

Context implements Provider.Context() interface method.

func (Github) DisplayName

func (p Github) DisplayName() string

DisplayName implements Provider.DisplayName() interface method.

func (*Github) FetchAuthUser

func (p *Github) FetchAuthUser(token *oauth2.Token) (*AuthUser, error)

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

func (p Github) FetchRawUserData(token *oauth2.Token) ([]byte, error)

FetchRawUserData implements Provider.FetchRawUserData() interface method.

func (Github) FetchToken

func (p Github) FetchToken(code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)

FetchToken implements Provider.FetchToken() interface method.

func (Github) PKCE

func (p Github) PKCE() bool

PKCE implements Provider.PKCE() 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

func (p Github) SetContext(ctx context.Context)

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

func NewProviderByName(name string) (Provider, error)

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.

Docs: https://dev.vk.com/api/oauth-parameters

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

func (p VK) Client(token *oauth2.Token) *http.Client

Client implements Provider.Client() 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) Context

func (p VK) Context() context.Context

Context implements Provider.Context() interface method.

func (VK) DisplayName

func (p VK) DisplayName() string

DisplayName implements Provider.DisplayName() interface method.

func (*VK) FetchAuthUser

func (p *VK) FetchAuthUser(token *oauth2.Token) (*AuthUser, error)

FetchAuthUser returns an AuthUser instance based on VK's user api.

API reference: https://dev.vk.com/method/users.get

func (VK) FetchRawUserData

func (p VK) FetchRawUserData(token *oauth2.Token) ([]byte, error)

FetchRawUserData implements Provider.FetchRawUserData() interface method.

func (VK) FetchToken

func (p VK) FetchToken(code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)

FetchToken implements Provider.FetchToken() interface method.

func (VK) PKCE

func (p VK) PKCE() bool

PKCE implements Provider.PKCE() 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

func (p VK) SetContext(ctx context.Context)

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.

Docs: https://yandex.ru/dev/id/doc/en/

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

func (p Yandex) Client(token *oauth2.Token) *http.Client

Client implements Provider.Client() 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) Context

func (p Yandex) Context() context.Context

Context implements Provider.Context() interface method.

func (Yandex) DisplayName

func (p Yandex) DisplayName() string

DisplayName implements Provider.DisplayName() interface method.

func (*Yandex) FetchAuthUser

func (p *Yandex) FetchAuthUser(token *oauth2.Token) (*AuthUser, error)

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

func (p Yandex) FetchRawUserData(token *oauth2.Token) ([]byte, error)

FetchRawUserData implements Provider.FetchRawUserData() interface method.

func (Yandex) FetchToken

func (p Yandex) FetchToken(code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)

FetchToken implements Provider.FetchToken() interface method.

func (Yandex) PKCE

func (p Yandex) PKCE() bool

PKCE implements Provider.PKCE() 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

func (p Yandex) SetContext(ctx context.Context)

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.

Jump to

Keyboard shortcuts

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