Documentation ¶
Index ¶
- Variables
- func AuthRedirectURL(p *Provider, state, nonce, redir string) string
- func Base64UrlDecode(s string) ([]byte, error)
- func GetCurve(s string) elliptic.Curve
- func ParseExponent(es string) int
- func ParseModulo(ns string) *big.Int
- func RandomString(len int) string
- type Goic
- func (g *Goic) AddProvider(p *Provider) *Provider
- func (g *Goic) Authenticate(p *Provider, codeOrTok, nonce, redir string) (tok *Token, err error)
- func (g *Goic) GetProvider(name string) *Provider
- func (g *Goic) MiddlewareFunc(next http.HandlerFunc) http.HandlerFunc
- func (g *Goic) MiddlewareHandler(next http.Handler) http.Handler
- func (g *Goic) NewProvider(name, uri string) *Provider
- func (g *Goic) RefreshToken(tok *Token) (*Token, error)
- func (g *Goic) RequestAuth(p *Provider, state, nonce, redir string, res http.ResponseWriter, ...) error
- func (g *Goic) RevokeToken(tok *Token) error
- func (g *Goic) SignOut(tok *Token, redir string, res http.ResponseWriter, req *http.Request) error
- func (g *Goic) Supports(name string) bool
- func (g *Goic) UnsetState(s string)
- func (g *Goic) UserCallback(cb UserCallback) *Goic
- func (g *Goic) UserInfo(tok *Token) *User
- type Provider
- func (p *Provider) AuthBasicHeader() string
- func (p *Provider) CanRevoke() bool
- func (p *Provider) CanSignOut() bool
- func (p *Provider) GetURI(action string) (uri string)
- func (p *Provider) Is(name string) bool
- func (p *Provider) SetErr(err error)
- func (p *Provider) SetQuery(fn func() string) *Provider
- func (p *Provider) WithCredential(id, secret string) *Provider
- func (p *Provider) WithScope(s string) *Provider
- type Token
- type User
- type UserCallback
- type WellKnown
Constants ¶
This section is empty.
Variables ¶
var ( // ErrProviderState is error for invalid request state ErrProviderState = fmt.Errorf("goic provider: invalid request state") // ErrProviderSupport is error for unsupported provider ErrProviderSupport = fmt.Errorf("goic provider: unsupported provider") // ErrTokenEmpty is error for empty token ErrTokenEmpty = fmt.Errorf("goic id_token: empty token") // ErrTokenInvalid is error for invalid token ErrTokenInvalid = fmt.Errorf("goic id_token: invalid id_token") // ErrRefreshTokenInvalid is error for invalid token ErrRefreshTokenInvalid = fmt.Errorf("goic id_token: invalid refresh_token") // ErrTokenClaims is error for invalid token claims ErrTokenClaims = fmt.Errorf("goic id_token: invalid id_token claims") // ErrTokenNonce is error for invalid noce ErrTokenNonce = fmt.Errorf("goic id_token: invalid nonce") // ErrTokenAud is error for invalid audience ErrTokenAud = fmt.Errorf("goic id_token: invalid audience") // ErrTokenAlgo is error for unsupported signing algo ErrTokenAlgo = fmt.Errorf("goic id_token: unsupported signing algo") // ErrTokenKey is error for undetermined signing key ErrTokenKey = fmt.Errorf("goic id_token: can't determine signing key") // ErrTokenAccessKey is error for invalid access_token ErrTokenAccessKey = fmt.Errorf("goic id_token: invalid access_token") // ErrSignOutRedir is error for invalid post sign-out redirect uri ErrSignOutRedir = fmt.Errorf("goic sign-out: post redirect uri is invalid") )
var Facebook = &Provider{ Name: "facebook", ResType: "code", URL: "https://www.facebook.com", Scope: "openid email public_profile", wellKnown: &WellKnown{TokenURI: "https://graph.facebook.com/v17.0/oauth/access_token"}, }
var Google = &Provider{
Name: "google",
URL: "https://accounts.google.com",
Scope: "openid email profile",
}
Google is ready to use Provider instance
var Microsoft = &Provider{
Name: "microsoft",
URL: "https://login.microsoftonline.com/common/v2.0",
Scope: "openid email profile offline_access",
}
Microsoft is ready to use Provider instance
var Paypal = &Provider{
Name: "paypal",
URL: "https://www.paypalobjects.com",
Scope: "openid email profile",
}
Paypal live provider
var PaypalSandbox = &Provider{ Name: "paypal", Sandbox: true, URL: "https://www.paypalobjects.com", Scope: "openid email profile", }
PaypalSandbox provider
var Yahoo = &Provider{
Name: "yahoo",
URL: "https://login.yahoo.com",
Scope: "openid openid2 email profile",
}
Yahoo provider
Functions ¶
func AuthRedirectURL ¶ added in v0.0.14
AuthRedirectURL gives the full auth redirect URL for the provider It returns empty string when there is an error
func Base64UrlDecode ¶ added in v0.0.5
Base64UrlDecode decodes JWT segments with base64 accounting for URL chars
func ParseExponent ¶
ParseExponent ParseModulo parses the "e" value of jwks key
func ParseModulo ¶
ParseModulo parses the "n" value of jwks key
func RandomString ¶
RandomString generates random string of given length It sets rand seed on each call and returns generated string.
Types ¶
type Goic ¶
type Goic struct { URIPrefix string // contains filtered or unexported fields }
Goic is the main program
func (*Goic) AddProvider ¶ added in v0.0.6
AddProvider adds a Provider to Goic
func (*Goic) Authenticate ¶
Authenticate tries to authenticate a user by given code and nonce It is where token is requested and validated
func (*Goic) GetProvider ¶ added in v0.0.14
GetProvider returns Provider by name or nil if not existent
func (*Goic) MiddlewareFunc ¶
func (g *Goic) MiddlewareFunc(next http.HandlerFunc) http.HandlerFunc
MiddlewareFunc is wrapper for http.HandlerFunc that adds OpenID support
func (*Goic) MiddlewareHandler ¶
MiddlewareHandler is wrapper for http.Handler that adds OpenID support
func (*Goic) NewProvider ¶
NewProvider adds a new OpenID provider by name It also preloads the well known config and jwks keys
func (*Goic) RefreshToken ¶ added in v0.0.10
RefreshToken gets new access token using the refresh token
func (*Goic) RequestAuth ¶
func (g *Goic) RequestAuth(p *Provider, state, nonce, redir string, res http.ResponseWriter, req *http.Request) error
RequestAuth is the starting point of OpenID flow
func (*Goic) RevokeToken ¶ added in v0.0.12
RevokeToken revokes a Token so that it is no longer usable
func (*Goic) SignOut ¶ added in v0.0.11
SignOut signs out the Token from OpenID Provider and then redirects to given URI Redirect URI must be preconfigured in OpenID Provider already
func (*Goic) UnsetState ¶ added in v0.0.8
UnsetState unsets state from memory
func (*Goic) UserCallback ¶
func (g *Goic) UserCallback(cb UserCallback) *Goic
UserCallback sets a callback for post user verification
type Provider ¶
type Provider struct { QueryFn func() string Name string URL string Scope string ResType string Sandbox bool // contains filtered or unexported fields }
Provider represents OpenID Connect provider
func (*Provider) AuthBasicHeader ¶ added in v0.0.12
AuthBasicHeader gives a string ready to use as Authorization header The returned value contains "Basic " prefix already
func (*Provider) CanRevoke ¶ added in v0.0.12
CanRevoke checks if token can be revoked for this Provider
func (*Provider) CanSignOut ¶ added in v0.0.12
CanSignOut checks if token can be signed out for this Provider
func (*Provider) WithCredential ¶
WithCredential sets client id and secret for a Provider
type Token ¶
type Token struct { Claims jwt.MapClaims `json:"-"` Err string `json:"error,omitempty"` ErrDesc string `json:"error_description,omitempty"` IDToken string `json:"id_token"` AccessToken string `json:"access_token,omitempty"` RefreshToken string `json:"refresh_token,omitempty"` Provider string `json:"provider,omitempty"` }
Token represents token structure from well known token endpoint
func (*Token) VerifyClaims ¶ added in v0.1.0
verifyClaims verifies the claims of a Token
type User ¶
type User struct { Email string `json:"email"` EmailVerified bool `json:"email_verified,omitempty"` FamilyName string `json:"family_name,omitempty"` GivenName string `json:"given_name,omitempty"` Locale string `json:"locale,omitempty"` Name string `json:"name"` Picture string `json:"picture,omitempty"` Subject string `json:"sub,omitempty"` Error error `json:"-"` }
User represents user from well known user info endpoint
func (*User) FromClaims ¶ added in v0.1.0
type UserCallback ¶
UserCallback defines signature for post user verification callback
type WellKnown ¶
type WellKnown struct { Issuer string `json:"issuer"` KeysURI string `json:"jwks_uri"` AuthURI string `json:"authorization_endpoint"` TokenURI string `json:"token_endpoint"` UserInfoURI string `json:"userinfo_endpoint"` SignOutURI string `json:"end_session_endpoint,omitempty"` RevokeURI string `json:"revocation_endpoint,omitempty"` XRevokeURI string `json:"token_revocation_endpoint,omitempty"` AlgoSupport []string `json:"id_token_signing_alg_values_supported"` // contains filtered or unexported fields }
WellKnown represents OpenID Connect well-known config