Documentation ¶
Index ¶
- type AuthorizeRequest
- type AuthorizeResponse
- type AuthorizeType
- type Client
- type Generator
- type GrantInfo
- type GrantRequest
- type GrantResponse
- type KVStorage
- type Options
- type RefreshRequest
- type Request
- type Server
- func (s *Server) Authorize(request *AuthorizeRequest, sessionId string) (*AuthorizeResponse, error)
- func (s *Server) AuthorizeFromRequest(r *http.Request, sessionId string) (*AuthorizeResponse, error)
- func (s *Server) GetClient(clientID string) (Client, error)
- func (s *Server) Grant(request *GrantRequest) (*GrantResponse, error)
- func (s *Server) GrantFromRequest(r *http.Request) (*GrantResponse, error)
- func (s *Server) Refresh(refreshToken string) (*GrantResponse, error)
- func (s *Server) SetStorage(storage Storage)
- func (s *Server) Storage() Storage
- func (s *Server) VerifyAccessToken(accessToken string) (*GrantResponse, error)
- type SimpleClient
- type SimpleGenerator
- type SimpleStorage
- func (s *SimpleStorage) GetClient(id string) (Client, error)
- func (s *SimpleStorage) GetGrantCode(code string) (string, error)
- func (s *SimpleStorage) GetGrantInfoByAccessToken(accessToken string) (GrantInfo, error)
- func (s *SimpleStorage) GetGrantInfoByRefreshToken(refreshToken string) (GrantInfo, error)
- func (s *SimpleStorage) PutClient(c *SimpleClient)
- func (s *SimpleStorage) RemoveAccessToken(accessToken string) error
- func (s *SimpleStorage) RemoveClient(id string)
- func (s *SimpleStorage) RemoveGrantCode(code string) error
- func (s *SimpleStorage) RemoveRefreshToken(refreshToken string) error
- func (s *SimpleStorage) SaveGrantCode(code string, sessionId string) error
- func (s *SimpleStorage) SaveGrantInfo(info GrantInfo) error
- type Storage
- type SyncMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthorizeRequest ¶
type AuthorizeRequest struct { Request //其他公共参数,暂未使用 RequestType AuthorizeType //授权类型 ClientId string //客户端id Redirect string //授权回调地址 State string //额外参数 }
func NewAuthorizeRequest ¶
func NewAuthorizeRequest(r *http.Request) (*AuthorizeRequest, error)
type AuthorizeResponse ¶
type AuthorizeResponse struct { ClientId string // GrantCode string // 授权码 State string // 额外参数 // contains filtered or unexported fields }
func (*AuthorizeResponse) Redirect ¶
func (r *AuthorizeResponse) Redirect() string
type AuthorizeType ¶
type AuthorizeType string
const ( AuthorizationCode AuthorizeType = "code" Implicit AuthorizeType = "implicit" PasswordCredentials AuthorizeType = "password" ClientCredentials AuthorizeType = "client" )
type GrantInfo ¶
type GrantInfo struct { ClientId string `json:"client_id"` SessionId string `json:"session_id"` AccessToken string `json:"access_token"` AccessTokenExpire int64 `json:"access_token_expire"` RefreshToken string `json:"refresh_token"` RefreshTokenExpire int64 `json:"refresh_token_expire"` Data interface{} `json:"data,omitempty"` }
type GrantRequest ¶
func NewGrantRequest ¶
func NewGrantRequest(r *http.Request) (*GrantRequest, error)
type GrantResponse ¶
type GrantResponse struct {
Info GrantInfo `json:"info"`
}
type KVStorage ¶
type KVStorage interface { Get(k string) (interface{}, error) Put(k string, v interface{}) error Del(k string) error }
func NewLRUStorage ¶ added in v0.0.3
type Options ¶
type Options struct { CheckRedirect bool AccessTokenExpire int64 //second RefreshTokenExpire int64 //second Generator Generator Verify func(c Client, header http.Header, val url.Values) error }
func DefaultOptions ¶
func DefaultOptions() *Options
type RefreshRequest ¶
type RefreshRequest struct {
RefreshToken string
}
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) Authorize ¶
func (s *Server) Authorize(request *AuthorizeRequest, sessionId string) (*AuthorizeResponse, error)
Authorize request 授权请求参数 sessionId 当前用户识别标识,可以是用户id也可以是其他 每次生成授权码(grant_code)时,会将 grant_code 与 sessionId 关联保存,确认授权时,会读取出 sessionId 返回给业务端, 业务端自行决定 sessionId 用途(一般用作用户标识)
func (*Server) AuthorizeFromRequest ¶
func (*Server) Grant ¶
func (s *Server) Grant(request *GrantRequest) (*GrantResponse, error)
func (*Server) GrantFromRequest ¶
func (s *Server) GrantFromRequest(r *http.Request) (*GrantResponse, error)
func (*Server) SetStorage ¶
func (*Server) VerifyAccessToken ¶
func (s *Server) VerifyAccessToken(accessToken string) (*GrantResponse, error)
type SimpleClient ¶
func (*SimpleClient) Callback ¶
func (s *SimpleClient) Callback() []string
func (*SimpleClient) GetClientId ¶
func (s *SimpleClient) GetClientId() string
func (*SimpleClient) GetSecret ¶
func (s *SimpleClient) GetSecret() string
type SimpleGenerator ¶
type SimpleGenerator struct{}
func NewSimpleGenerator ¶
func NewSimpleGenerator() *SimpleGenerator
func (*SimpleGenerator) GenAccessToken ¶
func (g *SimpleGenerator) GenAccessToken(c Client, sessionId string) (string, error)
func (*SimpleGenerator) GenGrantCode ¶
func (g *SimpleGenerator) GenGrantCode(c Client, sessionId string) (string, error)
func (*SimpleGenerator) GenRefreshToken ¶
func (g *SimpleGenerator) GenRefreshToken(c Client, sessionId string) (string, error)
type SimpleStorage ¶
type SimpleStorage struct {
// contains filtered or unexported fields
}
func NewSimpleKVStorage ¶
func NewSimpleKVStorage(getClient func(id string) (Client, error), newKVStorage func() KVStorage) *SimpleStorage
func NewSimpleStorage ¶
func NewSimpleStorage(getClient func(id string) (Client, error)) *SimpleStorage
func (*SimpleStorage) GetGrantCode ¶
func (s *SimpleStorage) GetGrantCode(code string) (string, error)
func (*SimpleStorage) GetGrantInfoByAccessToken ¶
func (s *SimpleStorage) GetGrantInfoByAccessToken(accessToken string) (GrantInfo, error)
func (*SimpleStorage) GetGrantInfoByRefreshToken ¶
func (s *SimpleStorage) GetGrantInfoByRefreshToken(refreshToken string) (GrantInfo, error)
func (*SimpleStorage) PutClient ¶
func (s *SimpleStorage) PutClient(c *SimpleClient)
func (*SimpleStorage) RemoveAccessToken ¶
func (s *SimpleStorage) RemoveAccessToken(accessToken string) error
func (*SimpleStorage) RemoveClient ¶
func (s *SimpleStorage) RemoveClient(id string)
func (*SimpleStorage) RemoveGrantCode ¶
func (s *SimpleStorage) RemoveGrantCode(code string) error
func (*SimpleStorage) RemoveRefreshToken ¶
func (s *SimpleStorage) RemoveRefreshToken(refreshToken string) error
func (*SimpleStorage) SaveGrantCode ¶
func (s *SimpleStorage) SaveGrantCode(code string, sessionId string) error
func (*SimpleStorage) SaveGrantInfo ¶
func (s *SimpleStorage) SaveGrantInfo(info GrantInfo) error
type Storage ¶
type Storage interface { GetClient(id string) (Client, error) SaveGrantCode(code string, sessionId string) error GetGrantCode(code string) (string, error) RemoveGrantCode(code string) error SaveGrantInfo(info GrantInfo) error GetGrantInfoByAccessToken(accessToken string) (GrantInfo, error) GetGrantInfoByRefreshToken(refreshToken string) (GrantInfo, error) RemoveAccessToken(accessToken string) error RemoveRefreshToken(refreshToken string) error }
type SyncMap ¶
type SyncMap struct {
// contains filtered or unexported fields
}
func NewSyncMap ¶
func NewSyncMap() *SyncMap
Source Files ¶
Click to show internal directories.
Click to hide internal directories.