GoogleIdTokenVerifier

package module
v0.0.0-...-47e8a50 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2019 License: MIT Imports: 15 Imported by: 0

README

GoogleIdTokenVerifier

To validate an Google ID Token in Golang

Usage:

	authToken := "XXXXXXXXXXX.XXXXXXXXXXXX.XXXXXXXXXX"
	email := "xxxx@xxxxx.iam.gserviceaccount.com"
	aud := "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com"
	tokeninfo, err := Verify(authToken, IssuerValidator(), ExpireValidator(), AudienceValidator(aud), EmailValidator(email))

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidIssuer   = errors.New("Token is not valid, ISS from token and certificate don't match")
	ErrInvalidAudience = errors.New("Token is not valid, Audience from token and certificate don't match")
	ErrInvalidEmail    = errors.New("Token is not valid, Email from token and certificate don't match")
	ErrTokenExpired    = errors.New("Token is not valid, Token is expired.")
	ErrInvalidKid      = errors.New("Token is not valid, kid from token and certificate don't match")
)

Functions

func Close

func Close()

func GetCertsFromURL

func GetCertsFromURL() ([]byte, error)

GetCertsFromURL is

func SetHttpClient

func SetHttpClient(hc *http.Client)

Types

type Certs

type Certs struct {
	Keys []*keys `json:"keys"`
}

Certs is

func GetCerts

func GetCerts(bt []byte) (*Certs, error)

GetCerts is

type TokenInfo

type TokenInfo struct {
	Sub           string `json:"sub"`
	Email         string `json:"email"`
	AtHash        string `json:"at_hash"`
	Aud           string `json:"aud"`
	EmailVerified bool   `json:"email_verified"`
	Name          string `json:"name"`
	GivenName     string `json:"given_name"`
	FamilyName    string `json:"family_name"`
	Picture       string `json:"picture"`
	Local         string `json:"locale"`
	Iss           string `json:"iss"`
	Azp           string `json:"azp"`
	Iat           int64  `json:"iat"`
	Exp           int64  `json:"exp"`
}

TokenInfo is

func Verify

func Verify(authToken string, validators ...Validator) (*TokenInfo, error)

Verify

func VerifyGoogleIDToken

func VerifyGoogleIDToken(authToken string, certs *Certs, validators ...Validator) (tokeninfo *TokenInfo, err error)

VerifyGoogleIDToken is

type Validator

type Validator func(*TokenInfo) error

func AudienceValidator

func AudienceValidator(audience string) Validator

func EmailValidator

func EmailValidator(email string) Validator

func ExpireValidator

func ExpireValidator() Validator

func IssuerValidator

func IssuerValidator() Validator

Jump to

Keyboard shortcuts

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