Newer Version Available
AuthToken Class
Namespace
AuthToken Methods
The following are methods for AuthToken. All methods are static.
getAccessToken(authProviderId, providerName)
Signature
public static String getAccessToken(String authProviderId, String providerName)
Parameters
- authProviderId
- Type: String
- providerName
- Type: String
-
The proper name of the third party. For all providers except
Janrain, the expected values are
- Salesforce
- Open ID Connect
- Microsoft Access Control Service
Return Value
Type: String
getAccessTokenMap(authProviderId, providerName)
Signature
public static Map<String, String> getAccessTokenMap(String authProviderId, String providerName)
Parameters
- authProviderId
- Type: String
- providerName
- Type: String
- The proper name of the third party. For all providers except
Janrain, the expected values are
- Salesforce
- Open ID Connect
- Microsoft Access Control Service
refreshAccessToken(authProviderId, providerName, oldAccessToken)
Signature
public static Map<String, String> refreshAccessToken(String authProviderId, String providerName, String oldAccessToken)
Parameters
- authProviderId
- Type: String
- providerName
- Type: String
- The proper name of the third party. For all providers except
Janrain, the expected values are
- Salesforce
- Open ID Connect
- Microsoft Access Control Service
- oldAccessToken
- Type: String
Usage
This method works when using Salesforce or an OpenID Connect provider, but not when using Facebook or Janrain. The returned map contains AccessToken and RefreshError keys. Evaluate the keys in the response to check if the request was successful. For a successful request, the RefreshError value is null, and AccessToken is a token value. For an unsuccessful request, the RefreshError value is an error message, and the AccessToken value is null.
When successful, this method updates the token stored in the database, which you can get using Auth.AuthToken.getAccessToken().
If you are using an OpenID Connect authentication provider, an id_token is not required in the response from the provider. If a Token Issuer is specified in the Auth. Provider settings and an id_token is provided anyway, Salesforce will verify it.
Example
1String accessToken = Auth.AuthToken.getAccessToken('0SOD000000000De', 'Open ID connect');
2Map<String, String> responseMap = Auth.AuthToken.refreshAccessToken('0SOD000000000De', 'Open ID connect', accessToken);A successful request includes the access token in the response.
1 (RefreshError,null)(AccessToken,00DD00000007BhE!AQkAQFzj...)revokeAccess(authProviderId, providerName, userId, remoteIdentifier)
Signature
public static Boolean revokeAccess(String authProviderId, String providerName, String userId, String remoteIdentifier)
Parameters
- authProviderId
- Type: String
- The ID of the Auth. Provider in the Salesforce organization.
- providerName
- Type: String
- The proper name of the third party. For all providers except
Janrain, the expected values are
- Salesforce
- Open ID Connect
- Microsoft Access Control Service
- userId
- Type: String
- The 15-character ID for the user whose access is being revoked.
- remoteIdentifier
- Type: String
- The unique ID for the user in the third-party system (this value is in the associated ThirdPartyAccountLink standard object).
Return Value
Type: Boolean
The return value is true if the revokeAccess() operation is successful; otherwise false.
Example
The following example revokes a Facebook user's access token.
1Auth.AuthToken.revokeAccess('0SOxx00000#####', 'facebook', '005xx00000#####', 'ThirdPartyIdentifier_exist214176560#####');