Documentation ¶
Index ¶
Constants ¶
const ContextUserID = "SocialAuthUserID"
ContextUserID is the key under which the UserID of the current user is stored in the given context, through the ContextSetFunc Only for Authenticated requests
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthProvider ¶
type AuthProvider interface { // Identifier returns the string identifier of the provider Identifier() string // Verifies the given token against the server's provider (Facebook, Google...) // And returns the user ID or an error VerifyToken(userToken string) (string, error) }
AuthProvider is an interface that provides a method for token verification
type ContextSetFunc ¶
ContextSetFunc is the function that sets a value for a given key and request in a context. Usually this is the Gorilla Context -> context.Set -> github.com/gorilla/context
type FacebookAuthProvider ¶
type FacebookAuthProvider struct {
// contains filtered or unexported fields
}
FBAuthProvider - The Facebook Auth provider implementation
func NewFacebookAuthProvider ¶
func NewFacebookAuthProvider(appAccessToken string) *FacebookAuthProvider
Creates a new Facebook Authentication Provider instance The required appAccessToken can be obtained by Facebook's API -> https://developers.facebook.com/docs/facebook-login/access-tokens/#apptokens
func (*FacebookAuthProvider) Identifier ¶
func (p *FacebookAuthProvider) Identifier() string
Returns the identifier of this provider
func (*FacebookAuthProvider) VerifyToken ¶
func (p *FacebookAuthProvider) VerifyToken(userToken string) (string, error)
VerifyToken verifies the given token against the Facebook's server and returns the user ID or an error
type GoogleAuthProvider ¶
type GoogleAuthProvider struct {
// contains filtered or unexported fields
}
The GoogleAuthProvider validates the token against the google api
func NewGoogleAuthProvider ¶
func NewGoogleAuthProvider(appClientId string) *GoogleAuthProvider
Creates a new Google Authentication Provider The required appClientId can be found in your Google API's Dashboard https://developers.google.com/identity/protocols/OAuth2
func (*GoogleAuthProvider) Identifier ¶
func (p *GoogleAuthProvider) Identifier() string
Returns the identifier of this provider
func (*GoogleAuthProvider) VerifyToken ¶
func (p *GoogleAuthProvider) VerifyToken(userToken string) (string, error)
VerifyToken verifies the given token against the server's provider (Facebook, Google...) And returns the user ID or an error
type GoogleTokenValidator ¶
type GoogleTokenValidator struct {
// contains filtered or unexported fields
}
GoogleTokenValidator validates the given token using the Google's public keys
func NewGoogleTokenValidator ¶
func NewGoogleTokenValidator(appClientID string) *GoogleTokenValidator
NewGoogleTokenValidator creates a new instance of the GoogleTokenValidator struct Configures it and returns it
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware is a middleware for the http package It verifies if the request has a valid token The token is verified by one of the Social AuthProviders (Facebook, Google,...)
func NewMiddleware ¶
func NewMiddleware(socialAuth *SocialAuth, contextSetFunc ContextSetFunc) *Middleware
NewMiddleware creates a new Middleware with the given configuration
func (*Middleware) ServeHTTP ¶
func (am *Middleware) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)
type SocialAuth ¶
type SocialAuth struct {
// contains filtered or unexported fields
}
SocialAuth holds all the configured providers Use an instance of this struct to work with this library
func NewSocialAuth ¶
func NewSocialAuth(providers ...AuthProvider) *SocialAuth
NewSocialAuth creates and returns a new instance of the SocialAuth with the given providers
func (*SocialAuth) Get ¶
func (sa *SocialAuth) Get(provider string) AuthProvider
Get returns the asked provider. Nil if such provider is not configured.
type TokenInfo ¶
type TokenInfo struct { Sub string `json:"sub"` Email string `json:"email"` AtHash string `json:"at_hash"` Aud string `json:"aud"` EmailVerified bool `json:"email_verified"` Name string `json:"name"` GivenName string `json:"given_name"` FamilyName string `json:"family_name"` Picture string `json:"picture"` Local string `json:"locale"` Iss string `json:"iss"` Azp string `json:"azp"` Iat int64 `json:"iat"` Exp int64 `json:"exp"` }
TokenInfo