---
schema_version: "1"
id: d47b694ccce24c5742da0cbc8931fb60405f63bbe82e889a807934eecb3848af
title: JWS Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_class_Auth_JWS.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_JWS.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 5f4313ec0a8941a70d93e39e67cbff61e52759eddabdf446588156a29ad3c532
description: Contains methods that apply a digital signature to a JSON Web Token (JWT), using a JSON Web Signature (JWS) data structure. This class creates the signed JWT bearer token, which can be used to request an OAuth access token in the OAuth 2.0 JWT bearer token flow.Creates an instance of the JWS class using the specified Auth.JWT payload and the certificate used for signing the JWT bearer token.Creates an instance of the JWS class using the specified payload and certificate used for signing the JWT bearer token.Makes a duplicate copy of the JWS object.Returns the compact serialization representation of the JWS as a concatenated string, with the encoded JWS header, encoded JWS payload, and encoded JWS signature strings separated by period ('.') characters.
---
# JWS Class

Contains methods that apply a digital signature to a JSON Web Token (JWT), using a JSON Web Signature (JWS) data structure. This class creates the signed JWT bearer token, which can be used to request an OAuth access token in the OAuth 2.0 JWT bearer token flow.

## Namespace

[Auth](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_Auth.htm "The Auth namespace provides an interface and classes for single sign-on into Salesforce and session security management.")

## Usage

Use the methods in this class to sign the JWT bearer token with the X509 certificate.

- **[JWS Constructors](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_JWS.htm#apex_Auth_JWS_constructors)**
- **[JWS Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_JWS.htm#apex_Auth_JWS_methods)**

## JWS Constructors

The following are constructors for JWS.

- **[JWS(jwt, certDevName)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_JWS.htm#apex_Auth_JWS_ctor)**  
    Creates an instance of the JWS class using the specified Auth.JWT payload and the certificate used for signing the JWT bearer token.
- **[JWS(payload, certDevName)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_JWS.htm#apex_Auth_JWS_ctor_2)**  
    Creates an instance of the JWS class using the specified payload and certificate used for signing the JWT bearer token.

### JWS(jwt, certDevName)

Creates an instance of the JWS class using the specified Auth.JWT payload and the certificate used for signing the JWT bearer token.

#### Signature

public JWS(Auth.JWT jwt, String certDevName)

#### Parameters

- **jwt**:
    
    Type: [Auth.JWT](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_JWT.htm#apex_class_Auth_JWT "Generates the JSON Claims Set in a JSON Web Token (JWT). The resulting Base64-encoded payload can be passed as an argument to create an instance of the Auth.JWS class.")
    
    The Base64-encoded JSON Claims Set in the JWT bearer token generated by Auth.JWT.
- **certDevName**:
    
    Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")
    
    The Unique Name for a certificate stored in the Salesforce org’s Certificate and Key Management page to use for signing the JWT bearer token.

#### Usage

Calls the toJSONString() method in Auth.JWT and sets the resulting string as the payload of the JWT bearer token. Alternatively, you can specify the payload directly using JWS(payload, certDevName).

### JWS(payload, certDevName)

Creates an instance of the JWS class using the specified payload and certificate used for signing the JWT bearer token.

#### Signature

public JWS(String payload, String certDevName)

#### Parameters

- **payload**:
    
    Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")
    
    The Base64-encoded JSON Claims Set in the JWT bearer token.
- **certDevName**:
    
    Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")
    
    The Unique Name for a certificate stored in the Salesforce org’s Certificate and Key Management page to use for signing the JWT bearer token.

#### Usage

Sets the payload string as the payload of the JWT bearer token. Alternatively, if you generate the payload using Auth.JWT, you can use JWS(jwt, certDevName) instead.

## JWS Methods

The following are methods for JWS. All are instance methods.

- **[clone()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_JWS.htm#apex_Auth_JWS_clone)**  
    Makes a duplicate copy of the JWS object.
- **[getCompactSerialization()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Auth_JWS.htm#apex_Auth_JWS_getCompactSerialization)**  
    Returns the compact serialization representation of the JWS as a concatenated string, with the encoded JWS header, encoded JWS payload, and encoded JWS signature strings separated by period ('.') characters.

### clone()

Makes a duplicate copy of the JWS object.

#### Signature

public Object clone()

#### Return Value

Type: [JWS](#apex_class_Auth_JWS "Contains methods that apply a digital signature to a JSON Web Token (JWT), using a JSON Web Signature (JWS) data structure. This class creates the signed JWT bearer token, which can be used to request an OAuth access token in the OAuth 2.0 JWT bearer token flow.")

### getCompactSerialization()

Returns the compact serialization representation of the JWS as a concatenated string, with the encoded JWS header, encoded JWS payload, and encoded JWS signature strings separated by period ('.') characters.

#### Signature

public String getCompactSerialization()

#### Return Value

Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")