JWTBearerTokenExchange Class
Contains methods that POST the signed JWT bearer token to a token endpoint to request an access token, in the OAuth 2.0 JWT bearer token flow.
Use the methods in this class to post a signed JWT bearer token to the OAuth token endpoint, in exchange for an access token.
To test HTTP callouts to the token endpoint, use the Auth.HttpCalloutMockUtil class.
In the following example application, the Apex controller:
- Creates the JSON Claims Set.
- Specifies the scope of the request with additional claims.
- Creates the signed JWT.
- Specifies the token endpoint and POSTs to it.
- Gets the access token from the HTTP response.
The following are constructors for JWTBearerTokenExchange.
-
JWTBearerTokenExchange(tokenEndpoint, jws)
Creates an instance of the
JWTBearerTokenExchangeclass using the specified token endpoint and the signed JWT bearer token. -
Creates an instance of the
Auth.JWTBearerTokenExchangeclass.
Creates an instance of the JWTBearerTokenExchange class using the specified token endpoint and the signed JWT bearer token.
public JWTBearerTokenExchange(String tokenEndpoint, Auth.JWS jws)
-
tokenEndpoint:
Type: String
The token endpoint that the signed JWT bearer token is POSTed to.
-
jws:
Type: Auth.JWS
The signed JWT bearer token.
Creates an instance of the Auth.JWTBearerTokenExchange class.
public JWTBearerTokenExchange()
The following are methods for JWTBearerTokenExchange. All are instance methods.
-
Makes a duplicate copy of the JWTBearerTokenExchange object.
-
Returns the
access_tokenin the token response to the JWT bearer token request. -
Returns the grant type specified in the JWT bearer token request. The grant type value defaults to
urn:ietf:params:oauth:grant-type:jwt-bearer. -
Returns the full
System.HttpResponsetoken response to the JWT bearer token request. -
Returns the JWS specified in the JWT bearer token request.
-
Returns the token endpoint that the JWT bearer token request is POSTed to.
-
Sets the grant type in the JWT bearer token request. Returned by the
getGrantType()method. -
Sets the JWS in the JWT bearer token request. Returned by the
getJWS()method. -
setTokenEndpoint(tokenEndpoint)
Sets the token endpoint that the JWT bearer token request is POSTed to. Returned by the
getTokenEndpoint()method.
Makes a duplicate copy of the JWTBearerTokenExchange object.
public Object clone()
Type: JWTBearerTokenExchange
Returns the access_token in the token response to the JWT bearer token request.
public String getAccessToken()
Type: String
This method extracts the access_token from the token response. If the token response issues the access token in a different parameter, the request fails.
If you want the full HTTP token response returned, use getHttpResponse instead.
Returns the grant type specified in the JWT bearer token request. The grant type value defaults to urn:ietf:params:oauth:grant-type:jwt-bearer.
public String getGrantType()
Type: String
Returns the full System.HttpResponse token response to the JWT bearer token request.
public System.HttpResponse getHttpResponse()
Type: System.HttpResponse
You can get the access token from the full System.HttpResponse. If you want only the access_token from the token response, you can use getAccessToken instead.
Returns the JWS specified in the JWT bearer token request.
public Auth.JWS getJWS()
Type: Auth.JWS
Returns the token endpoint that the JWT bearer token request is POSTed to.
public String getTokenEndpoint()
Type: String
Sets the grant type in the JWT bearer token request. Returned by the getGrantType() method.
public void setGrantType(String grantType)
-
grantType:
Type: String
Type: void
Sets the JWS in the JWT bearer token request. Returned by the getJWS() method.
public void setJWS(Auth.JWS jws)
-
jws:
Type: Auth.JWS
Type: void
Sets the token endpoint that the JWT bearer token request is POSTed to. Returned by the getTokenEndpoint() method.
public void setTokenEndpoint(String tokenEndpoint)
-
tokenEndpoint:
Type: String
Type: void