definition

package module
v0.0.0-...-fa9cb49 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2023 License: Apache-2.0 Imports: 6 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessGenerate

type AccessGenerate interface {
	Token(ctx context.Context, data *GenerateBasic, isGenRefresh bool) (body GenerateTokenBody, err error)
}

AccessGenerate generate the access and refresh tokens interface

type AuthorizeGenerate

type AuthorizeGenerate interface {
	Token(ctx context.Context, data *GenerateBasic) (code string, err error)
}

AuthorizeGenerate generate the authorization code interface

type ClientInfo

type ClientInfo interface {
	GetID() string
	GetSecret() string
	GetDomain() string
	IsPublic() bool
	GetUserID() string
}

ClientInfo the client information model interface

type ClientPasswordVerifier

type ClientPasswordVerifier interface {
	VerifyPassword(string) bool
}

ClientPasswordVerifier the password handler interface

type ClientStore

type ClientStore interface {
	// GetByID according to the ID for the client information
	GetByID(ctx context.Context, id string) (ClientInfo, error)
}

ClientStore the client information storage interface

type CodeChallengeMethod

type CodeChallengeMethod string

CodeChallengeMethod PCKE method

const (
	// CodeChallengePlain PCKE Method
	CodeChallengePlain CodeChallengeMethod = "plain"
	// CodeChallengeS256 PCKE Method
	CodeChallengeS256 CodeChallengeMethod = "S256"
)

func (CodeChallengeMethod) String

func (ccm CodeChallengeMethod) String() string

func (CodeChallengeMethod) Validate

func (ccm CodeChallengeMethod) Validate(cc, ver string) bool

Validate code challenge

type CodeInfo

type CodeInfo interface {
	CodeInfoAdapter

	GetClientID() string
	SetClientID(string)
	GetUserID() string
	SetUserID(string)
	GetRedirectURI() string
	SetRedirectURI(string)
	GetScope() string
	SetScope(string)

	GetCode() string
	// SetCode code should be a random string that 32 length size, seem like a string id.
	SetCode(string)
	GetChallenge() string
	SetChallenge(string)
	GetChallengeMethod() CodeChallengeMethod
	SetChallengeMethod(CodeChallengeMethod)
	GetExpiredAt() time.Time
	SetExpiredAt(time.Time)
}

CodeInfo the authorization code information model interface

type CodeInfoAdapter

type CodeInfoAdapter interface {
	New() CodeInfo
}

type GenerateBasic

type GenerateBasic struct {
	Client    ClientInfo
	UserID    string
	CreateAt  time.Time
	TokenInfo TokenInfo
	Request   *http.Request
}

GenerateBasic provide the basis of the generated token data

type GenerateTokenBody

type GenerateTokenBody struct {
	Code             string
	Access           string
	AccessIdentifier string
	Refresh          string
}

GenerateTokenBody generator's result, if there is a AccessIdentifier (which is set for jwt, the result token is too large), you can just save the identifier to storage

type GrantType

type GrantType string

GrantType authorization model

const (
	AuthorizationCode   GrantType = "authorization_code"
	PasswordCredentials GrantType = "password"
	ClientCredentials   GrantType = "client_credentials"
	Refreshing          GrantType = "refresh_token"
	Implicit            GrantType = "__implicit"
)

define authorization model

func (GrantType) String

func (gt GrantType) String() string

type LogLevel

type LogLevel int8
const (
	LogLevelFalat LogLevel = iota
	LogLevelError
	LogLevelInfo
	LogLevelTrace
)

type Logger

type Logger interface {
	Falatf(format string, args ...any)
	Errorf(format string, args ...any)
	Infof(format string, args ...any)
}

Logger interface

type Manager

type Manager interface {
	// GetClient get the client information
	GetClient(ctx context.Context, clientID string) (cli ClientInfo, err error)

	// SetCodeAdapter auth code model adapter
	SetCodeAdapter(adp CodeInfoAdapter)
	// SetTokenAdapter access token model adapter
	SetTokenAdapter(adp TokenInfoAdapter)

	// GenerateAuthToken generate the authorization code
	GenerateAuthToken(ctx context.Context, rt ResponseType, tgr *TokenGenerateRequest) (rb any, err error)

	// GenerateAccessToken generate the access token(authorize token)
	GenerateAccessToken(ctx context.Context, gt GrantType, tgr *TokenGenerateRequest) (accessToken TokenInfo, err error)

	// RefreshAccessToken refreshing an access token
	RefreshAccessToken(ctx context.Context, tgr *TokenGenerateRequest) (accessToken TokenInfo, err error)

	// RemoveAccessToken use the access token to delete the token information
	RemoveAccessToken(ctx context.Context, access string) (err error)

	// RemoveRefreshToken use the refresh token to delete the token information
	RemoveRefreshToken(ctx context.Context, refresh string) (err error)

	// LoadAccessToken according to the access token for corresponding token information
	LoadAccessToken(ctx context.Context, access string) (ti TokenInfo, err error)

	// LoadRefreshToken according to the refresh token for corresponding token information
	LoadRefreshToken(ctx context.Context, refresh string) (ti TokenInfo, err error)
}

Manager authorization management interface

type ResponseType

type ResponseType string

ResponseType the type of authorization request

const (
	Code  ResponseType = "code"
	Token ResponseType = "token"
)

define the type of authorization request

func (ResponseType) String

func (rt ResponseType) String() string

type TokenGenerateRequest

type TokenGenerateRequest struct {
	ClientID            string
	ClientSecret        string
	UserID              string
	RedirectURI         string
	Scope               string
	Code                string
	CodeChallenge       string
	CodeChallengeMethod CodeChallengeMethod
	Refresh             string
	CodeVerifier        string
	Request             *http.Request
}

TokenGenerateRequest provide to generate the token request parameters

type TokenInfo

type TokenInfo interface {
	TokenInfoAdapter

	GetClientID() string
	SetClientID(string)
	GetUserID() string
	SetUserID(string)
	GetScope() string
	SetScope(string)

	GetAccess() string
	// SetAccess access should be a random string that 32 length size, seem like a string id.
	SetAccess(string)
	GetAccessIdentifier() string
	SetAccessIdentifier(string)
	GetExpiredAt() time.Time
	SetExpiredAt(time.Time)
	GetRefresh() string
	// SetRefresh refresh should be a random string that 32 length size, seem like a string id.
	SetRefresh(string)
	GetRefreshExpiredAt() time.Time
	SetRefreshExpiredAt(time.Time)
}

TokenInfo the access token information model interface

type TokenInfoAdapter

type TokenInfoAdapter interface {
	New() TokenInfo
}

type TokenStore

type TokenStore interface {
	// Create and store the new token information,
	// info must be one of CodeInfo, TokenInfo, RefreshInfo
	Create(ctx context.Context, info any) error

	// RemoveByCode delete the authorization code
	RemoveByCode(ctx context.Context, code string) error

	// RemoveByAccess use the access token to delete the token information
	RemoveByAccess(ctx context.Context, access string) error

	// RemoveByRefresh use the refresh token to delete the token information
	RemoveByRefresh(ctx context.Context, refresh string) error

	// GetByCode use the authorization code for token information data
	GetByCode(ctx context.Context, code string) (CodeInfo, error)

	// GetByAccess use the access token for token information data
	GetByAccess(ctx context.Context, access string) (TokenInfo, error)

	// GetByRefresh use the refresh token for token information data
	GetByRefresh(ctx context.Context, refresh string) (TokenInfo, error)
}

TokenStore the token information storage interface

type TraceableLogger

type TraceableLogger interface {
	Tracef(format string, args ...any)
}

TraceableLogger interface

Jump to

Keyboard shortcuts

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