jwt

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2015 License: BSD-3-Clause Imports: 10 Imported by: 0

README

jwt.go

Build Status BSD License

🚧 UNDER DEVELOPMENT 🚧

Primary Goal

  • Stop implementing crypto things by myself.
  • Provide building blocks around JWT, JWK and JWS not whole implementation.
    • Work well for both using JWT and providing JWT-based service.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeJWKSet

func DecodeJWKSet(r io.Reader) ([]*jose.JsonWebKey, error)

DecodeJWKSet decodes the data with reading from r into JWKs.

func VerifyExp

func VerifyExp(skew time.Duration, exp int64) bool

VerifyExp verifies exp (expiration time). It will return true if the current time is before exp. Otherwise, it will return false. See http://openid.net/specs/openid-connect-core-1_0.html#IDToken

func VerifyJWS

func VerifyJWS(jws *jose.JsonWebSignature, jwks []*jose.JsonWebKey) ([]byte, *jose.JsonWebKey, error)

VerifyJWS validates jws by jwks and return the jwk and payload. If VerifyJWS fails to validate by all jwks, it will return the last verification error.

Types

type JWKSet

type JWKSet struct {
	Keys []*jose.JsonWebKey `json:"keys"`
}

JWKSet represents JWK Set. See https://tools.ietf.org/html/rfc7517#section-5

type JWKSetResponse

type JWKSetResponse struct {
	Keys []*jose.JsonWebKey

	TTL time.Duration // This would be used as TTL for caching.
}

JWKSetResponse represents a response of JWK Set. This contains a TTL (Time to Live) for caching purpose.

type JWKsCacher

type JWKsCacher struct {
	// contains filtered or unexported fields
}

JWKsCacher fetches JWKs via Cache if available.

func NewCacher

func NewCacher(defaultExpiration, cleanupInterval time.Duration, f JWKsFetcher) *JWKsCacher

NewCacher returns JWKsCacher with initializing cache store.

func (*JWKsCacher) FetchJWKs

func (c *JWKsCacher) FetchJWKs(cacheKey string) (*JWKSetResponse, error)

FetchJWKs tries to retrieve JWKs from Cache. If the cache is not available, it will call Fetcher.FetchJWKs and cache the result for future request.

type JWKsFetcher

type JWKsFetcher interface {
	// FetchJWKs retrieves JWKSet from path.
	FetchJWKs(path string) (*JWKSetResponse, error)
}

JWKsFetcher is an interface that represents JWKs fetcher.

type JWKsHTTPFetcher

type JWKsHTTPFetcher struct {
	Client *http.Client
}

JWKsHTTPFetcher fetches JWKs via HTTP.

func (*JWKsHTTPFetcher) FetchJWKs

func (f *JWKsHTTPFetcher) FetchJWKs(uri string) (*JWKSetResponse, error)

FetchJWKs implements JWKsFetcher interface by using http.Client. FetchJWKs tries to retrieve JWKSet from uri.

type JWKsS3Fetcher

type JWKsS3Fetcher struct {
	S3Svc s3iface.S3API
}

JWKsS3Fetcher fetches JWKs via S3.

func (*JWKsS3Fetcher) FetchJWKs

func (f *JWKsS3Fetcher) FetchJWKs(path string) (*JWKSetResponse, error)

FetchJWKs implements JWKsS3Fetcher by using S3. It tries to retrieve an S3 object from path. path must be in s3://<bucket>/<key>.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL