server

package
v4.5.2 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: MIT Imports: 9 Imported by: 176

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientBasicHandler

func ClientBasicHandler(r *http.Request) (string, string, error)

ClientBasicHandler get client data from basic authorization

func ClientFormHandler

func ClientFormHandler(r *http.Request) (string, string, error)

ClientFormHandler get client data from form

Types

type AccessTokenExpHandler

type AccessTokenExpHandler func(w http.ResponseWriter, r *http.Request) (exp time.Duration, err error)

AccessTokenExpHandler set expiration date for the access token

type AuthorizeRequest

type AuthorizeRequest struct {
	ResponseType        oauth2.ResponseType
	ClientID            string
	Scope               string
	RedirectURI         string
	State               string
	UserID              string
	CodeChallenge       string
	CodeChallengeMethod oauth2.CodeChallengeMethod
	AccessTokenExp      time.Duration
	Request             *http.Request
}

AuthorizeRequest authorization request

type AuthorizeScopeHandler

type AuthorizeScopeHandler func(w http.ResponseWriter, r *http.Request) (scope string, err error)

AuthorizeScopeHandler set the authorized scope

type ClientAuthorizedHandler

type ClientAuthorizedHandler func(clientID string, grant oauth2.GrantType) (allowed bool, err error)

ClientAuthorizedHandler check the client allows to use this authorization grant type

type ClientInfoHandler

type ClientInfoHandler func(r *http.Request) (clientID, clientSecret string, err error)

ClientInfoHandler get client info from request

type ClientScopeHandler

type ClientScopeHandler func(tgr *oauth2.TokenGenerateRequest) (allowed bool, err error)

ClientScopeHandler check the client allows to use scope

type Config

type Config struct {
	TokenType                   string                // token type
	AllowGetAccessRequest       bool                  // to allow GET requests for the token
	AllowedResponseTypes        []oauth2.ResponseType // allow the authorization type
	AllowedGrantTypes           []oauth2.GrantType    // allow the grant type
	AllowedCodeChallengeMethods []oauth2.CodeChallengeMethod
	ForcePKCE                   bool
}

Config configuration parameters

func NewConfig

func NewConfig() *Config

NewConfig create to configuration instance

type ExtensionFieldsHandler

type ExtensionFieldsHandler func(ti oauth2.TokenInfo) (fieldsValue map[string]interface{})

ExtensionFieldsHandler in response to the access token with the extension of the field

type InternalErrorHandler

type InternalErrorHandler func(err error) (re *errors.Response)

InternalErrorHandler internal error handing

type PasswordAuthorizationHandler

type PasswordAuthorizationHandler func(ctx context.Context, clientID, username, password string) (userID string, err error)

PasswordAuthorizationHandler get user id from username and password

type PreRedirectErrorHandler added in v4.4.3

type PreRedirectErrorHandler func(w http.ResponseWriter, req *AuthorizeRequest, err error) error

PreRedirectErrorHandler is used to override "redirect-on-error" behavior

type RefreshingScopeHandler

type RefreshingScopeHandler func(tgr *oauth2.TokenGenerateRequest, oldScope string) (allowed bool, err error)

RefreshingScopeHandler check the scope of the refreshing token

type RefreshingValidationHandler added in v4.2.0

type RefreshingValidationHandler func(ti oauth2.TokenInfo) (allowed bool, err error)

RefreshingValidationHandler check if refresh_token is still valid. eg no revocation or other

type ResponseErrorHandler

type ResponseErrorHandler func(re *errors.Response)

ResponseErrorHandler response error handing

type ResponseTokenHandler added in v4.4.2

type ResponseTokenHandler func(w http.ResponseWriter, data map[string]interface{}, header http.Header, statusCode ...int) error

ResponseTokenHandler response token handing

type Server

type Server struct {
	Config                       *Config
	Manager                      oauth2.Manager
	ClientInfoHandler            ClientInfoHandler
	ClientAuthorizedHandler      ClientAuthorizedHandler
	ClientScopeHandler           ClientScopeHandler
	UserAuthorizationHandler     UserAuthorizationHandler
	PasswordAuthorizationHandler PasswordAuthorizationHandler
	RefreshingValidationHandler  RefreshingValidationHandler
	PreRedirectErrorHandler      PreRedirectErrorHandler
	RefreshingScopeHandler       RefreshingScopeHandler
	ResponseErrorHandler         ResponseErrorHandler
	InternalErrorHandler         InternalErrorHandler
	ExtensionFieldsHandler       ExtensionFieldsHandler
	AccessTokenExpHandler        AccessTokenExpHandler
	AuthorizeScopeHandler        AuthorizeScopeHandler
	ResponseTokenHandler         ResponseTokenHandler
}

Server Provide authorization server

func NewDefaultServer

func NewDefaultServer(manager oauth2.Manager) *Server

NewDefaultServer create a default authorization server

func NewServer

func NewServer(cfg *Config, manager oauth2.Manager) *Server

NewServer create authorization server

func (*Server) BearerAuth

func (s *Server) BearerAuth(r *http.Request) (string, bool)

BearerAuth parse bearer token

func (*Server) CheckCodeChallengeMethod added in v4.2.0

func (s *Server) CheckCodeChallengeMethod(ccm oauth2.CodeChallengeMethod) bool

CheckCodeChallengeMethod checks for allowed code challenge method

func (*Server) CheckGrantType

func (s *Server) CheckGrantType(gt oauth2.GrantType) bool

CheckGrantType check allows grant type

func (*Server) CheckResponseType

func (s *Server) CheckResponseType(rt oauth2.ResponseType) bool

CheckResponseType check allows response type

func (*Server) GetAccessToken

func (s *Server) GetAccessToken(ctx context.Context, gt oauth2.GrantType, tgr *oauth2.TokenGenerateRequest) (oauth2.TokenInfo,
	error)

GetAccessToken access token

func (*Server) GetAuthorizeData

func (s *Server) GetAuthorizeData(rt oauth2.ResponseType, ti oauth2.TokenInfo) map[string]interface{}

GetAuthorizeData get authorization response data

func (*Server) GetAuthorizeToken

func (s *Server) GetAuthorizeToken(ctx context.Context, req *AuthorizeRequest) (oauth2.TokenInfo, error)

GetAuthorizeToken get authorization token(code)

func (*Server) GetErrorData

func (s *Server) GetErrorData(err error) (map[string]interface{}, int, http.Header)

GetErrorData get error response data

func (*Server) GetRedirectURI

func (s *Server) GetRedirectURI(req *AuthorizeRequest, data map[string]interface{}) (string, error)

GetRedirectURI get redirect uri

func (*Server) GetTokenData

func (s *Server) GetTokenData(ti oauth2.TokenInfo) map[string]interface{}

GetTokenData token data

func (*Server) HandleAuthorizeRequest

func (s *Server) HandleAuthorizeRequest(w http.ResponseWriter, r *http.Request) error

HandleAuthorizeRequest the authorization request handling

func (*Server) HandleTokenRequest

func (s *Server) HandleTokenRequest(w http.ResponseWriter, r *http.Request) error

HandleTokenRequest token request handling

func (*Server) SetAccessTokenExpHandler

func (s *Server) SetAccessTokenExpHandler(handler AccessTokenExpHandler)

SetAccessTokenExpHandler set expiration date for the access token

func (*Server) SetAllowGetAccessRequest

func (s *Server) SetAllowGetAccessRequest(allow bool)

SetAllowGetAccessRequest to allow GET requests for the token

func (*Server) SetAllowedGrantType

func (s *Server) SetAllowedGrantType(types ...oauth2.GrantType)

SetAllowedGrantType allow the grant types

func (*Server) SetAllowedResponseType

func (s *Server) SetAllowedResponseType(types ...oauth2.ResponseType)

SetAllowedResponseType allow the authorization types

func (*Server) SetAuthorizeScopeHandler

func (s *Server) SetAuthorizeScopeHandler(handler AuthorizeScopeHandler)

SetAuthorizeScopeHandler set scope for the access token

func (*Server) SetClientAuthorizedHandler

func (s *Server) SetClientAuthorizedHandler(handler ClientAuthorizedHandler)

SetClientAuthorizedHandler check the client allows to use this authorization grant type

func (*Server) SetClientInfoHandler

func (s *Server) SetClientInfoHandler(handler ClientInfoHandler)

SetClientInfoHandler get client info from request

func (*Server) SetClientScopeHandler

func (s *Server) SetClientScopeHandler(handler ClientScopeHandler)

SetClientScopeHandler check the client allows to use scope

func (*Server) SetExtensionFieldsHandler

func (s *Server) SetExtensionFieldsHandler(handler ExtensionFieldsHandler)

SetExtensionFieldsHandler in response to the access token with the extension of the field

func (*Server) SetInternalErrorHandler

func (s *Server) SetInternalErrorHandler(handler InternalErrorHandler)

SetInternalErrorHandler internal error handling

func (*Server) SetPasswordAuthorizationHandler

func (s *Server) SetPasswordAuthorizationHandler(handler PasswordAuthorizationHandler)

SetPasswordAuthorizationHandler get user id from username and password

func (*Server) SetPreRedirectErrorHandler added in v4.4.3

func (s *Server) SetPreRedirectErrorHandler(handler PreRedirectErrorHandler)

SetPreRedirectErrorHandler sets the PreRedirectErrorHandler in current Server instance

func (*Server) SetRefreshingScopeHandler

func (s *Server) SetRefreshingScopeHandler(handler RefreshingScopeHandler)

SetRefreshingScopeHandler check the scope of the refreshing token

func (*Server) SetRefreshingValidationHandler added in v4.2.0

func (s *Server) SetRefreshingValidationHandler(handler RefreshingValidationHandler)

SetRefreshingValidationHandler check if refresh_token is still valid. eg no revocation or other

func (*Server) SetResponseErrorHandler

func (s *Server) SetResponseErrorHandler(handler ResponseErrorHandler)

SetResponseErrorHandler response error handling

func (*Server) SetResponseTokenHandler added in v4.4.2

func (s *Server) SetResponseTokenHandler(handler ResponseTokenHandler)

SetResponseTokenHandler response token handing

func (*Server) SetTokenType

func (s *Server) SetTokenType(tokenType string)

SetTokenType token type

func (*Server) SetUserAuthorizationHandler

func (s *Server) SetUserAuthorizationHandler(handler UserAuthorizationHandler)

SetUserAuthorizationHandler get user id from request authorization

func (*Server) ValidationAuthorizeRequest

func (s *Server) ValidationAuthorizeRequest(r *http.Request) (*AuthorizeRequest, error)

ValidationAuthorizeRequest the authorization request validation

func (*Server) ValidationBearerToken

func (s *Server) ValidationBearerToken(r *http.Request) (oauth2.TokenInfo, error)

ValidationBearerToken validation the bearer tokens https://tools.ietf.org/html/rfc6750

func (*Server) ValidationTokenRequest

func (s *Server) ValidationTokenRequest(r *http.Request) (oauth2.GrantType, *oauth2.TokenGenerateRequest, error)

ValidationTokenRequest the token request validation

type UserAuthorizationHandler

type UserAuthorizationHandler func(w http.ResponseWriter, r *http.Request) (userID string, err error)

UserAuthorizationHandler get user id from request authorization

Jump to

Keyboard shortcuts

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