Documentation ¶
Index ¶
- Variables
- func AddContextTokenToRequest(ctx context.Context, r *http.Request) (*http.Request, bool)
- func AddToContext(ctx context.Context, s string) context.Context
- func FromCtx(ctx context.Context) string
- func NewPrivKeyAuthToken(pk crypto.PrivKey, profileID string, ttl time.Duration) (string, error)
- func OAuthTokenMiddleware(next http.Handler) http.Handler
- type Claims
- type CtxKey
- type RawToken
- type RawTokens
- type Source
- type Store
- type Token
Constants ¶
This section is empty.
Variables ¶
var ( // Timestamp is a replacable function for getting the current time, // can be overridden for tests Timestamp = func() time.Time { return time.Now() } // ErrTokenNotFound is returned by stores that cannot find an access token // for a given key ErrTokenNotFound = errors.New("access token not found") // ErrInvalidToken indicates an access token is invalid ErrInvalidToken = errors.New("invalid access token") // DefaultTokenTTL is the default DefaultTokenTTL = time.Hour * 24 * 14 )
Functions ¶
func AddContextTokenToRequest ¶
AddContextTokenToRequest checks the supplied context for an auth token and adds it to an http request, returns true if a token is added
func AddToContext ¶
AddToContext adds a token string to a context
func NewPrivKeyAuthToken ¶
NewPrivKeyAuthToken creates a JWT token string suitable for making requests authenticated as the given private key
Types ¶
type Claims ¶
type Claims struct { *jwt.StandardClaims ProfileID string `json:"profileID"` }
Claims is a JWT Claims object
type CtxKey ¶
type CtxKey string
CtxKey defines a distinct type for context keys used by the access package
type RawTokens ¶
type RawTokens []RawToken
RawTokens is a list of tokens that implements sorting by keys
type Source ¶
type Source interface { CreateToken(pro *profile.Profile, ttl time.Duration) (string, error) CreateTokenWithClaims(claims jwt.MapClaims, ttl time.Duration) (string, error) // VerifyKey returns the verification key for a given token VerificationKey(t *Token) (interface{}, error) }
Source creates tokens, and provides a verification key for all tokens it creates
implementations of Source must conform to the assertion test defined in the spec subpackage
type Store ¶
type Store interface { PutToken(ctx context.Context, key, rawToken string) error RawToken(ctx context.Context, key string) (rawToken string, err error) DeleteToken(ctx context.Context, key string) (err error) ListTokens(ctx context.Context, offset, limit int) (results []RawToken, err error) }
Store is a store intended for clients, who need to persist secret jwts given to them by other remotes for API access. It deals in raw, string-formatted json web tokens, which are more useful when working with APIs, but validates the tokens are well-formed when placed in the store
implementations of Store must conform to the assertion test defined in the spec subpackage