server

package
v0.0.0-...-730ab85 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultCodeExp               = time.Minute * 10
	DefaultAuthorizeCodeTokenCfg = &TokenConfig{AccessTokenExp: time.Hour * 2, RefreshTokenExp: time.Hour * 24 * 3, IsGenerateRefresh: true}
	DefaultImplicitTokenCfg      = &TokenConfig{AccessTokenExp: time.Hour * 1}
	DefaultPasswordTokenCfg      = &TokenConfig{AccessTokenExp: time.Hour * 2, RefreshTokenExp: time.Hour * 24 * 7, IsGenerateRefresh: true}
	DefaultClientTokenCfg        = &TokenConfig{AccessTokenExp: time.Hour * 2}
	DefaultRefreshTokenCfg       = &RefreshingConfig{IsGenerateRefresh: true, IsRemoveAccess: true, IsRemoveRefreshing: true}
)

Functions

func ClientBasicHandler

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

func ClientFormHandler

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

func DefPasswordAuthorizationHandler

func DefPasswordAuthorizationHandler(username, password string) (string, error)

func DefUserAuthorizationHandler

func DefUserAuthorizationHandler(w http.ResponseWriter, r *http.Request) (string, error)

func DefValidateURIHandler

func DefValidateURIHandler(baseURI string, redirectURI string) error

func GetDefaultStore

func GetDefaultStore() store.Store

func GetDefaultTokenConfig

func GetDefaultTokenConfig() map[api.GrantType]*TokenConfig

Types

type AuthCodeOption

type AuthCodeOption interface {
	// contains filtered or unexported methods
}
var (
	AccessTypeOnline  AuthCodeOption = SetAuthURLParam("access_type", "online")
	AccessTypeOffline AuthCodeOption = SetAuthURLParam("access_type", "offline")
	ApprovalForce     AuthCodeOption = SetAuthURLParam("prompt", "consent")
)

func SetAuthURLParam

func SetAuthURLParam(key, value string) AuthCodeOption

type AuthorizeRequest

type AuthorizeRequest struct {
	ResponseType api.ResponseType
	ClientID     string
	ClientSecret string
	Scope        string
	RedirectURI  string
	State        string

	UserID string
}

type AuthorizeScopeHandler

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

type ClientAuthorizedHandler

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

type ClientInfoHandler

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

type ClientScopeHandler

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

type ExtensionFieldsHandler

type ExtensionFieldsHandler func(t *token.Token) (fieldsValue map[string]interface{})

type Generates

type Generates struct {
	TokenType         string
	MacAlgorithm      string
	AllowedGrantTypes []api.GrantType

	ClientStore *stores.ClientStore
	TokenStore  *stores.TokenStore

	AuthorizeGenerate generates.AuthorizeGenerate
	AccessGenerate    generates.AccessGenerate

	ValidateURIHandler     ValidateURIHandler
	ExtensionFieldsHandler ExtensionFieldsHandler

	ClientAuthorizedHandler ClientAuthorizedHandler
	ClientScopeHandler      ClientScopeHandler
	RefreshingScopeHandler  RefreshingScopeHandler
	// contains filtered or unexported fields
}

func (*Generates) GetAccessToken

func (g *Generates) GetAccessToken(ctx context.Context, tr *TokenRequest) (*token.Token, error)

func (*Generates) GetAuthorizeToken

func (g *Generates) GetAuthorizeToken(ctx context.Context, req *AuthorizeRequest) (*token.Token, error)

func (*Generates) LoadAccessToken

func (g *Generates) LoadAccessToken(ctx context.Context, access string) (*token.Token, error)

type MacRequest

type MacRequest struct {
	// contains filtered or unexported fields
}

type Oauth2

type Oauth2 struct {
	ClientInfoHandler            ClientInfoHandler
	UserAuthorizationHandler     UserAuthorizationHandler
	PasswordAuthorizationHandler PasswordAuthorizationHandler
	AuthorizeScopeHandler        AuthorizeScopeHandler
	ValidateClientHandler        ValidateClientHandler
	// contains filtered or unexported fields
}

func NewOauth2

func NewOauth2(opts *Options) *Oauth2

func (*Oauth2) HandleAuthorizeRequest

func (o *Oauth2) HandleAuthorizeRequest(w http.ResponseWriter, r *http.Request) error

func (*Oauth2) HandleTokenRequest

func (o *Oauth2) HandleTokenRequest(w http.ResponseWriter, r *http.Request) error

func (*Oauth2) SaveClient

func (o *Oauth2) SaveClient(ctx context.Context, client *stores.Client)

func (*Oauth2) SetAccessGenerate

func (o *Oauth2) SetAccessGenerate(accessGenerate generates.AccessGenerate)

func (*Oauth2) SetAuthorizeGenerate

func (o *Oauth2) SetAuthorizeGenerate(authorizeGenerate generates.AuthorizeGenerate)

func (*Oauth2) SetClientAuthorizedHandler

func (o *Oauth2) SetClientAuthorizedHandler(clientAuthorizedHandler ClientAuthorizedHandler)

func (*Oauth2) SetClientScopeHandler

func (o *Oauth2) SetClientScopeHandler(clientScopeHandler ClientScopeHandler)

func (*Oauth2) SetClientStore

func (o *Oauth2) SetClientStore(clientStore *stores.ClientStore)

func (*Oauth2) SetExtensionFieldsHandler

func (o *Oauth2) SetExtensionFieldsHandler(extensionFieldsHandler ExtensionFieldsHandler)

func (*Oauth2) SetRefreshingScopeHandler

func (o *Oauth2) SetRefreshingScopeHandler(refreshingScopeHandler RefreshingScopeHandler)

func (*Oauth2) SetTokenStore

func (o *Oauth2) SetTokenStore(tokenStore *stores.TokenStore)

func (*Oauth2) SetValidateURIHandler

func (o *Oauth2) SetValidateURIHandler(validateURIHandler ValidateURIHandler)

func (*Oauth2) ValidationBearerToken

func (o *Oauth2) ValidationBearerToken(r *http.Request) (*token.Token, error)

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

func (*Oauth2) ValidationMACToken

func (o *Oauth2) ValidationMACToken(r *http.Request) (*token.Token, error)

type Options

type Options struct {
	TokenType             string
	AllowGetAccessRequest bool
	AllowedResponseTypes  []api.ResponseType
	AllowedGrantTypes     []api.GrantType

	MacAlgorithm string
	// contains filtered or unexported fields
}

func (*Options) SetCodeExp

func (opt *Options) SetCodeExp(codeExp time.Duration)

func (*Options) SetRefreshConfig

func (opt *Options) SetRefreshConfig(refreshingConfig *RefreshingConfig)

func (*Options) SetTokenConfig

func (opt *Options) SetTokenConfig(gt api.GrantType, tc *TokenConfig)

type PasswordAuthorizationHandler

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

type RefreshingConfig

type RefreshingConfig struct {
	AccessTokenExp     time.Duration
	RefreshTokenExp    time.Duration
	IsGenerateRefresh  bool
	IsResetRefreshTime bool
	IsRemoveAccess     bool
	IsRemoveRefreshing bool
}

type RefreshingScopeHandler

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

type Request

type Request struct {
	Request               *http.Request
	AllowedResponseTypes  []api.ResponseType
	AllowGetAccessRequest bool

	ClientInfoHandler            ClientInfoHandler
	PasswordAuthorizationHandler PasswordAuthorizationHandler
}

func (*Request) BearerAuth

func (re *Request) BearerAuth() (string, bool)

func (*Request) MacAuth

func (re *Request) MacAuth() (*MacRequest, error)

id / ts / nonce / ext / mac

func (*Request) ValidationAuthorizeRequest

func (re *Request) ValidationAuthorizeRequest() (*AuthorizeRequest, error)

func (*Request) ValidationTokenRequest

func (re *Request) ValidationTokenRequest() (*TokenRequest, error)

type Response

type Response struct {
	Writer http.ResponseWriter
}

func (*Response) ErrorData

func (res *Response) ErrorData(err error) (map[string]interface{}, int)

func (*Response) OutputToken

func (res *Response) OutputToken(data map[string]interface{}, statusCode ...int) error

func (*Response) OutputTokenError

func (res *Response) OutputTokenError(err error) error

func (*Response) Redirect

func (res *Response) Redirect(uri string) error

type TokenConfig

type TokenConfig struct {
	AccessTokenExp    time.Duration
	RefreshTokenExp   time.Duration
	IsGenerateRefresh bool
}

type TokenRequest

type TokenRequest struct {
	GrantType    api.GrantType
	ClientID     string
	ClientSecret string
	Code         string
	RedirectURI  string

	Scope   string
	Refresh string
	UserID  string
}

type UserAuthorizationHandler

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

type ValidateClientHandler

type ValidateClientHandler func(nonce string, ts int, ext string) (allowed bool, err error)

type ValidateURIHandler

type ValidateURIHandler func(baseURI, redirectURI string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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