server

package
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

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

ClientBasicHandler 客户端基础认证信息

func ClientFormFastHandler

func ClientFormFastHandler(ctx *fasthttp.RequestCtx) (clientID, clientSecret string, err error)

ClientFormFastHandler 客户端表单信息(基于fasthttp)

func ClientFormHandler

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

ClientFormHandler 客户端表单信息

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

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

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 配置参数

func NewConfig

func NewConfig() *Config

NewConfig 创建默认的配置参数

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 ScopeHandler

type ScopeHandler func(new, old string) (err error)

ScopeHandler 更新令牌时的授权范围检查

type Server

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

Server OAuth2服务处理

func NewServer

func NewServer(cfg *Config, manager oauth2.Manager) *Server

NewServer 创建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

func (s *Server) HandleTokenRequest(w http.ResponseWriter, r *http.Request) (err error)

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) SetTokenType

func (s *Server) SetTokenType(tokenType string)

SetTokenType 设置令牌类型

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

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

UserHandler 密码模式下,根据用户名、密码获取用户标识

Jump to

Keyboard shortcuts

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