auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

func (v *Verifier) ValidateClient(clientID, clientSecret, _ string, r *http.Request) error

Validate clientID and secret returning an error if the client credentials are wrong

func (*Verifier) ValidateTokenID

func (v *Verifier) ValidateTokenID(tokenType oauth.TokenType, credential, tokenID, refreshTokenID string) error

Optionally validate previously stored tokenID during refresh request

func (*Verifier) ValidateUser

func (v *Verifier) ValidateUser(username, password, scope string, r *http.Request) error

Validate username and password returning an error if the user credentials are wrong

Jump to

Keyboard shortcuts

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