Documentation
¶
Index ¶
- func HashID(h hash.Hash, val string) string
- func SetUserInfo(r *http.Request, user User) *http.Request
- type Audience
- type AudienceFunc
- type Claims
- type ClaimsUpdFunc
- type ClaimsUpdater
- type Handshake
- type Opts
- type Secret
- type SecretFunc
- type Service
- func (j *Service) Get(r *http.Request) (Claims, string, error)
- func (j *Service) IsExpired(claims Claims) bool
- func (j *Service) Parse(tokenString string) (Claims, error)
- func (j *Service) Reset(w http.ResponseWriter)
- func (j *Service) Set(w http.ResponseWriter, claims Claims) (Claims, error)
- func (j *Service) Token(claims Claims) (string, error)
- type User
- type Validator
- type ValidatorFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AudienceFunc ¶ added in v0.3.0
AudienceFunc type is an adapter to allow the use of ordinary functions as Audience.
func (AudienceFunc) Get ¶ added in v0.3.0
func (f AudienceFunc) Get() ([]string, error)
Get calls f()
type Claims ¶
type Claims struct {
jwt.StandardClaims
User *User `json:"user,omitempty"` // user info
SessionOnly bool `json:"sess_only,omitempty"`
Handshake *Handshake `json:"handshake,omitempty"` // used for oauth handshake
}
Claims stores user info for token and state & from from login
type ClaimsUpdFunc ¶
ClaimsUpdFunc type is an adapter to allow the use of ordinary functions as ClaimsUpdater. If f is a function with the appropriate signature, ClaimsUpdFunc(f) is a Handler that calls f.
func (ClaimsUpdFunc) Update ¶
func (f ClaimsUpdFunc) Update(claims Claims) Claims
Update calls f(id)
type ClaimsUpdater ¶
ClaimsUpdater defines interface adding extras to claims
type Handshake ¶
type Handshake struct {
State string `json:"state,omitempty"`
From string `json:"from,omitempty"`
ID string `json:"id,omitempty"`
}
Handshake used for oauth handshake
type Opts ¶
type Opts struct {
SecretReader Secret
ClaimsUpd ClaimsUpdater
SecureCookies bool
TokenDuration time.Duration
CookieDuration time.Duration
DisableXSRF bool
DisableIAT bool // disable IssuedAt claim
// optional (custom) names for cookies and headers
JWTCookieName string
JWTHeaderKey string
XSRFCookieName string
XSRFHeaderKey string
AudienceReader Audience // allowed aud values
Issuer string // optional value for iss claim, usually application name
}
Opts holds constructor params
type SecretFunc ¶
SecretFunc type is an adapter to allow the use of ordinary functions as Secret. If f is a function with the appropriate signature, SecretFunc(f) is a Handler that calls f.
type Service ¶
type Service struct {
Opts
}
Service wraps jwt operations supports both header and cookie tokens
func (*Service) Get ¶
Get token from url, header or cookie if cookie used, verify xsrf token to match
type User ¶
type User struct {
Name string `json:"name"`
ID string `json:"id"`
Picture string `json:"picture"`
IP string `json:"ip,omitempty"`
Email string `json:"email,omitempty"`
Attributes map[string]interface{} `json:"attrs,omitempty"`
}
User is the basic part of oauth data provided by service
func GetUserInfo ¶
GetUserInfo returns user from request context
func MustGetUserInfo ¶
MustGetUserInfo fails if can't extract user data from the request. should be called from authenticated controllers only
func (*User) SetBoolAttr ¶
SetBoolAttr sets boolean attribute
func (*User) SetStrAttr ¶
SetStrAttr sets string attribute
type Validator ¶
Validator defines interface to accept o reject claims with consumer defined logic It works with valid token and allows to reject some, based on token match or user's fields
type ValidatorFunc ¶
ValidatorFunc type is an adapter to allow the use of ordinary functions as Validator. If f is a function with the appropriate signature, ValidatorFunc(f) is a Validator that calls f.