o2

package
v1.1.3-0...-e5dd412 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2019 License: Apache-2.0 Imports: 17 Imported by: 3

Documentation

Index

Constants

View Source
const (
	//SessionUserID user id
	SessionUserID = "UserID"
)

Variables

This section is empty.

Functions

func AddUserHandler

func AddUserHandler(w http.ResponseWriter, r *http.Request)

add new user handler

func AddUserProcessor

func AddUserProcessor(w http.ResponseWriter, r *http.Request) (err error)

add new user

func AuthHandler

func AuthHandler(w http.ResponseWriter, r *http.Request)

func AuthorizeRequestHandler

func AuthorizeRequestHandler(w http.ResponseWriter, r *http.Request)

func AuthorizeScopeHandler

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

AuthorizeScopeHandler set the authorized scope

func BearerTokenValidator

func BearerTokenValidator(w http.ResponseWriter, r *http.Request)

func CheckUserAuth

func CheckUserAuth(w http.ResponseWriter, r *http.Request) (authorized bool, err error)

func ClientAuthorizedHandler

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

func ClientBasicAuth

func ClientBasicAuth(r *http.Request) (cid string, err error)

func ClientScopeHandler

func ClientScopeHandler(clientID, scope string) (allowed bool, err error)

ClientScopeHandler check the client allows to use scope

func ErrorResponse

func ErrorResponse(w http.ResponseWriter, err error, status int)

func FormatRedirectUri

func FormatRedirectUri(uri string) string

---------------------------

func GetOauth2Mgr

func GetOauth2Mgr() *manage.Manager

GetOauth2Mgr expose for custom configuration

func HandleProcessor

func HandleProcessor(processor func(w http.ResponseWriter, r *http.Request) error) func(w http.ResponseWriter, r *http.Request)

func HttpResponse

func HttpResponse(w http.ResponseWriter, data interface{}, status int)

func IndexHandler

func IndexHandler(w http.ResponseWriter, r *http.Request)

func InitServerConfig

func InitServerConfig(cfg *ServerConfig, mapper HandleMapper)

func InitTemplate

func InitTemplate()

InitTemplate initial tempalte

func InternalErrorHandler

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

func LoginHandler

func LoginHandler(w http.ResponseWriter, r *http.Request)

func PasswordAuthorizationHandler

func PasswordAuthorizationHandler(username, password string) (userID string, err error)

func RefreshingScopeHandler

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

RefreshingScopeHandler check the scope of the refreshing token

func RemoveUserProcessor

func RemoveUserProcessor(w http.ResponseWriter, r *http.Request) (err error)

remove user processor

func ResponseErrorHandler

func ResponseErrorHandler(re *errors.Response)

func TokenRequestHandler

func TokenRequestHandler(w http.ResponseWriter, r *http.Request)

func UpdatePwdProcessor

func UpdatePwdProcessor(w http.ResponseWriter, r *http.Request) (err error)

update password processor

func UpdateScopeProcessor

func UpdateScopeProcessor(w http.ResponseWriter, r *http.Request) (err error)

update scope processor

Types

type GrantTypeRequestValidator

type GrantTypeRequestValidator func(r *http.Request) (gt oauth2.GrantType, tgr *oauth2.TokenGenerateRequest, err error)

type HandleConfigurer

type HandleConfigurer func(mapper HandleMapper)

type HandleMapper

type HandleMapper func(method, pattern string, handler func(w http.ResponseWriter, r *http.Request))

type Oauth2Server

type Oauth2Server struct {
	*server.Server
	// contains filtered or unexported fields
}

Oauth2Server oauth2 server

func GetOauth2Svr

func GetOauth2Svr() *Oauth2Server

GetOauth2Svr expose for custom configuration

func InitOauth2Server

func InitOauth2Server(cs oauth2.ClientStore, ts oauth2.TokenStore, us o2x.UserStore, as o2x.AuthStore,
	cfg *ServerConfig, mapper HandleMapper) *Oauth2Server

InitOauth2Server initial a oauth2 server with storage services

func NewServer

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

NewServer create authorization server

func (*Oauth2Server) AddCustomerGrantType

func (s *Oauth2Server) AddCustomerGrantType(grantType oauth2.GrantType, validator GrantTypeRequestValidator, handleConfigurer HandleConfigurer)

AddCustomerGrantType add customer grant type

func (*Oauth2Server) AddHandler

func (s *Oauth2Server) AddHandler(method, uri string, handler func(w http.ResponseWriter, r *http.Request))

AddHandler add http handler

func (*Oauth2Server) DisableMultipleUserToken

func (s *Oauth2Server) DisableMultipleUserToken()

DisableMultipleUserToken user can have only one token one time

func (*Oauth2Server) EnableMultipleUserToken

func (s *Oauth2Server) EnableMultipleUserToken()

EnableMultipleUserToken user can have multiple token one time

func (*Oauth2Server) GetUserStore

func (s *Oauth2Server) GetUserStore() o2x.UserStore

GetUserStore get user store

func (*Oauth2Server) HandleTokenRequest

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

HandleTokenRequest token request handling

func (*Oauth2Server) ParseJWTAccessToken

func (s *Oauth2Server) ParseJWTAccessToken(access string) (claims *jwtex.Oauth2Claims, err error)

ParseJWTAccessToken valid jwt access token

func (*Oauth2Server) ValidationTokenRequest

func (s *Oauth2Server) ValidationTokenRequest(r *http.Request) (gt oauth2.GrantType, tgr *oauth2.TokenGenerateRequest, err error)

ValidationTokenRequest the token request validation, add user client scope validation

type ServerConfig

type ServerConfig struct {
	// oauth2 server name, will be show in login and authorize page
	ServerName string

	// favicon url
	Favicon string

	Logo string

	// uri context
	URIContext string

	// uri prefix to add before authRedirect uri
	URIPrefix string

	// JWTSupport jwt token
	JWTSupport bool

	//JWT config
	JWT jwtex.JWTConfig
}

ServerConfig oauth2 server config

func DefaultServerConfig

func DefaultServerConfig() *ServerConfig

DefaultServerConfig default server config

Jump to

Keyboard shortcuts

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