Documentation
¶
Overview ¶
Package oauth - OAuth 2.0 sign-in with Google, VK ID and Yandex: the authorization URL, the code exchange and the user's profile normalized to Profile. Knows nothing of the application: credentials and the callback URL come from the caller.
Index ¶
Constants ¶
const ( Google = "google" VK = "vk" Yandex = "yandex" )
Provider names (Provider.Name).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Credentials ¶
Credentials - an app registered with a provider.
type Profile ¶
type Profile struct {
ProviderUserID string
Email string
// EmailVerified - the provider vouches the account owns Email (it
// confirmed the address); only then may Email sign in to an existing
// account with that address.
EmailVerified bool
DisplayName string
AvatarURL string
}
Profile is normalized user data from an OAuth provider.
type Provider ¶
type Provider interface {
Name() string
AuthCodeURL(state string) string
Exchange(ctx context.Context, code string) (*oauth2.Token, error)
UserInfo(ctx context.Context, token *oauth2.Token) (*Profile, error)
}
Provider implements OAuth2 authorization for one social network.
func NewGoogle ¶
func NewGoogle(creds Credentials, redirectURL string) Provider
NewGoogle - the Google provider with the app's credentials; redirectURL is the callback registered in the provider's console.
func NewVK ¶
func NewVK(creds Credentials, redirectURL string) Provider
NewVK - the VK provider with the app's credentials; redirectURL is the callback registered in the provider's console.
func NewYandex ¶
func NewYandex(creds Credentials, redirectURL string) Provider
NewYandex - the Yandex provider with the app's credentials; redirectURL is the callback registered in the provider's console.