...

Package jwt

import "cloud.google.com/go/auth/internal/jwt"
Overview
Index

Overview ▾

Constants

const (
    // HeaderAlgRSA256 is the RS256 [Header.Algorithm].
    HeaderAlgRSA256 = "RS256"
    // HeaderAlgES256 is the ES256 [Header.Algorithm].
    HeaderAlgES256 = "ES256"
    // HeaderType is the standard [Header.Type].
    HeaderType = "JWT"
)

func EncodeJWS

func EncodeJWS(header *Header, c *Claims, key *rsa.PrivateKey) (string, error)

EncodeJWS encodes the data using the provided key as a JSON web signature.

func VerifyJWS

func VerifyJWS(token string, key *rsa.PublicKey) error

VerifyJWS tests whether the provided JWT token's signature was produced by the private key associated with the provided public key.

type Claims

Claims represents the claims set of a JWT.

type Claims struct {
    // Iss is the issuer JWT claim.
    Iss string `json:"iss"`
    // Scope is the scope JWT claim.
    Scope string `json:"scope,omitempty"`
    // Exp is the expiry JWT claim. If unset, default is in one hour from now.
    Exp int64 `json:"exp"`
    // Iat is the subject issued at claim. If unset, default is now.
    Iat int64 `json:"iat"`
    // Aud is the audience JWT claim. Optional.
    Aud string `json:"aud"`
    // Sub is the subject JWT claim. Optional.
    Sub string `json:"sub,omitempty"`
    // AdditionalClaims contains any additional non-standard JWT claims. Optional.
    AdditionalClaims map[string]interface{} `json:"-"`
}

func DecodeJWS

func DecodeJWS(payload string) (*Claims, error)

DecodeJWS decodes a claim set from a JWS payload.

Header represents a JWT header.

type Header struct {
    Algorithm string `json:"alg"`
    Type      string `json:"typ"`
    KeyID     string `json:"kid"`
}