Documentation ¶
Index ¶
- Constants
- Variables
- type Claims
- type Profile
- type StandardClaims
- func (c StandardClaims) Valid() error
- func (c *StandardClaims) VerifyAudience(cmp string, req bool) bool
- func (c *StandardClaims) VerifyExpiresAt(cmp int64, req bool) bool
- func (c *StandardClaims) VerifyIssuedAt(cmp int64, req bool) bool
- func (c *StandardClaims) VerifyIssuer(cmp string, req bool) bool
- func (c *StandardClaims) VerifyNotBefore(cmp int64, req bool) bool
- type Stock
- type User
- type UsersService
- type ValidationError
Constants ¶
const ( ValidationErrorMalformed uint32 = 1 << iota // Token is malformed ValidationErrorUnverifiable // Token could not be verified because of signing problems ValidationErrorSignatureInvalid // Signature validation failed // Standard Claim validation errors ValidationErrorAudience // AUD validation failed ValidationErrorExpired // EXP validation failed ValidationErrorIssuedAt // IAT validation failed ValidationErrorIssuer // ISS validation failed ValidationErrorNotValidYet // NBF validation failed ValidationErrorId // JTI validation failed ValidationErrorClaimsInvalid // Generic claims validation error )
The errors that might occur when parsing and validating a token
Variables ¶
var ( ErrInvalidKey = errors.New("key is invalid") ErrInvalidKeyType = errors.New("key is of invalid type") )
Error constants
Functions ¶
This section is empty.
Types ¶
type Claims ¶
type Claims interface {
Valid() error
}
Claims objects must justhave a Valid method that determines if the token is invalid for any supported reason
type Profile ¶
type Profile interface { // GetName returns the profile's name GetName() string // GetRiches returns the profile's riches, counted in 1/1000th of a dollars // i.e, a value of 1000 would be $1 GetRiches() int // GetStocks returns the profile's stocks GetStocks() []Stock // GetUserID returns the profile's ID in the system GetUserID() string }
Profile represents the information about a user that the application stores.
type StandardClaims ¶
type StandardClaims struct { Audience []string `json:"aud,omitempty"` ExpiresAt int64 `json:"exp,omitempty"` ID string `json:"jti,omitempty"` IssuedAt int64 `json:"iat,omitempty"` Issuer string `json:"iss,omitempty"` NotBefore int64 `json:"nbf,omitempty"` Subject string `json:"sub,omitempty"` }
StandardClaims is the structured version of Claims Section, as referenced at https://tools.ietf.org/html/rfc7519#section-4.1 See examples for how to use this with your own claim types
func (StandardClaims) Valid ¶
func (c StandardClaims) Valid() error
Valid validates time based claims "exp, iat, nbf". There is no accounting for clock skew. As well, if any of the above claims are not in the token, it will still be considered a valid claim.
func (*StandardClaims) VerifyAudience ¶
func (c *StandardClaims) VerifyAudience(cmp string, req bool) bool
VerifyAudience compares the aud claim against cmp. If required is false, this method will return true if the value matches or is unset
func (*StandardClaims) VerifyExpiresAt ¶
func (c *StandardClaims) VerifyExpiresAt(cmp int64, req bool) bool
VerifyExpiresAt compares the exp claim against cmp. If required is false, this method will return true if the value matches or is unset
func (*StandardClaims) VerifyIssuedAt ¶
func (c *StandardClaims) VerifyIssuedAt(cmp int64, req bool) bool
VerifyIssuedAt compares the iat claim against cmp. If required is false, this method will return true if the value matches or is unset
func (*StandardClaims) VerifyIssuer ¶
func (c *StandardClaims) VerifyIssuer(cmp string, req bool) bool
VerifyIssuer compares the iss claim against cmp. If required is false, this method will return true if the value matches or is unset
func (*StandardClaims) VerifyNotBefore ¶
func (c *StandardClaims) VerifyNotBefore(cmp int64, req bool) bool
VerifyNotBefore compares the nbf claim against cmp. If required is false, this method will return true if the value matches or is unset
type Stock ¶
type Stock interface { // GetQuantity returns the quantity of the stock GetQuantity() int // GetTicker returns the ticker of the stock GetTicker() string }
Stock represents the quantity of stock owned by ticker
type User ¶
type User interface { // GetAccessToken returns the user's access token GetAccessToken() string // GetIDToken returns the user's ID token GetIDToken() string // GetProfile returns the user profile GetProfile() Profile // GetRefreshToken returns the user's refresh token GetRefreshToken() string // JSON serializes the user record JSON() ([]byte, error) }
User represents a user of the system. Owner of purchase orders and sell orders. Only the profile portion of a user is ever stored server side
type UsersService ¶
type UsersService interface { // GetProfile retrieves a profile for a userID GetProfile(userID string) (Profile, error) // ListTopProfiles returns the top 10 profiles based // on current riches ListTopProfiles() ([]Profile, error) // Login exchanges the code for a user profile // and then upserts the user profile into persistent // storage Login(code string) (User, int, error) // RefreshToken exchanges the refresh token for a user profile // and then upserts the user profile into persistent // storage RefreshToken(refreshToken string) (User, error) // UpdateForBuyOrderByUserID removes riches from the user and adds // to the stock quantity for the given ticker. Will // return an error if the user cannot be found UpdateForBuyOrderByUserID(userID, ticker string, quantity int, price int) error // UpdateForSellOrderByUserID adds to the user's riches. Will // return an error if the user cannot be found UpdateForSellOrderByUserID(userID, ticker string, quantity int, amount int) error // UserIDForAccessToken verifies the RS256 signature // of a JWT access token UserIDForAccessToken(accessToken string) (string, error) }
UsersService manages CRUD for buy & sell users
func New ¶
func New(auth0Creds auth0creds.Auth0Creds, mongoDB *mgo.Session) UsersService
New constructs a new UsersService that will persist data using the provided mongo session
type ValidationError ¶
type ValidationError struct { Inner error // stores the error returned by external dependencies, i.e.: KeyFunc Errors uint32 // bitfield. see ValidationError... constants // contains filtered or unexported fields }
The error from Parse if token is not valid
func NewValidationError ¶
func NewValidationError(errorText string, errorFlags uint32) *ValidationError
Helper for constructing a ValidationError with a string error message
func (ValidationError) Error ¶
func (e ValidationError) Error() string
Validation error is an error type