jwt

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2017 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package jwt provides utility functions for validating JSON Web Tokens (JWT) as defined by Cloud Identity-Aware Proxy (Cloud IAP). This package follows the instructions specified at https://cloud.google.com/iap/docs/signed-headers-howtospecifications

Index

Constants

This section is empty.

Variables

View Source
var (
	// PublicKeysURL is the URL from which public keys will be fetched.
	PublicKeysURL = "https://www.gstatic.com/iap/verify/public_key"
	// HTTPClient is the default HTTP Client to use for fetching public keys.
	HTTPClient = &http.Client{Timeout: 10 * time.Second}
)

Functions

func DecodePublicKeys

func DecodePublicKeys(r io.Reader) (map[string]PublicKey, error)

DecodePublicKeys decodes all public keys from the given Reader.

func FetchPublicKeys

func FetchPublicKeys() (map[string]PublicKey, error)

FetchPublicKeys downloads and decodes all public keys from Google.

func ValidateRequestClaims

func ValidateRequestClaims(req *http.Request, cfg *Config) error

ValidateRequestClaims checks the validity of the claims in the request.

Types

type Audience

type Audience url.URL

Audience must be the base URL from the request including protocol, domain, and port if applicable for the domains you specify in your IAP proxy. For example, https://example.com or https://foo.example.com:port.

func NewAudience

func NewAudience(u *url.URL) *Audience

NewAudience returns an Audience from a URL.

func ParseAudience

func ParseAudience(rawURL string) (*Audience, error)

ParseAudience parses an Audience from a URL string.

func (*Audience) Sanitize

func (aud *Audience) Sanitize() error

Sanitize normalizes the structure of the Audience's URL and validates it.

func (*Audience) Validate

func (aud *Audience) Validate() error

Validate performs error checking on the Audience's URL.

type Claims

type Claims struct {
	jwt.StandardClaims
	Email string `json:"email,omitempty"`
	// contains filtered or unexported fields
}

Claims represents parsed JWT Token Claims.

func RequestClaims

func RequestClaims(req *http.Request, cfg *Config) (*Claims, error)

RequestClaims checks the validity and returns the claims in the request. Claims may be returned even if an error occurs.

func (Claims) Valid

func (c Claims) Valid() error

Valid validates the Claims.

type Config

type Config struct {
	PublicKeys     map[string]PublicKey
	MatchAudiences *regexp.Regexp
}

Config specifies the parameters for which to perform validation of JWT tokens in requests against.

func (*Config) Validate

func (cfg *Config) Validate() error

Validate validates the Configuration.

type PublicKey

type PublicKey []byte

PublicKey are Google's public keys to use for JWT token validation.

func CreatePublicKey

func CreatePublicKey(b []byte) PublicKey

CreatePublicKey creates a PublicKey from a byte slice.

Jump to

Keyboard shortcuts

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