Skip to main content

OAuth 2.0 Refresh Token Flow for Renewed Sessions

Welcome to catchontosalesforce! 

Description :

We used to renew access tokens issued by OAuth 2.0 web server flow or the OAuth 2.0 user-agent flow.

For refresh access token, It's used to reduce subsequent credential login in Authorization Code and Credentials Flow for Public/ Private Clients. we just use refresh token to renew access token whenever access token is expired. 

API Details :

HTTP Endpoint

<Your Experience Site URL>+'/services/oauth2/token'

HTTP Method

POST

HTTP Header

Authorization

'BASIC ' +EncodingUtil.base64Encode(Blob.valueOf(<ClientId> : <ClientSecret>))

grant_type

refresh_token

refresh_token

<Refresh_Token>


Example,
In Client custom app, we ask key-in username and password to authorize user and get access token to access salesforce protected data. If you skip subsequence user login/authorization, the OAuth 2.0 Refresh token policy will help you.

Apex :
HttpRequest req = new HttpRequest();
req.setEndpoint(<Your Experience Site URL>+'/services/oauth2/token');
req.setMethod('POST');          
Blob headerValue = Blob.valueOf(<ClientId> + ':' + <ClientSecret>);
req.setHeader('Authorization', 'BASIC ' +EncodingUtil.base64Encode(headerValue));
req.setHeader('grant_type', 'refresh_token');
req.setHeader('refresh_token', <Refresh_Token>);
Http http = new Http();
HttpResponse res = http.send(req);
System.debug(res.getbody());


Thanks
Priyananth


Comments

Popular posts from this blog

Authorization Code and Credentials Flow for Private Clients

I have created a sample javascript app with functionality of Authorization Code and Credentials Flow for Private Clients.  Just visit Blogshot:   https://www.catchontosalesforce.com/p /authorization-code-and-credentials-flow.html   Github : https://github.com/Priyananth-Salesforce/Headless-SF-Authenication--Login-Via-Javascript-App

HTTP POST via Lightning Flow

 I have done account sync between Salesforce (Source) to salesforce (Destination) using Lightning flow. Just visit Blog:  https://www.catchontosalesforce.com/p/http-post-via-lightning-flow.html