package jwt

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

Index

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"
)

Functions

func EncodeJWS

func EncodeJWS(header *Header, c *Claims, signer crypto.Signer) (string, error)

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

func VerifyJWS

func VerifyJWS(token string, key crypto.PublicKey) error

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

Types

type Claims

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:"-"`
}

Claims represents the claims set of a JWT.

func DecodeJWS

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

DecodeJWS decodes a claim set from a JWS payload.

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

Header represents a JWT header.

Source Files

jwt.go

Version
v0.20.0 (latest)
Published
Apr 6, 2026
Platform
js/wasm
Imports
14 packages
Last checked
6 minutes ago

Tools for package owners.