Class ClientCredentialsGrant

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

public final class ClientCredentialsGrant extends Object implements AccessTokenGrant

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.

  • Field Details

    • JWT_BEARER_ASSERTION_TYPE

      public static final String JWT_BEARER_ASSERTION_TYPE
      client_assertion_type of a private_key_jwt client.
      See Also:
  • Method Details

    • builder

      public static ClientCredentialsGrant.Builder builder(String tokenUri, String clientId)
      Parameters:
      tokenUri - the authorization server's token endpoint
      clientId - this server's client id there
    • 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