Access Tokens
Last updated
Last updated
In order to access Salesforce from an external application, an access token must be requested from Salesforce.
The first step in configuring Salesforce to generate access tokens is to create a connected app in Salesforce. The connected app will contain the security settings for issuing tokens to the custom application.
Visit Creating a Connected App in Salesforce for details.
Once the connected app is configured, access tokens can be requested from Salesforce using the connected app's configuration details.
To create an access token, a post request is sent to the following end point.
One or more of the following data is posted in the request based on application requirements.
Property | Description |
---|---|
An access token returned from Salesforce has the following properties.
For more details on Salesforce access tokens, visit Get an Access Token from Salesforce.
For details on how to use these settings with WireBootstrap, visit Data Connector.
All the material discussed in this section has been implemented in the sample application that comes with the WireBootstrap for Salesforce. This sample is a good example of how to generate tokens in order to access Salesforce data from external applications.
In the project, the TokensController
class at \Controllers\TokensController.cs
contains a method called GetAccessToken
that can be called by clients to retrieve a token from Salesforce.
The following in an excerpt from the call to this method from \lib\service.js
in the sample.
On the server, GetAccessToken
reads the values for the token request from appsettings.json
, makes the call to Salesforce, and returns the token to the client.
Below is an excerpt from appsettings.json
with the variables needed for the call to generate a token. Replace the brackets []
with the actual values needed to connect to your Salesforce connected app.
Property | Example | Description |
---|---|---|
client_id
The connected app's unique identifier
client_secret
The secret for the API registered in the application with permission to access the Salesforce API
username
Optional. Used only with the password
grant type.
password
Optional. Used only with the password
grant type.
grant_type
The authentication flow used to generate the access token.
access_token
eyJ0e...Agjmg
This is the actual token used for authenticating calls to Salesforce.
instance_url
https://domain-dev-my.salesforce.com
This is the REST API endpoint to use for making calls to Salesforce.
token_type
Bearer
This is the OAuth 2.0 token type in access_token
.