Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/jose/jwt/sign.ts>SignJWT

"JSON Web Almost Everything" - JWA, JWS, JWE, JWT, JWK, JWKS with no dependencies using runtime's native crypto in Node.js, Browser, Cloudflare Workers, Electron, and Deno.
Extremely Popular
Go to Latest
class SignJWT
extends ProduceJWT
import { SignJWT } from "https://deno.land/x/jose@v4.8.3/jwt/sign.ts";

The SignJWT class is a utility for creating Compact JWS formatted JWT strings.

Examples

Usage

const jwt = await new jose.SignJWT({ 'urn:example:claim': true })
  .setProtectedHeader({ alg: 'ES256' })
  .setIssuedAt()
  .setIssuer('urn:example:issuer')
  .setAudience('urn:example:audience')
  .setExpirationTime('2h')
  .sign(privateKey)

console.log(jwt)

Properties

private
_protectedHeader: JWTHeaderParameters

Methods

Sets the JWS Protected Header on the SignJWT object.

sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<string>

Signs and returns the JWT.