server

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2016 License: Apache-2.0 Imports: 7 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 ClientBasicHandler

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

ClientBasicHandler 客户端基础认证信息

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
	State       string
	UserID      string
}

AuthorizeRequest 授权请求

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 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) 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 处理令牌请求 cli 获取客户端信息 user 获取用户信息

func (*Server) ResJSON

func (s *Server) ResJSON(w http.ResponseWriter, ti oauth2.TokenInfo) (err error)

ResJSON 响应Json数据

func (*Server) ResRedirectURI

func (s *Server) ResRedirectURI(w http.ResponseWriter, authReq *AuthorizeRequest, ti oauth2.TokenInfo) (err error)

ResRedirectURI 响应数据到重定向URI

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