PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, August 6, 2022

[FIXED] How can i get a Refresh token using the Salesforce OAuth?

 August 06, 2022     oauth, salesforce     No comments   

Issue

When i first authenticate with OAuth to Salesforce i dont get back a refresh token , i just get back an access token. So if the token needs to be refreshed by using the following:

var client = new RestClient("https://myOrg.salesforce.com/services/oauth2/token");
var request = new RestRequest("", Method.POST);
request.AddParameter("refresh_token", {currentRefreshToken}, ParameterType.GetOrPost);
request.AddParameter("grant_type", "refresh_token", ParameterType.GetOrPost);
request.AddParameter("client_id", {clientId}, ParameterType.GetOrPost);
request.AddParameter("client_secret", {clientsecret}, ParameterType.GetOrPost);
var response = client.Execute(request);

The currentRefreshToken is NULL because i didnt receive any refresh token on the initial authentication response. The initial call to authenticate is

    https://login.salesforce.com/services/oauth2/authorize? client_id={consumer_key}& 
    redirect_uri={callback_url}& response_type=code

and this doesnt give back a refreshtoken. How can i get an initial refresh token ?


Solution

The connected app has to allow issuing refresh tokens (check if "scopes" contains refresh and if there isn't something like "immediately expire refresh tokens" set).

And then you need to ask for it, add optional scope=refresh_token parameter to your request.

https://help.salesforce.com/s/articleView?id=sf.remoteaccess_oauth_user_agent_flow.htm&type=5



Answered By - eyescream
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing