server

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2020 License: MIT Imports: 9 Imported by: 0

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
	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(clientID, scope string) (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
}

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(username, password string) (userID string, err error)

PasswordAuthorizationHandler get user id from username and password

type RefreshingScopeHandler

type RefreshingScopeHandler func(newScope, oldScope string) (allowed bool, err error)

RefreshingScopeHandler check the scope of the refreshing token

type ResponseErrorHandler

type ResponseErrorHandler func(re *errors.Response)

ResponseErrorHandler response error handing

type Server

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

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) 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) SetRefreshingScopeHandler

func (s *Server) SetRefreshingScopeHandler(handler RefreshingScopeHandler)

SetRefreshingScopeHandler check the scope of the refreshing token

func (*Server) SetResponseErrorHandler

func (s *Server) SetResponseErrorHandler(handler ResponseErrorHandler)

SetResponseErrorHandler response error handling

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