Generate the Access Token for Agentforce Conversation Client Web SDK 

To complete the authentication process, you need to generate an access token and a frontdoor URL. Use the generated frontdoor URL as the authCredential value when you initialize the SDK.

Generate the Access Token 

To generate the token without creating logic for single sign-on, you can use this command to get the access_token. In this command, the location references your Salesforce org and client_id and client_secret are the values that you copied and saved from the OAuth Settings.

1curl --location 'https://<your-salesforce-org>/services/oauth2/token' \
2--data-urlencode 'grant_type=client_credentials' \
3--data-urlencode 'client_id=<client_id_of_the_app_created_in_previous_step>' \
4--data-urlencode 'client_secret=<client_secret_of_the_app_created_in_previous_step>'

For more information on Salesforce OAuth flows and access tokens, see

Generate a Frontdoor URL for Embedding 

Frontdoor URLs are used to bridge into UI sessions, giving users uninterrupted access to Salesforce and other apps. It uses an existing session to automatically log users into a new UI with making them enter their credentials again.

Frontdoor URLs are short-lived. For session refresh, a new frontdoor URL must be generated.

Note

Example: Generate a Frontdoor URL in JavaScript 

1const getFrontdoorUrl = async (accessToken: string, instanceUrl: string) => {
2  try {
3    const frontdoorEndpoint = `${instanceUrl}/services/oauth2/singleaccess`;
4
5    const myHeaders = new Headers();
6    myHeaders.append('accept', 'application/json');
7    myHeaders.append('authorization', `Bearer ${accessToken}`);
8    myHeaders.append('content-type', 'application/x-www-form-urlencoded');
9
10    const urlencoded = new URLSearchParams();
11
12    const requestOptions = {
13      method: 'POST',
14      headers: myHeaders,
15      body: urlencoded
16    };
17
18    const response = await fetch(frontdoorEndpoint, requestOptions);
19    if (!response.ok) {
20      return {error: `Salesforce API responded with ${response.status}`, statusCode: response.status};
21    }
22    const responseData = await response.json();
23    return {frontdoorUrl: responseData.frontdoor_uri};
24  } catch (error) {
25    // eslint-disable-next-line no-console
26    console.error('Error in getFrontdoorUrl:', error);
27    return {error: error.message || 'Failed to generate frontdoor URL'};
28  }
29};

For information on how to use the UI Bridge API to generate frontdoor URLs, see Generate a frontdoor URL to Bridge into UI Sessions.

Authentication Management 

  • Don’t hardcode OAuth tokens or frontdoor URLs in your client-side code.
  • Pass credentials to the browser only when strictly necessary. Credentials can be scrapped from the browser by malicious actors.

See Also 

Get Your Employee Agent ID