manage

package
v0.0.0-...-61905c3 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: GPL-2.0, MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

default configs

Functions

func DefaultValidateURI

func DefaultValidateURI(baseURI string, redirectURI string) error

DefaultValidateURI validates that redirectURI is contained in baseURI

Types

type Config

type Config struct {
	// access token expiration time, 0 means it doesn't expire
	AccessTokenExp time.Duration
	// refresh token expiration time, 0 means it doesn't expire
	RefreshTokenExp time.Duration
	// whether to generate the refreshing token
	IsGenerateRefresh bool
}

Config authorization configuration parameters

type Manager

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

Manager provide authorization management

func NewDefaultManager

func NewDefaultManager() *Manager

NewDefaultManager create to default authorization management instance

func NewManager

func NewManager() *Manager

NewManager create to authorization management instance

func (*Manager) GenerateAccessToken

func (m *Manager) GenerateAccessToken(ctx context.Context, gt oauth2.GrantType, tgr *oauth2.TokenGenerateRequest) (oauth2.TokenInfo, error)

GenerateAccessToken generate the access token

func (*Manager) GenerateAuthToken

func (m *Manager) GenerateAuthToken(ctx context.Context, rt oauth2.ResponseType, tgr *oauth2.TokenGenerateRequest) (oauth2.TokenInfo, error)

GenerateAuthToken generate the authorization token(code)

func (*Manager) GetClient

func (m *Manager) GetClient(ctx context.Context, clientID string) (cli oauth2.ClientInfo, err error)

GetClient get the client information

func (*Manager) LoadAccessToken

func (m *Manager) LoadAccessToken(ctx context.Context, access string) (oauth2.TokenInfo, error)

LoadAccessToken according to the access token for corresponding token information

func (*Manager) LoadRefreshToken

func (m *Manager) LoadRefreshToken(ctx context.Context, refresh string) (oauth2.TokenInfo, error)

LoadRefreshToken according to the refresh token for corresponding token information

func (*Manager) MapAccessGenerate

func (m *Manager) MapAccessGenerate(gen oauth2.AccessGenerate)

MapAccessGenerate mapping the access token generate interface

func (*Manager) MapAuthorizeGenerate

func (m *Manager) MapAuthorizeGenerate(gen oauth2.AuthorizeGenerate)

MapAuthorizeGenerate mapping the authorize code generate interface

func (*Manager) MapClientStorage

func (m *Manager) MapClientStorage(stor oauth2.ClientStore)

MapClientStorage mapping the client store interface

func (*Manager) MapTokenStorage

func (m *Manager) MapTokenStorage(stor oauth2.TokenStore)

MapTokenStorage mapping the token store interface

func (*Manager) MustClientStorage

func (m *Manager) MustClientStorage(stor oauth2.ClientStore, err error)

MustClientStorage mandatory mapping the client store interface

func (*Manager) MustTokenStorage

func (m *Manager) MustTokenStorage(stor oauth2.TokenStore, err error)

MustTokenStorage mandatory mapping the token store interface

func (*Manager) RefreshAccessToken

func (m *Manager) RefreshAccessToken(ctx context.Context, tgr *oauth2.TokenGenerateRequest) (oauth2.TokenInfo, error)

RefreshAccessToken refreshing an access token

func (*Manager) RemoveAccessToken

func (m *Manager) RemoveAccessToken(ctx context.Context, access string) error

RemoveAccessToken use the access token to delete the token information

func (*Manager) RemoveRefreshToken

func (m *Manager) RemoveRefreshToken(ctx context.Context, refresh string) error

RemoveRefreshToken use the refresh token to delete the token information

func (*Manager) SetAuthorizeCodeExp

func (m *Manager) SetAuthorizeCodeExp(exp time.Duration)

SetAuthorizeCodeExp set the authorization code expiration time

func (*Manager) SetAuthorizeCodeTokenCfg

func (m *Manager) SetAuthorizeCodeTokenCfg(cfg *Config)

SetAuthorizeCodeTokenCfg set the authorization code grant token config

func (*Manager) SetClientTokenCfg

func (m *Manager) SetClientTokenCfg(cfg *Config)

SetClientTokenCfg set the client grant token config

func (*Manager) SetImplicitTokenCfg

func (m *Manager) SetImplicitTokenCfg(cfg *Config)

SetImplicitTokenCfg set the implicit grant token config

func (*Manager) SetPasswordTokenCfg

func (m *Manager) SetPasswordTokenCfg(cfg *Config)

SetPasswordTokenCfg set the password grant token config

func (*Manager) SetRefreshTokenCfg

func (m *Manager) SetRefreshTokenCfg(cfg *RefreshingConfig)

SetRefreshTokenCfg set the refreshing token config

func (*Manager) SetValidateURIHandler

func (m *Manager) SetValidateURIHandler(handler ValidateURIHandler)

SetValidateURIHandler set the validates that RedirectURI is contained in baseURI

type RefreshingConfig

type RefreshingConfig struct {
	// access token expiration time, 0 means it doesn't expire
	AccessTokenExp time.Duration
	// refresh token expiration time, 0 means it doesn't expire
	RefreshTokenExp time.Duration
	// whether to generate the refreshing token
	IsGenerateRefresh bool
	// whether to reset the refreshing create time
	IsResetRefreshTime bool
	// whether to remove access token
	IsRemoveAccess bool
	// whether to remove refreshing token
	IsRemoveRefreshing bool
}

RefreshingConfig refreshing token config

type ValidateURIHandler

type ValidateURIHandler func(baseURI, redirectURI string) error

ValidateURIHandler validates that redirectURI is contained in baseURI

Jump to

Keyboard shortcuts

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