Class JwtBearerGrant

java.lang.Object
com.codename1.backend.security.oauth2.client.credentials.JwtBearerGrant
All Implemented Interfaces:
AccessTokenGrant

public final class JwtBearerGrant extends Object implements AccessTokenGrant

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.

  • Field Details

  • Method Details

    • builder

      public static JwtBearerGrant.Builder builder(String tokenUri, String issuer, Jwk signingKey)
      Parameters:
      tokenUri - the token endpoint the assertion is exchanged at
      issuer - iss: the service account, such as its client email
      signingKey - the service account's private key; its id, if it has one, goes into the header as kid
    • fetch

      public AccessToken fetch()
      Description copied from interface: AccessTokenGrant
      Exchanges the credentials for a new token.
      Specified by:
      fetch in interface AccessTokenGrant
    • toString

      public String toString()
      Description copied from class: Object
      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())
      Overrides:
      toString in class Object