Documentation ¶
Index ¶
- Constants
- Variables
- func Base64UrlDecode(value string) ([]byte, error)
- func Base64UrlEncode(value []byte) string
- func RegisterSigningMethod(algorithm Algorithm, f func() SigningMethod)
- type Algorithm
- type ClaimName
- type Claims
- type Header
- type JOSEHeaderParameter
- type JWT
- type Key
- type SigningMethod
- type SigningMethodHMAC
- type SigningMethodNONE
Constants ¶
const ( // AlgorithmNone if the JWT should not be signed or encrypted AlgorithmNone = "none" // AlgorithmHS256 uses HMAC SHA-256 to sign the JWT AlgorithmHS256 = "HS256" )
Algorithms specified in RFC section 8.
Variables ¶
var ( // ErrUnknownAlgorithm: unknown algorithm ErrUnknownAlgorithm = errors.New("unknown algorithm") // ErrInvalidKeyType: key is of invalid type ErrInvalidKeyType = errors.New("key is of invalid type") ErrHashUnavailable = errors.New("the requested hash function is unavailable") // ErrSignatureInvalid: signature is invalid ErrSignatureInvalid = errors.New("signature is invalid") )
errors defined for the jwt package
Functions ¶
func Base64UrlDecode ¶
Base64UrlDecode decode JWT specific base64url encoding
func Base64UrlEncode ¶
Base64UrlEncode encode JWT specific base64url encoding
func RegisterSigningMethod ¶
func RegisterSigningMethod(algorithm Algorithm, f func() SigningMethod)
RegisterSigningMethod use to add a SigningMethod
Types ¶
type ClaimName ¶
type ClaimName = string
ClaimName Unique Key of Claims JSON Object
const ( // RegisteredClaimIssuer RFC 4.1.1. Registered JWT Claim "iss" Issuer RegisteredClaimIssuer ClaimName = "iss" // RegisteredClaimSubject RFC 4.1.2. Registered JWT Claim "sub" Subject RegisteredClaimSubject ClaimName = "sub" // RegisteredClaimAudience RFC 4.1.3. Registered JWT Claim "aud" Audience RegisteredClaimAudience ClaimName = "aud" // RegisteredClaimExpirationTime RFC 4.1.4. Registered JWT Claim "exp" Expiration Time RegisteredClaimExpirationTime ClaimName = "exp" // RegisteredClaimNotBefore RFC 4.1.5. Registered JWT Claim "nbf" Not Before RegisteredClaimNotBefore ClaimName = "nbf" // RegisteredClaimIssuedAt RFC 4.1.6. Registered JWT Claim "iat" Issued At RegisteredClaimIssuedAt ClaimName = "iat" // RegisteredClaimJWTID RFC 4.1.7. Registered JWT Claim "jti" JWT ID RegisteredClaimJWTID ClaimName = "jti" )
Registered Claim Names RFC 4.1.
type Claims ¶
type Claims map[string]interface{}
Claims contains all values for the JWT payload
type JOSEHeaderParameter ¶
type JOSEHeaderParameter = string
JOSEHeaderParameter Unique Key of JOSE Header JSON Object
const ( // JOSEHeaderParameterType RFC 5.1. Header Parameter "typ" Type JOSEHeaderParameterType JOSEHeaderParameter = "typ" // RECOMMENDED Value is "JWT" // JOSEHeaderParameterContentType RFC 5.2. Header Parameter "cty" Content Type JOSEHeaderParameterContentType JOSEHeaderParameter = "cty" // JOSEHeaderParameterAlgorithm ? Header Parameter "alg" Algorithm JOSEHeaderParameterAlgorithm JOSEHeaderParameter = "alg" )
JOSE Header Parameters RFC 5.
type JWT ¶
type JWT struct { // Raw hole token is set when you parse the JWT Raw string // Method the SigningMethod for signing the JWT Method SigningMethod // Header map for Headers the first part of the JWT Header Header // Claims values for the second part of the JWT Claims Claims // Signature third part of the JWT signature of part one and two of the JWT is set when you parse the JWT Signature string // Valid is the JWT valid is set when you parse the JWT Valid bool }
JWT type for the JWT itself
func NewWithClaims ¶
func NewWithClaims(method SigningMethod, claims Claims) *JWT
New creates an JWT with direct filled in Claims
type SigningMethod ¶
type SigningMethod interface { Sign(signing string, key Key) (string, error) // Returns encoded signature or error Verify(signing, signature string, key Key) (bool, error) // Returns true and nil if signing is verified, false and error if signing is invalid Algo() Algorithm // Returns Algorithm use in Signing Method for example AlgorithmHS256 }
SigningMethod interface for implementing method to sign and verify tokens
func GetSigningMethod ¶
func GetSigningMethod(algorithm Algorithm) (SigningMethod, error)
GetSigningMethod use to get SigningMethod to Algorithm
type SigningMethodHMAC ¶
SigningMethodHMAC implements the HMAC-SHA family of signing methods
var ( // SigningMethodHS256 using HMAC with SHA256 to signing the JWT SigningMethodHS256 *SigningMethodHMAC )
Specific Algorithm of the HMAC-SHA family
func (*SigningMethodHMAC) Algo ¶
func (m *SigningMethodHMAC) Algo() Algorithm
Algo returns the Algorithm of the SigningMethodHMAC
type SigningMethodNONE ¶
type SigningMethodNONE struct {
Algorithm Algorithm
}
only for special use cases NOT RECOMMENDED only here because its defined in RFC SigningMethodNONE the SigningMethod for AlgorithmNone
var ( // SigningMethodNone return empty but valid signature used for Unsecured JWTs RFC 6. SigningMethodNone *SigningMethodNONE )
specific SigningMethods for SigningMethodNONE
func (*SigningMethodNONE) Algo ¶
func (m *SigningMethodNONE) Algo() Algorithm
Algo returns the Algorithm of the SigningMethodNONE