Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class JwtBearerGrant

  1. Object
  2. JwtBearerGrant

ImplementsAccessTokenGrant

The JWT bearer grant of RFC 7523 section 2.1: this server signs an assertion with a service account’s private key and exchanges it for an access token. No client secret exists; the key is the credential.

It is how Google service accounts authenticate (see GoogleServiceAccountCredentials), and Salesforce, DocuSign and others accept it the same way. Every exchange signs a new assertion, valid for assertionLifetimeSeconds (one hour by default, the most Google accepts) and carrying a fresh jti.

Nested types

class JwtBearerGrant.Builder

Fields

public static final String GRANT_TYPE = "urn:ietf:params:oauth:grant-type:jwt-bearer"The grant_type of this grant.

Methods

public static JwtBearerGrant.Builder builder(String tokenUri, String issuer, Jwk signingKey)
public AccessToken fetch()Exchanges the credentials for a new token.
public String toString()Returns a string representation of the object.

Inherited methods

Field details

GRANT_TYPE

public static final String GRANT_TYPE = "urn:ietf:params:oauth:grant-type:jwt-bearer"
The grant_type of this grant.

Method details

builder

public static JwtBearerGrant.Builder builder(String tokenUri, String issuer, Jwk signingKey)

Parameters

tokenUri String
the token endpoint the assertion is exchanged at
issuer String
iss: the service account, such as its client email
signingKey Jwk
the service account’s private key; its id, if it has one, goes into the header as kid

fetch

public AccessToken fetch()
Exchanges the credentials for a new token.

Throws

TokenAcquisitionException
when no token was issued

toString

public String toString()
Returns a string representation of the object. In general, the toString method returns a string that “textually represents” this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@’, and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + ‘@’ + Integer.toHexString(hashCode())