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

public final class ClientCredentialsGrant

  1. Object
  2. ClientCredentialsGrant

ImplementsAccessTokenGrant

The OAuth2 client credentials grant (RFC 6749 section 4.4): this server authenticates as itself and receives a token for its own account.

AccessTokenProvider billing = new AccessTokenProvider(
        ClientCredentialsGrant.builder("https://auth.example.com/oauth/token", "orders")
                .clientSecret(config.get("billing.secret"))
                .scopes("invoices:write")
                .build());
Web.request("POST", url, Arrays.asList("Authorization: "
        + billing.getToken().toAuthorizationHeader()), body);

The client authenticates with a secret in an HTTP Basic header (the default, client_secret_basic), with a secret in the form (client_secret_post), or with a JWT signed by its own key (private_key_jwt, RFC 7523 section 2.2), which sends no shared secret at all.

Nested types

enum ClientCredentialsGrant.AuthenticationHow the client proves who it is.
class ClientCredentialsGrant.Builder

Fields

public static final String JWT_BEARER_ASSERTION_TYPE = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"client_assertion_type of a private_key_jwt client.

Methods

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

Inherited methods

Field details

JWT_BEARER_ASSERTION_TYPE

public static final String JWT_BEARER_ASSERTION_TYPE = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
client_assertion_type of a private_key_jwt client.

Method details

builder

public static ClientCredentialsGrant.Builder builder(String tokenUri, String clientId)

Parameters

tokenUri String
the authorization server’s token endpoint
clientId String
this server’s client id there

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