openid

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2021 License: MIT Imports: 17 Imported by: 10

Documentation

Overview

Package openid provides a specialized token that provides utilities to work with OpenID JWT tokens.

In order to use OpenID claims, you specify the token to use in the jwt.Parse method

jwt.Parse(data, jwt.WithToken(openid.New())

Index

Constants

View Source
const (
	AddressFormattedKey     = "formatted"
	AddressStreetAddressKey = "street_address"
	AddressLocalityKey      = "locality"
	AddressRegionKey        = "region"
	AddressPostalCodeKey    = "postal_code"
	AddressCountryKey       = "country"
)
View Source
const (
	AudienceKey            = "aud"
	ExpirationKey          = "exp"
	IssuedAtKey            = "iat"
	IssuerKey              = "iss"
	JwtIDKey               = "jti"
	NotBeforeKey           = "nbf"
	SubjectKey             = "sub"
	NameKey                = "name"
	GivenNameKey           = "given_name"
	MiddleNameKey          = "middle_name"
	FamilyNameKey          = "family_name"
	NicknameKey            = "nickname"
	PreferredUsernameKey   = "preferred_username"
	ProfileKey             = "profile"
	PictureKey             = "picture"
	WebsiteKey             = "website"
	EmailKey               = "email"
	EmailVerifiedKey       = "email_verified"
	GenderKey              = "gender"
	BirthdateKey           = "birthdate"
	ZoneinfoKey            = "zoneinfo"
	LocaleKey              = "locale"
	PhoneNumberKey         = "phone_number"
	PhoneNumberVerifiedKey = "phone_number_verified"
	AddressKey             = "address"
	UpdatedAtKey           = "updated_at"
)

Variables

This section is empty.

Functions

func RegisterCustomField added in v1.1.2

func RegisterCustomField(name string, object interface{})

RegisterCustomField allows users to specify that a private field be decoded as an instance of the specified type. This option has a global effect.

For example, suppose you have a custom field `x-birthday`, which you want to represent as a string formatted in RFC3339 in JSON, but want it back as `time.Time`.

In that case you would register a custom field as follows

jwt.RegisterCustomField(`x-birthday`, timeT)

Then `token.Get("x-birthday")` will still return an `interface{}`, but you can convert its type to `time.Time`

bdayif, _ := token.Get(`x-birthday`)
bday := bdayif.(time.Time)

Types

type AddressClaim

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

AddressClaim is the address claim as described in https://openid.net/specs/openid-connect-core-1_0.html#AddressClaim

func NewAddress

func NewAddress() *AddressClaim

func (*AddressClaim) Accept

func (t *AddressClaim) Accept(v interface{}) error

func (AddressClaim) Country

func (t AddressClaim) Country() string

Country is a convenience function to retrieve the corresponding value store in the token if there is a problem retrieving the value, the zero value is returned. If you need to differentiate between existing/non-existing values, use `Get` instead

func (AddressClaim) Formatted

func (t AddressClaim) Formatted() string

Formatted is a convenience function to retrieve the corresponding value store in the token if there is a problem retrieving the value, the zero value is returned. If you need to differentiate between existing/non-existing values, use `Get` instead

func (*AddressClaim) Get

func (t *AddressClaim) Get(s string) (interface{}, bool)

func (AddressClaim) Locality

func (t AddressClaim) Locality() string

Locality is a convenience function to retrieve the corresponding value store in the token if there is a problem retrieving the value, the zero value is returned. If you need to differentiate between existing/non-existing values, use `Get` instead

func (AddressClaim) MarshalJSON

func (t AddressClaim) MarshalJSON() ([]byte, error)

MarshalJSON serializes the token in JSON format.

func (AddressClaim) PostalCode

func (t AddressClaim) PostalCode() string

PostalCode is a convenience function to retrieve the corresponding value store in the token if there is a problem retrieving the value, the zero value is returned. If you need to differentiate between existing/non-existing values, use `Get` instead

func (AddressClaim) Region

func (t AddressClaim) Region() string

Region is a convenience function to retrieve the corresponding value store in the token if there is a problem retrieving the value, the zero value is returned. If you need to differentiate between existing/non-existing values, use `Get` instead

func (*AddressClaim) Set

func (t *AddressClaim) Set(key string, value interface{}) error

func (AddressClaim) StreetAddress

func (t AddressClaim) StreetAddress() string

StreetAddress is a convenience function to retrieve the corresponding value store in the token if there is a problem retrieving the value, the zero value is returned. If you need to differentiate between existing/non-existing values, use `Get` instead

func (*AddressClaim) UnmarshalJSON

func (t *AddressClaim) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes data from a JSON data buffer into a AddressClaim

type BirthdateClaim

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

func (*BirthdateClaim) Accept

func (b *BirthdateClaim) Accept(v interface{}) error

Accepts a value read from JSON, and converts it to a BirthdateClaim. This method DOES NOT verify the correctness of a date. Consumers should check for validity of dates such as Apr 31 et al

func (BirthdateClaim) Day

func (b BirthdateClaim) Day() int

func (BirthdateClaim) MarshalText

func (b BirthdateClaim) MarshalText() ([]byte, error)

func (BirthdateClaim) Month

func (b BirthdateClaim) Month() int

func (BirthdateClaim) String

func (b BirthdateClaim) String() string

func (*BirthdateClaim) UnmarshalJSON

func (b *BirthdateClaim) UnmarshalJSON(data []byte) error

func (BirthdateClaim) Year

func (b BirthdateClaim) Year() int

type ClaimPair

type ClaimPair = mapiter.Pair

type DecodeCtx added in v1.2.1

type DecodeCtx = json.DecodeCtx

type Iterator

type Iterator = mapiter.Iterator

type Token

type Token interface {
	Audience() []string
	Expiration() time.Time
	IssuedAt() time.Time
	Issuer() string
	JwtID() string
	NotBefore() time.Time
	Subject() string
	Name() string
	GivenName() string
	MiddleName() string
	FamilyName() string
	Nickname() string
	PreferredUsername() string
	Profile() string
	Picture() string
	Website() string
	Email() string
	EmailVerified() bool
	Gender() string
	Birthdate() *BirthdateClaim
	Zoneinfo() string
	Locale() string
	PhoneNumber() string
	PhoneNumberVerified() bool
	Address() *AddressClaim
	UpdatedAt() time.Time
	PrivateClaims() map[string]interface{}
	Get(string) (interface{}, bool)
	Set(string, interface{}) error
	Remove(string) error
	Clone() (jwt.Token, error)
	Iterate(context.Context) Iterator
	Walk(context.Context, Visitor) error
	AsMap(context.Context) (map[string]interface{}, error)
}

func New

func New() Token

New creates a standard token, with minimal knowledge of possible claims. Standard claims include"aud", "exp", "iat", "iss", "jti", "nbf", "sub", "name", "given_name", "middle_name", "family_name", "nickname", "preferred_username", "profile", "picture", "website", "email", "email_verified", "gender", "birthdate", "zoneinfo", "locale", "phone_number", "phone_number_verified", "address" and "updated_at". Convenience accessors are provided for these standard claims

type TokenWithDecodeCtx added in v1.2.1

type TokenWithDecodeCtx = json.DecodeCtxContainer

type Visitor

type Visitor = iter.MapVisitor

type VisitorFunc

type VisitorFunc = iter.MapVisitorFunc

Jump to

Keyboard shortcuts

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