jwt: gitlab.com/rucuriousyet/jwt Index | Files

package jwt

import "gitlab.com/rucuriousyet/jwt"

Index

Package Files

jwt.go

Constants

const (
    // HS512 is the HMAC SHA512 JWT Signing Algorithm
    HS512 SigningAlgorithm = "HS512"

    // HS256 is the HMAC SHA256 JWT Signing Algorithm
    HS256 SigningAlgorithm = "HS256"

    // Issuer is a public claim from the JWT
    // RFC that should be set to the url of
    // the issuing website/host of a token
    Issuer = "iss"

    // Subject is a public claim from the JWT
    // RFC that should be set the user/actor
    // identifier (usually a UUID or email address)
    Subject = "sub"

    // IssuedAt is a public claim from the JWT
    // RFC that should be set to the time
    // (ideally UTC) the token was created
    IssuedAt = "iat"

    // ExpiresAt is a public claim from the JWT
    // RFC that should be set to the desired
    // expiry time of a token. I recommend
    // short lived tokens with a refresh mechanism
    // to ensure control over tokens in the wild
    // and make it easy to revoke access
    ExpiresAt = "exp"

    // TokenID (jti) is a public claim from the JWT
    // RFC that should be set to the ID of this
    // newly generated token, commonly used for
    // a token refresh mechanism or white/blacklisting
    TokenID = "jti"

    // Audience is a public claim from the JWT
    // RFC that should be set to the target
    // token validator/host url
    Audience = "aud"

    // Issuer is a public claim from the JWT
    // RFC that should be set to the time the
    // token was created, or a later start timeframe
    NotBefore = "nbf"
)

func New Uses

func New(alg SigningAlgorithm, secret []byte, claims M) (string, error)

New generates and signs a new JWT token with the supplied algorithm. secret and claims object, returning a string and error.

type JWTToken Uses

type JWTToken struct {
    SigningAlgorithm SigningAlgorithm
    Signature        []byte

    Header M
    Claims M
    // contains filtered or unexported fields
}

JWTToken is an object to store token information after parsing for validation or claim-access purposes

func Parse Uses

func Parse(tokenStr string) (*JWTToken, error)

Parse parses a token string and returns a pointer to a JWTToken and error. Please note that this function merely parses the token, validation must be done after a JWTToken is returned.

func (*JWTToken) VerifySignature Uses

func (j *JWTToken) VerifySignature(secret []byte) bool

VerifySignature compares the signature of a token to a newly generated signature using the supplied secret.

type M Uses

type M map[string]interface{}

M is just a shorthand for map[string]interface{}

type SigningAlgorithm Uses

type SigningAlgorithm string

SigningAlgorithm is a type used for to enumerate supported algorithms as constants

Package jwt imports 9 packages (graph). Updated 2018-07-02. Refresh now. Tools for package owners.