jwt

package
v0.0.0-...-b0bbb88 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2019 License: MIT Imports: 10 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

View Source
const DefaultPublicKeysURL = "https://www.gstatic.com/iap/verify/public_key"

DefaultPublicKeysURL is the URL from which public keys will be fetched.

Variables

View Source
var (
	ErrAudienceInsufficientParts                   = errors.New("Audience must have 4 or 5 parts")
	ErrAudienceMustStartWithProjects               = errors.New("Audience must start with /projects")
	ErrAudienceEmptyProject                        = errors.New("Audience must have a non-empty project number")
	ErrAudienceInvalidAppEngineFormat              = errors.New("Audience for AppEngine must match /projects/PROJECT_NUMBER/apps/PROJECT_ID")
	ErrAudienceMissingProjectID                    = errors.New("Audience for AppEngine must have a project ID")
	ErrAudienceInvalidComputeContainerEngineFormat = errors.New("Audience for Compute or Container Engine must match /projects/PROJECT_NUMBER/global/backendServices/PROJECT_ID")
	ErrAudienceMissingServiceID                    = errors.New("Audience for Compute or Container Engine must have a service ID")
)
View Source
var (
	ErrConfigUndefinedMatchAudiences = errors.New("No audiences to match defined")
	ErrConfigNoPublicKeys            = errors.New("No public keys defined")
)
View Source
var (
	ErrMissingRequestToken = errors.New("Token was not found in the request headers")
)
View Source
var (
	ErrPublicKeyNoFilesFound = errors.New("Could not find any readable public keys matching *.pub")
)

Functions

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 string

Audience is a string wrapper to provide validation logic for GCP IAP audience URLs. From the IAP docs at https://cloud.google.com/iap/docs/signed-headers-howto: Audience must be a string with the following values: * App Engine: /projects/PROJECT_NUMBER/apps/PROJECT_ID * Compute Engine and Container Engine: /projects/PROJECT_NUMBER/global/backendServices/SERVICE_ID

func NewAudience

func NewAudience(u string) *Audience

NewAudience returns an Audience from a string.

func ParseAudience

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

ParseAudience parses an Audience from a string.

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 {
	// contains filtered or unexported fields
}

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

func NewConfig

func NewConfig(audiences string, publicKeys PublicKeys) (*Config, error)

type KeyID

type KeyID string

KeyID is the ID for a public key

type PublicKey

type PublicKey []byte

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

type PublicKeys

type PublicKeys map[KeyID]PublicKey

PublicKeys is a map of key id and pem encoded EC256 keys

func DecodePublicKeys

func DecodePublicKeys(r io.Reader) (PublicKeys, error)

DecodePublicKeys decodes all public keys from the given Reader.

func FetchPublicKeys

func FetchPublicKeys(httpClient *http.Client, url string) (PublicKeys, error)

FetchPublicKeys downloads and decodes all public keys from Google.

func ReadAllPublickeys

func ReadAllPublickeys(directory string) (PublicKeys, error)

ReadAllPublickeys reads all .pub files in the given directory using the file name without the file extionsion as the key ID.

Jump to

Keyboard shortcuts

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