Step 2: Generate an Access Token
-
From Setup, in the Quick Find box, enter
External Client App Manager, and then select the app you created. -
Click the Settings tab, and go to the OAuth Settings section.
-
Click Consumer Key and Secret. A browser tab opens up for entering the verification code.
-
In the new browser tab, verify your identity with the verification code sent to the email address of your Salesforce account.
-
Copy the consumer key.
-
Generate the Signed JSON Web Token. You can use your preferred method, such as JWT.io to generate a signed JWT.
-
JWT Header: Set
algto the RS256 hash algorithm. -
JWT Payload: Set these claims:
iss: The consumer key of the connected app.sub: The username of the Salesforce user account. You can click the Salesforce profile icon at top-right, and then click Settings, to find the username.aud: The instance login URL. For example, for falcon environment, usehttps://login.test1.pc-rnd.salesforce.com/, and for local environment usehttps://localhost:6101/.exp: The expiry date and time of the token in milliseconds since the Unix epoch. You can use an Epoch Converter available online to generate this value.
-
Signature: Add public and private keys in PEM format, including the respective headers and footers from the
server.crtandserver.keyfiles. Copy the verified signature.
-
-
Generate the access token.
To generate the access token, use a cURL command that includes the signed JWT and the OAuth authorization endpoint (
OAUTH_AUTH_ENDPOINT), which is typically your instance URL followed by/services/oauth2/token(https://login.salesforce.com/services/oauth2/tokenorhttps://login.test1.pc-rnd.salesforce.com/services/oauth2/tokenfor test1 environments).
The OAUTH_AUTH_ENDPOINT value should match the aud (audience) value in your JWT.
Also, instead of using login.salesforce.com, you can use the My Domain, Experience Cloud site, or test.salesforce.com (sandbox) domain in these endpoints. For hostname, use the My Domain, Experience Cloud site, or custom URL. All endpoints require secure HTTP (HTTPS).
In the cURL command, replace OAUTH_AUTH_ENDPOINT with the appropriate URL and JWT with the verified signature you obtained from JWT.io. Use your terminal to execute the command to generate the access token.
The resulting token is in the {orgId}!{token} format. Share this with your customers as the bearer token.
After you generate the access token, create a platform event and assign permissions.