Documentation ¶
Index ¶
- Variables
- func MakeHTTPHandler(oauthSvc interface{ ... }) http.Handler
- func NewOAuth2Server(singingKey string, ttl time.Duration, verifier oauth.CredentialsVerifier) *oauth.BearerServer
- type VarifierOption
- type Verifier
- func (v *Verifier) AddClaims(tokenType oauth.TokenType, credential, tokenID, scope string, r *http.Request) (map[string]string, error)
- func (v *Verifier) AddProperties(tokenType oauth.TokenType, credential, tokenID, scope string, r *http.Request) (map[string]string, error)
- func (v *Verifier) StoreTokenID(tokenType oauth.TokenType, credential, tokenID, refreshTokenID string) error
- func (v *Verifier) ValidateClient(clientID, clientSecret, _ string, r *http.Request) error
- func (v *Verifier) ValidateTokenID(tokenType oauth.TokenType, credential, tokenID, refreshTokenID string) error
- func (v *Verifier) ValidateUser(username, password, scope string, r *http.Request) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidCredentials = errors.New("invalid credentials") ErrInvalidToken = errors.New("invalid token") ErrInvalidGrantType = errors.New("invalid grant type") ErrPasswordNotSupported = errors.New("password grant type not supported") ErrTokenExpired = errors.New("token expired") )
Predefined errors.
Functions ¶
func MakeHTTPHandler ¶
func MakeHTTPHandler(oauthSvc interface { ClientCredentials(w http.ResponseWriter, r *http.Request) }, ) http.Handler
MakeHTTPHandler returns an http.Handler that can be used to serve the OAuth2 API.
func NewOAuth2Server ¶
func NewOAuth2Server(singingKey string, ttl time.Duration, verifier oauth.CredentialsVerifier) *oauth.BearerServer
Set up limited oauth2 server for client_credentials, and refresh_token flows. Does not support password, authorization code flow.
Types ¶
type VarifierOption ¶
type VarifierOption func(*Verifier)
VerifierOption is a function that configures the Verifier.
func WithAccessTokenTTL ¶
func WithAccessTokenTTL(ttl time.Duration) VarifierOption
WithAccessTokenTTL sets the TTL for access tokens.
func WithRefreshTokenTTL ¶
func WithRefreshTokenTTL(ttl time.Duration) VarifierOption
WithRefreshTokenTTL sets the TTL for refresh tokens.
type Verifier ¶
type Verifier struct {
// contains filtered or unexported fields
}
Verifier is the service that validates the client credentials. Implements the interface gihub.com/go-chi/oauth/server.go.CredentialsVerifier
func NewVerifier ¶
func NewVerifier(repo verifierRepository, clientID, clientSecretHash string, opts ...VarifierOption) *Verifier
NewVerifier creates a new Verifier.
func (*Verifier) AddClaims ¶
func (v *Verifier) AddClaims(tokenType oauth.TokenType, credential, tokenID, scope string, r *http.Request) (map[string]string, error)
Provide additional claims to the token
func (*Verifier) AddProperties ¶
func (v *Verifier) AddProperties(tokenType oauth.TokenType, credential, tokenID, scope string, r *http.Request) (map[string]string, error)
Provide additional information to the authorization server response
func (*Verifier) StoreTokenID ¶
func (v *Verifier) StoreTokenID(tokenType oauth.TokenType, credential, tokenID, refreshTokenID string) error
Optionally store the tokenID generated for the user
func (*Verifier) ValidateClient ¶
Validate clientID and secret returning an error if the client credentials are wrong