Newer Version Available

This content describes an older version of this product. View Latest

AuthToken Class

Contains methods for providing the access token associated with an authentication provider for an authenticated user, except for the Janrain provider.

Namespace

Auth

AuthToken Methods

The following are methods for AuthToken. All are instance methods.

getAccessToken(String, String)

Returns an access token for the current user using the specified 18-character identifier of an Auth. Provider definition in your organization and the name of the provider, such as Salesforce or Facebook.

Signature

public String getAccessToken(String authProviderId, String providerName)

Parameters

authProviderId
Type: String
providerName
Type: String

Return Value

Type: String

getAccessTokenMap(String, String)

Returns a map from the third-party identifier to the access token for the currently logged-in Salesforce user. The identifier value depends on the third party. For example, for Salesforce it would be the user ID, while for Facebook it would be the user number.

Signature

public Map<String, String> getAccessTokenMap(String authProviderId, String providerName)

Parameters

authProviderId
Type: String
providerName
Type: String

Return Value

Type: Map<String, String>

refreshAccessToken(String, String, String)

Returns a map from the third-party identifier containing a refreshed access token for the currently logged-in Salesforce user.

Signature

public Map<String, String> refreshAccessToken(String authProviderId, String providerName, String oldAccessToken)

Parameters

authProviderId
Type: String
providerName
Type: String
oldAccessToken
Type: String

Return Value

Type: Map<String, 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().

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