Documentation ¶
Index ¶
- Variables
- type ClientDetailsService
- type CommentService
- type ComposeTokenGranter
- type DefaultTokenService
- func (tokenService *DefaultTokenService) CreateAccessToken(oauth2Details *OAuth2Details) (*OAuth2Token, error)
- func (tokenService *DefaultTokenService) GetAccessToken(details *OAuth2Details) (*OAuth2Token, error)
- func (tokenService *DefaultTokenService) GetOAuth2DetailsByAccessToken(tokenValue string) (*OAuth2Details, error)
- func (tokenService *DefaultTokenService) ReadAccessToken(tokenValue string) (*OAuth2Token, error)
- func (tokenService *DefaultTokenService) RefreshAccessToken(refreshTokenValue string) (*OAuth2Token, error)
- type JwtTokenEnhancer
- type JwtTokenStore
- func (tokenStore *JwtTokenStore) GetAccessToken(oauth2Details *OAuth2Details) (*OAuth2Token, error)
- func (tokenStore *JwtTokenStore) ReadAccessToken(tokenValue string) (*OAuth2Token, error)
- func (tokenStore *JwtTokenStore) ReadOAuth2Details(tokenValue string) (*OAuth2Details, error)
- func (tokenStore *JwtTokenStore) ReadOAuth2DetailsForRefreshToken(tokenValue string) (*OAuth2Details, error)
- func (tokenStore *JwtTokenStore) ReadRefreshToken(tokenValue string) (*OAuth2Token, error)
- func (tokenStore *JwtTokenStore) RemoveAccessToken(tokenValue string)
- func (tokenStore *JwtTokenStore) RemoveRefreshToken(oauth2Token string)
- func (tokenStore *JwtTokenStore) StoreAccessToken(oauth2Token *OAuth2Token, oauth2Details *OAuth2Details)
- func (tokenStore *JwtTokenStore) StoreRefreshToken(oauth2Token *OAuth2Token, oauth2Details *OAuth2Details)
- type MysqlClientDetailsService
- type OAuth2TokenCustomClaims
- type RefreshTokenGranter
- type RemoteUserService
- type Service
- type ServiceMiddleware
- type TokenEnhancer
- type TokenGranter
- type TokenService
- type TokenStore
- type UserDetailsService
- type UsernamePasswordTokenGranter
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNotSupportGrantType = errors.New("grant type is not supported") ErrNotSupportOperation = errors.New("no support operation") ErrInvalidUsernameAndPasswordRequest = errors.New("invalid username, password") ErrInvalidTokenRequest = errors.New("invalid token") ErrExpiredToken = errors.New("token is expired") )
View Source
var ( InvalidAuthentication = errors.New("invalid auth") InvalidUserInfo = errors.New("invalid user info") )
View Source
var (
ErrClientMessage = errors.New("invalid client")
)
Functions ¶
This section is empty.
Types ¶
type ClientDetailsService ¶
type ClientDetailsService interface {
GetClientDetailByClientId(ctx context.Context, clientId string, clientSecret string) (*model.ClientDetails, error)
}
Service Define a service interface
func NewMysqlClientDetailsService ¶
func NewMysqlClientDetailsService() ClientDetailsService
type CommentService ¶
type CommentService struct { }
func NewCommentService ¶
func NewCommentService() *CommentService
func (*CommentService) HealthCheck ¶
func (s *CommentService) HealthCheck() bool
HealthCheck implement Service method 用于检查服务的健康状态,这里仅仅返回true
type ComposeTokenGranter ¶
type ComposeTokenGranter struct {
TokenGrantDict map[string]TokenGranter
}
type DefaultTokenService ¶
type DefaultTokenService struct {
// contains filtered or unexported fields
}
func (*DefaultTokenService) CreateAccessToken ¶
func (tokenService *DefaultTokenService) CreateAccessToken(oauth2Details *OAuth2Details) (*OAuth2Token, error)
func (*DefaultTokenService) GetAccessToken ¶
func (tokenService *DefaultTokenService) GetAccessToken(details *OAuth2Details) (*OAuth2Token, error)
func (*DefaultTokenService) GetOAuth2DetailsByAccessToken ¶
func (tokenService *DefaultTokenService) GetOAuth2DetailsByAccessToken(tokenValue string) (*OAuth2Details, error)
func (*DefaultTokenService) ReadAccessToken ¶
func (tokenService *DefaultTokenService) ReadAccessToken(tokenValue string) (*OAuth2Token, error)
func (*DefaultTokenService) RefreshAccessToken ¶
func (tokenService *DefaultTokenService) RefreshAccessToken(refreshTokenValue string) (*OAuth2Token, error)
type JwtTokenEnhancer ¶
type JwtTokenEnhancer struct {
// contains filtered or unexported fields
}
func (*JwtTokenEnhancer) Enhance ¶
func (enhancer *JwtTokenEnhancer) Enhance(oauth2Token *OAuth2Token, oauth2Details *OAuth2Details) (*OAuth2Token, error)
func (*JwtTokenEnhancer) Extract ¶
func (enhancer *JwtTokenEnhancer) Extract(tokenValue string) (*OAuth2Token, *OAuth2Details, error)
type JwtTokenStore ¶
type JwtTokenStore struct {
// contains filtered or unexported fields
}
func (*JwtTokenStore) GetAccessToken ¶
func (tokenStore *JwtTokenStore) GetAccessToken(oauth2Details *OAuth2Details) (*OAuth2Token, error)
根据客户端信息和用户信息获取访问令牌
func (*JwtTokenStore) ReadAccessToken ¶
func (tokenStore *JwtTokenStore) ReadAccessToken(tokenValue string) (*OAuth2Token, error)
func (*JwtTokenStore) ReadOAuth2Details ¶
func (tokenStore *JwtTokenStore) ReadOAuth2Details(tokenValue string) (*OAuth2Details, error)
根据令牌值获取令牌对应的客户端和用户信息
func (*JwtTokenStore) ReadOAuth2DetailsForRefreshToken ¶
func (tokenStore *JwtTokenStore) ReadOAuth2DetailsForRefreshToken(tokenValue string) (*OAuth2Details, error)
根据令牌值获取刷新令牌对应的客户端和用户信息
func (*JwtTokenStore) ReadRefreshToken ¶
func (tokenStore *JwtTokenStore) ReadRefreshToken(tokenValue string) (*OAuth2Token, error)
根据令牌值获取刷新令牌
func (*JwtTokenStore) RemoveAccessToken ¶
func (tokenStore *JwtTokenStore) RemoveAccessToken(tokenValue string)
移除存储的访问令牌
func (*JwtTokenStore) RemoveRefreshToken ¶
func (tokenStore *JwtTokenStore) RemoveRefreshToken(oauth2Token string)
移除存储的刷新令牌
func (*JwtTokenStore) StoreAccessToken ¶
func (tokenStore *JwtTokenStore) StoreAccessToken(oauth2Token *OAuth2Token, oauth2Details *OAuth2Details)
func (*JwtTokenStore) StoreRefreshToken ¶
func (tokenStore *JwtTokenStore) StoreRefreshToken(oauth2Token *OAuth2Token, oauth2Details *OAuth2Details)
存储刷新令牌
type MysqlClientDetailsService ¶
type MysqlClientDetailsService struct { }
func (*MysqlClientDetailsService) GetClientDetailByClientId ¶
func (service *MysqlClientDetailsService) GetClientDetailByClientId(ctx context.Context, clientId string, clientSecret string) (*model.ClientDetails, error)
type OAuth2TokenCustomClaims ¶
type OAuth2TokenCustomClaims struct { UserDetails UserDetails ClientDetails ClientDetails RefreshToken OAuth2Token jwt.StandardClaims }
type RefreshTokenGranter ¶
type RefreshTokenGranter struct {
// contains filtered or unexported fields
}
type RemoteUserService ¶
type RemoteUserService struct {
// contains filtered or unexported fields
}
UserService implement Service interface
func NewRemoteUserDetailService ¶
func NewRemoteUserDetailService() *RemoteUserService
func (*RemoteUserService) GetUserDetailByUsername ¶
func (service *RemoteUserService) GetUserDetailByUsername(ctx context.Context, username, password string) (*model.UserDetails, error)
type Service ¶
type Service interface { // HealthCheck check service health status HealthCheck() bool }
type ServiceMiddleware ¶
ServiceMiddleware define service middleware
type TokenEnhancer ¶
type TokenEnhancer interface { // 组装 Token 信息 Enhance(oauth2Token *OAuth2Token, oauth2Details *OAuth2Details) (*OAuth2Token, error) // 从 Token 中还原信息 Extract(tokenValue string) (*OAuth2Token, *OAuth2Details, error) }
func NewJwtTokenEnhancer ¶
func NewJwtTokenEnhancer(secretKey string) TokenEnhancer
type TokenGranter ¶
type TokenGranter interface {
Grant(ctx context.Context, grantType string, client *ClientDetails, reader *http.Request) (*OAuth2Token, error)
}
func NewComposeTokenGranter ¶
func NewComposeTokenGranter(tokenGrantDict map[string]TokenGranter) TokenGranter
func NewRefreshGranter ¶
func NewRefreshGranter(grantType string, userDetailsService UserDetailsService, tokenService TokenService) TokenGranter
func NewUsernamePasswordTokenGranter ¶
func NewUsernamePasswordTokenGranter(grantType string, userDetailsService UserDetailsService, tokenService TokenService) TokenGranter
type TokenService ¶
type TokenService interface { // 根据访问令牌获取对应的用户信息和客户端信息 GetOAuth2DetailsByAccessToken(tokenValue string) (*OAuth2Details, error) // 根据用户信息和客户端信息生成访问令牌 CreateAccessToken(oauth2Details *OAuth2Details) (*OAuth2Token, error) // 根据刷新令牌获取访问令牌 RefreshAccessToken(refreshTokenValue string) (*OAuth2Token, error) // 根据用户信息和客户端信息获取已生成访问令牌 GetAccessToken(details *OAuth2Details) (*OAuth2Token, error) // 根据访问令牌值获取访问令牌结构体 ReadAccessToken(tokenValue string) (*OAuth2Token, error) }
func NewTokenService ¶
func NewTokenService(tokenStore TokenStore, tokenEnhancer TokenEnhancer) TokenService
type TokenStore ¶
type TokenStore interface { // 存储访问令牌 StoreAccessToken(oauth2Token *OAuth2Token, oauth2Details *OAuth2Details) // 根据令牌值获取访问令牌结构体 ReadAccessToken(tokenValue string) (*OAuth2Token, error) // 根据令牌值获取令牌对应的客户端和用户信息 ReadOAuth2Details(tokenValue string) (*OAuth2Details, error) // 根据客户端信息和用户信息获取访问令牌 GetAccessToken(oauth2Details *OAuth2Details) (*OAuth2Token, error) // 移除存储的访问令牌 RemoveAccessToken(tokenValue string) // 存储刷新令牌 StoreRefreshToken(oauth2Token *OAuth2Token, oauth2Details *OAuth2Details) // 移除存储的刷新令牌 RemoveRefreshToken(oauth2Token string) // 根据令牌值获取刷新令牌 ReadRefreshToken(tokenValue string) (*OAuth2Token, error) // 根据令牌值获取刷新令牌对应的客户端和用户信息 ReadOAuth2DetailsForRefreshToken(tokenValue string) (*OAuth2Details, error) }
func NewJwtTokenStore ¶
func NewJwtTokenStore(jwtTokenEnhancer *JwtTokenEnhancer) TokenStore
type UserDetailsService ¶
type UserDetailsService interface { // Get UserDetails By username GetUserDetailByUsername(ctx context.Context, username, password string) (*model.UserDetails, error) }
Service Define a service interface
type UsernamePasswordTokenGranter ¶
type UsernamePasswordTokenGranter struct {
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.