jwt

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Registered Claim Names
	ClaimNameIssuer         = "iss" // RFC 7519, 4.1.1
	ClaimNameSubject        = "sub" // RFC 7519, 4.1.2
	ClaimNameAudience       = "aud" // RFC 7519, 4.1.3
	ClaimNameExpirationTime = "exp" // RFC 7519, 4.1.4
	ClaimNameNotBefore      = "nbf" // RFC 7519, 4.1.5
	ClaimNameIssuedAt       = "iat" // RFC 7519, 4.1.6
	ClaimNameJWTID          = "jti" // RFC 7519, 4.1.7

)

See: https://tools.ietf.org/html/rfc7519

View Source
const (
	// JOSE Header
	HeaderParameterType        = "type" // RFC 7231, 5.1
	HeaderParameterContentType = "cty"  // RFC 7231, 5.2

	// Replicating Claims as Header Parameters
	HeaderParameterIssuer         = ClaimNameIssuer         // RFC 7231, 5.3 RFC 7519, 10.4.1
	HeaderParameterSubject        = ClaimNameSubject        // RFC 7231, 5.3 RFC 7519, 10.4.1
	HeaderParameterAudience       = ClaimNameAudience       // RFC 7231, 5.3 RFC 7519, 10.4.1
	HeaderParameterExpirationTime = ClaimNameExpirationTime // RFC 7231, 5.3
	HeaderParameterNotBefore      = ClaimNameNotBefore      // RFC 7231, 5.3
	HeaderParameterIssuedAt       = ClaimNameIssuedAt       // RFC 7231, 5.3
	HeaderParameterJWTID          = ClaimNameJWTID          // RFC 7231, 5.3
)
View Source
const (
	SigningMethodNone  = "none"
	SigningMethodHS256 = "HS256" // HS256: HMAC using SHA-256
	SigningMethodHS384 = "HS384" // HS384: HMAC using SHA-384
	SigningMethodHS512 = "HS512" // HS512: HMAC using SHA-512
	SigningMethodRS256 = "RS256" // RS256: RSASSA-PKCS-v1_5 using SHA-256
	SigningMethodRS384 = "RS384" // RS384: RSASSA-PKCS-v1_5 using SHA-384
	SigningMethodRS512 = "RS512" // RS512: RSASSA-PKCS-v1_5 using SHA-512
	SigningMethodPS256 = "PS256" // PS256: RSASSA-PSS using SHA-256 and MGF1 with SHA-256
	SigningMethodPS384 = "PS384" // PS384: RSASSA-PSS using SHA-384 and MGF1 with SHA-384
	SigningMethodPS512 = "PS512" // PS512: RSASSA-PSS using SHA-512 and MGF1 with SHA-512
	SigningMethodES256 = "ES256" // ES256: ECDSA using P-256 and SHA-256
	SigningMethodES384 = "ES384" // ES384: ECDSA using P-384 and SHA-384
	SigningMethodES512 = "ES512" // ES512: ECDSA using P-521 and SHA-512
)

https://jwt.io/

Variables

This section is empty.

Functions

func ClaimNamesText

func ClaimNamesText(name string) string

ClaimNamesText returns a text for the Claim Names. It returns the empty string if the code is "".

func Copy

func Copy(elements map[string]interface{}) (result map[string]interface{})

Copy will copy all elements in a map and return a new representational map

func HeaderParameterText

func HeaderParameterText(param string) string

HeaderParameterText returns a text for the Claim Names. It returns the empty string if the code is "".

Types

type AuthKey

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

func NewAuthKey

func NewAuthKey(alg string, privateKey []byte, publicKey []byte, password ...string) (*AuthKey, error)

SymmetricKey : privateKey else: privKey publicKey

func NewAuthKeyFromFile

func NewAuthKeyFromFile(alg string, privateKeyFile string, publicKeyFile string, password ...string) (*AuthKey, error)

func NewAuthKeyFromRandom

func NewAuthKeyFromRandom(alg string) (*AuthKey, error)

func (*AuthKey) GetSignedKey

func (a *AuthKey) GetSignedKey(token *jwt.Token) (interface{}, error)

func (*AuthKey) GetSignedMethod

func (a *AuthKey) GetSignedMethod() jwt.SigningMethod

func (*AuthKey) GetVerifiedKey

func (a *AuthKey) GetVerifiedKey(token *jwt.Token) (interface{}, error)

func (*AuthKey) IsECMAKey

func (a *AuthKey) IsECMAKey() bool

func (*AuthKey) IsRSAKey

func (a *AuthKey) IsRSAKey() bool

func (*AuthKey) IsSymmetricKey

func (a *AuthKey) IsSymmetricKey() bool

type Claims

type Claims struct {
	RegisteredClaims
	Scope []string `json:"scope"`
	Extra map[string]interface{}
}

Claims represent a token's claims.

func (*Claims) Add

func (c *Claims) Add(key string, value interface{})

Add will add a key-value pair to the extra field

func (*Claims) FromMap

func (c *Claims) FromMap(m map[string]interface{})

FromMap will set the claims based on a mapping

func (*Claims) FromMapClaims

func (c *Claims) FromMapClaims(mc jwt.MapClaims)

FromMapClaims will populate claims from a jwt-go MapClaims representation

func (Claims) Get

func (c Claims) Get(key string) interface{}

Get will get a value from the extra field based on a given key

func (*Claims) ToMap

func (c *Claims) ToMap() map[string]interface{}

ToMap will transform the headers to a map structure

func (Claims) ToMapClaims

func (c Claims) ToMapClaims() jwt.MapClaims

ToMapClaims will return a jwt-go MapClaims representation

func (*Claims) With

func (c *Claims) With(expiry time.Time, scope, audience []string) ClaimsContainer

func (*Claims) WithDefaults

func (c *Claims) WithDefaults(iat time.Time, issuer string) ClaimsContainer

type ClaimsContainer

type ClaimsContainer interface {
	// With returns a copy of itself with expiresAt, scope, audience set to the given values.
	With(expiry time.Time, scope, audience []string) ClaimsContainer

	// WithDefaults returns a copy of itself with issuedAt and issuer set to the given default values. If those
	// values are already set in the claims, they will not be updated.
	WithDefaults(iat time.Time, issuer string) ClaimsContainer

	// ToMapClaims returns the claims as a github.com/dgrijalva/jwt-go.MapClaims type.
	ToMapClaims() jwt.MapClaims
}

type RegisteredClaims

type RegisteredClaims struct {
	Subject   string    `json:"sub"`
	Issuer    string    `json:"iss"`
	Audience  []string  `json:"aud"`
	JWTID     string    `json:"jti"`
	IssuedAt  time.Time `json:"iat"`
	NotBefore time.Time `json:"nbf"`
	ExpiresAt time.Time `json:"exp"`
}

func (*RegisteredClaims) SetDefaults

func (c *RegisteredClaims) SetDefaults()

Jump to

Keyboard shortcuts

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