Documentation ¶
Index ¶
- Variables
- func ClientBasicFastHandler(ctx *fasthttp.RequestCtx) (clientID, clientSecret string, err error)
- func ClientBasicHandler(r *http.Request) (clientID, clientSecret string, err error)
- func ClientFormFastHandler(ctx *fasthttp.RequestCtx) (clientID, clientSecret string, err error)
- func ClientFormHandler(r *http.Request) (clientID, clientSecret string, err error)
- type AuthorizeRequest
- type ClientFastHandler
- type ClientHandler
- type Config
- type FastServer
- func (fs *FastServer) GetAuthorizeRequest(ctx *fasthttp.RequestCtx) (authReq *AuthorizeRequest, err error)
- func (fs *FastServer) HandleAuthorizeRequest(ctx *fasthttp.RequestCtx, authReq *AuthorizeRequest) (err error)
- func (fs *FastServer) HandleTokenRequest(ctx *fasthttp.RequestCtx) (err error)
- func (fs *FastServer) ResJSON(ctx *fasthttp.RequestCtx, ti oauth2.TokenInfo) (err error)
- func (fs *FastServer) SetClientHandler(handler ClientFastHandler)
- type ScopeHandler
- type Server
- func (s *Server) GetAuthorizeRequest(r *http.Request) (authReq *AuthorizeRequest, err error)
- func (s *Server) GetRedirectURI(authReq *AuthorizeRequest, ti oauth2.TokenInfo) (uri string, err error)
- func (s *Server) HandleAuthorizeRequest(w http.ResponseWriter, authReq *AuthorizeRequest) (err error)
- func (s *Server) HandleTokenRequest(w http.ResponseWriter, r *http.Request) (err error)
- func (s *Server) ResJSON(w http.ResponseWriter, ti oauth2.TokenInfo) (err error)
- func (s *Server) SetAllowedGrantType(allowedTypes ...oauth2.GrantType)
- func (s *Server) SetAllowedResponseType(allowedTypes ...oauth2.ResponseType)
- func (s *Server) SetClientHandler(handler ClientHandler)
- func (s *Server) SetScopeHandler(handler ScopeHandler)
- func (s *Server) SetTokenType(tokenType string)
- func (s *Server) SetUserHandler(handler UserHandler)
- type TokenRequestHandler
- type UserHandler
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRequestMethodInvalid Request method invalid ErrRequestMethodInvalid = errors.New("request method invalid") // ErrResponseTypeInvalid Response type invalid ErrResponseTypeInvalid = errors.New("response type invalid") // ErrGrantTypeInvalid Grant type invalid ErrGrantTypeInvalid = errors.New("grant type invalid") // ErrClientInvalid Client invalid ErrClientInvalid = errors.New("client invalid") // ErrUserInvalid User invalid ErrUserInvalid = errors.New("user invalid") // ErrAuthorizationFormInvalid Authorization form invalid ErrAuthorizationFormInvalid = errors.New("authorization form invalid") // ErrAuthorizationHeaderInvalid Authorization header invalid ErrAuthorizationHeaderInvalid = errors.New("authorization header invalid") // ErrRefreshInvalid Refresh token invalid ErrRefreshInvalid = errors.New("refresh token invalid") )
Functions ¶
func ClientBasicFastHandler ¶
func ClientBasicFastHandler(ctx *fasthttp.RequestCtx) (clientID, clientSecret string, err error)
ClientBasicFastHandler 客户端基础认证信息(基于fasthttp)
func ClientBasicHandler ¶
ClientBasicHandler 客户端基础认证信息
func ClientFormFastHandler ¶
func ClientFormFastHandler(ctx *fasthttp.RequestCtx) (clientID, clientSecret string, err error)
ClientFormFastHandler 客户端表单信息(基于fasthttp)
Types ¶
type AuthorizeRequest ¶
type AuthorizeRequest struct { Type oauth2.ResponseType // 授权类型 ClientID string // 客户端标识 Scope string // 授权范围 RedirectURI string // 重定向URI State string // 状态 UserID string // 用户标识 }
AuthorizeRequest 授权请求
type ClientFastHandler ¶
type ClientFastHandler func(ctx *fasthttp.RequestCtx) (clientID, clientSecret string, err error)
ClientFastHandler 基于fasthttp获取客户端认证信息
type ClientHandler ¶
ClientHandler 获取请求的客户端认证信息
type Config ¶
type Config struct { // TokenType 令牌类型(默认为Bearer) TokenType string // AllowedResponseType 允许的授权类型(默认code) AllowedResponseType []oauth2.ResponseType // AllowedGrantType 允许的授权模式(默认authorization_code) AllowedGrantType []oauth2.GrantType // Handler 令牌请求处理 Handler *TokenRequestHandler }
Config 配置参数
type FastServer ¶
type FastServer struct {
Server
}
FastServer 基于fasthttp(https://github.com/valyala/fasthttp)的OAuth2服务处理
func NewFastServer ¶
func NewFastServer(cfg *Config, manager oauth2.Manager) *FastServer
NewFastServer 创建基于fasthttp的OAuth2服务实例
func (*FastServer) GetAuthorizeRequest ¶
func (fs *FastServer) GetAuthorizeRequest(ctx *fasthttp.RequestCtx) (authReq *AuthorizeRequest, err error)
GetAuthorizeRequest 获取授权请求参数
func (*FastServer) HandleAuthorizeRequest ¶
func (fs *FastServer) HandleAuthorizeRequest(ctx *fasthttp.RequestCtx, authReq *AuthorizeRequest) (err error)
HandleAuthorizeRequest 处理授权请求
func (*FastServer) HandleTokenRequest ¶
func (fs *FastServer) HandleTokenRequest(ctx *fasthttp.RequestCtx) (err error)
HandleTokenRequest 处理令牌请求
func (*FastServer) ResJSON ¶
func (fs *FastServer) ResJSON(ctx *fasthttp.RequestCtx, ti oauth2.TokenInfo) (err error)
ResJSON 响应Json数据
func (*FastServer) SetClientHandler ¶
func (fs *FastServer) SetClientHandler(handler ClientFastHandler)
SetClientHandler 设置客户端处理
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server OAuth2服务处理
func (*Server) GetAuthorizeRequest ¶
func (s *Server) GetAuthorizeRequest(r *http.Request) (authReq *AuthorizeRequest, err error)
GetAuthorizeRequest 获取授权请求参数
func (*Server) GetRedirectURI ¶
func (s *Server) GetRedirectURI(authReq *AuthorizeRequest, ti oauth2.TokenInfo) (uri string, err error)
GetRedirectURI 获取重定向URI
func (*Server) HandleAuthorizeRequest ¶
func (s *Server) HandleAuthorizeRequest(w http.ResponseWriter, authReq *AuthorizeRequest) (err error)
HandleAuthorizeRequest 处理授权请求
func (*Server) HandleTokenRequest ¶
HandleTokenRequest 处理令牌请求
func (*Server) ResJSON ¶
func (s *Server) ResJSON(w http.ResponseWriter, ti oauth2.TokenInfo) (err error)
ResJSON 响应Json数据
func (*Server) SetAllowedGrantType ¶
func (s *Server) SetAllowedGrantType(allowedTypes ...oauth2.GrantType)
SetAllowedGrantType 允许的授权模式
func (*Server) SetAllowedResponseType ¶
func (s *Server) SetAllowedResponseType(allowedTypes ...oauth2.ResponseType)
SetAllowedResponseType 设置允许的授权类型
func (*Server) SetClientHandler ¶
func (s *Server) SetClientHandler(handler ClientHandler)
SetClientHandler 设置客户端处理
func (*Server) SetScopeHandler ¶
func (s *Server) SetScopeHandler(handler ScopeHandler)
SetScopeHandler 设置授权范围处理
func (*Server) SetUserHandler ¶
func (s *Server) SetUserHandler(handler UserHandler)
SetUserHandler 设置用户处理
type TokenRequestHandler ¶
type TokenRequestHandler struct { // 客户端信息处理 ClientHandler ClientHandler // 客户端信息处理(基于fasthttp) ClientFastHandler ClientFastHandler // 用户信息处理 UserHandler UserHandler // 授权范围处理 ScopeHandler ScopeHandler }
TokenRequestHandler 令牌请求处理
type UserHandler ¶
UserHandler 密码模式下,根据用户名、密码获取用户标识