Documentation ¶
Index ¶
- Variables
- func GetCredentialsFromHttp(headerAuth string) (string, string, error)
- func HierarchicScope(requestScope string, clientScopes []string) bool
- func IsNotFound(err error) bool
- func RandomBytes(n int) ([]byte, error)
- func WriteJson(w http.ResponseWriter, status int, v interface{})
- func WriteJsonError(w http.ResponseWriter, err error) error
- type AccessToken
- type AppErr
- type AuthorizeCode
- type Client
- type CreateAccessTokenRequest
- type HMACTokenGenerator
- func (c *HMACTokenGenerator) CreateAccessToken(req *CreateAccessTokenRequest) (string, error)
- func (c *HMACTokenGenerator) CreateCode() string
- func (c *HMACTokenGenerator) CreateRefreshToken() string
- func (c *HMACTokenGenerator) Signature(token string) string
- func (c *HMACTokenGenerator) Validate(token string) error
- type JWTAccessToken
- type JWTTokenGenerator
- type RefreshToken
- type Storage
- type TokenGenerator
- type User
- type UserService
Constants ¶
This section is empty.
Variables ¶
View Source
var ( TokenEntropy = 32 SecretLength = 32 )
View Source
var Logger = zap.NewNop()
Functions ¶
func GetCredentialsFromHttp ¶
func HierarchicScope ¶
func IsNotFound ¶
func RandomBytes ¶
RandomBytes returns n random bytes by reading from crypto/rand.Reader
func WriteJson ¶
func WriteJson(w http.ResponseWriter, status int, v interface{})
func WriteJsonError ¶
func WriteJsonError(w http.ResponseWriter, err error) error
Types ¶
type AccessToken ¶
type AccessToken struct { AccessToken string `json:"at"` ClientID string `json:"cid,omitempty"` UserID string `json:"uid,omitempty"` Expired int64 `json:"exp"` ExpiresIn int `json:"ein"` Scopes []string `json:"scp"` Extras map[string]interface{} `json:"ext"` }
func (*AccessToken) HasScope ¶
func (a *AccessToken) HasScope(scopes ...string) bool
func (*AccessToken) Valid ¶
func (a *AccessToken) Valid() bool
type AppErr ¶
type AppErr struct { Message string `json:"error_description"` Code string `json:"error"` // contains filtered or unexported fields }
func InvalidClient ¶
func ServerError ¶
func UnknownError ¶
func (*AppErr) MarshalLogObject ¶
func (e *AppErr) MarshalLogObject(enc zapcore.ObjectEncoder) error
type AuthorizeCode ¶
type AuthorizeCode struct { Code string `json:"c"` ClientID string `json:"cid"` UserID string `json:"uid"` Expired int64 `json:"exp"` Scopes []string `json:"scp"` RedirectURI string `json:"rdr"` ResponseType string `json:"rpt"` Extras map[string]interface{} `json:"ext"` }
func (*AuthorizeCode) Valid ¶
func (a *AuthorizeCode) Valid() bool
type Client ¶
type Client struct { ID string `json:"id"` Name string `json:"n"` Secret string `json:"s"` RedirectURIs []string `json:"rdr"` GrantTypes []string `json:"gt"` Scopes []string `json:"scp"` Public bool `json:"pub"` CreatedAt string `json:"cat"` }
func (*Client) HasGrantType ¶
type HMACTokenGenerator ¶
type HMACTokenGenerator struct {
// contains filtered or unexported fields
}
HMACTokenGenerator is responsible for generating and validating challenges.
func NewHMACTokenGenerator ¶
func NewHMACTokenGenerator(secret []byte) *HMACTokenGenerator
func (*HMACTokenGenerator) CreateAccessToken ¶
func (c *HMACTokenGenerator) CreateAccessToken(req *CreateAccessTokenRequest) (string, error)
Generate generates a token and a matching signature or returns an error. This method implements rfc6819 Section 5.1.4.2.2: Use High Entropy for Secrets.
func (*HMACTokenGenerator) CreateCode ¶
func (c *HMACTokenGenerator) CreateCode() string
func (*HMACTokenGenerator) CreateRefreshToken ¶
func (c *HMACTokenGenerator) CreateRefreshToken() string
func (*HMACTokenGenerator) Signature ¶
func (c *HMACTokenGenerator) Signature(token string) string
func (*HMACTokenGenerator) Validate ¶
func (c *HMACTokenGenerator) Validate(token string) error
Validate validates a token and returns its signature or an error if the token is not valid.
type JWTAccessToken ¶
type JWTAccessToken struct { Audience string ExpiresAt int64 ID string IssuedAt int64 Issuer string Subject string Extras map[string]interface{} Scopes []string }
func ClaimJWTAccessToken ¶
func ClaimJWTAccessToken(publicKey *rsa.PublicKey, accesstoken string) (*JWTAccessToken, error)
func (*JWTAccessToken) HasScope ¶
func (a *JWTAccessToken) HasScope(scopes ...string) bool
func (*JWTAccessToken) Valid ¶
func (a *JWTAccessToken) Valid() bool
type JWTTokenGenerator ¶
type JWTTokenGenerator struct {
// contains filtered or unexported fields
}
func NewJWTTokenGenerator ¶
func NewJWTTokenGenerator(privateKey *rsa.PrivateKey) *JWTTokenGenerator
func (*JWTTokenGenerator) CreateAccessToken ¶
func (c *JWTTokenGenerator) CreateAccessToken(req *CreateAccessTokenRequest) (string, error)
func (*JWTTokenGenerator) CreateCode ¶
func (c *JWTTokenGenerator) CreateCode() string
func (*JWTTokenGenerator) CreateRefreshToken ¶
func (c *JWTTokenGenerator) CreateRefreshToken() string
type RefreshToken ¶
type RefreshToken struct { RefreshToken string `json:"rt"` ClientID string `json:"cid"` UserID string `json:"uid"` Expired int64 `json:"exp"` Scopes []string `json:"scp"` AccessTokenLifespan int `json:"atl"` RefreshTokenLifespan int `json:"rtl"` Extras map[string]interface{} `json:"ext"` }
func (*RefreshToken) Valid ¶
func (r *RefreshToken) Valid() bool
type Storage ¶
type Storage interface { GetClient(id string) (*Client, error) GetClientWithSecret(id, secret string) (*Client, error) GetRefreshToken(refreshToken string) (*RefreshToken, error) GetAuthorizeCode(code string) (*AuthorizeCode, error) GetAccessToken(accessToken string) (*AccessToken, error) SaveAccessToken(accessToken *AccessToken) error SaveRefreshToken(refreshToken *RefreshToken) error SaveAuthorizeCode(authCode *AuthorizeCode) error IsAvailableScope(scopes []string) (bool, error) RevokeRefreshToken(refreshToken string) error RevokeAccessToken(accessToken string) error }
type TokenGenerator ¶
type TokenGenerator interface { CreateAccessToken(req *CreateAccessTokenRequest) (string, error) CreateRefreshToken() string CreateCode() string }
type UserService ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.