function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Marco MaddionaMarco Maddiona 

Obtain refresh token with User Agent Flow

I have developed a web application that allows any user to connect with its salesforce account. I've implemented User Agent Flow and I obtain correctly access_token and other info but I can't obtain refresh_token, even if I have the correct scopes (api, web, refresh_token, offline_access).

This is my request:

https://login.salesforce.com/services/oauth2/authorize?response_type=token&scope=refresh_token&client_id=[MY_CLIENT_ID]&redirect_uri=[MY_REDIRECT_URL]

And my redirect URL is: 

http://[MYSITE].com/#/services/oauth2/success

(that corresponds to the host from where I make the call)


This call correctly gives me access_token but not refresh_token.

if I use "https" instead "http" I receive this error:
error=invalid_scope&error_description=the requested scope is not available

From the documentation, I read that 

"The refresh token for the user-agent flow is only issued if you requested scope=refresh_token and one of the following scenarios is true:

....

- The redirect URL host matches the request host and includes the servlet services/oauth2/success.

..."

I think to be in this case, what am I doing wrong?

Thanks in advance

 

AnkaiahAnkaiah (Salesforce Developers) 
Hi Marco,

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

Thanks!!
Marco MaddionaMarco Maddiona

Thank you Ankaiah for your response. 

I know that article and I've followed it to implement the OAuth User Agent Flow. I think I've done all the correct steps, but I can't obtain the refresh_token anyway.
Is there something wrong with the procedure that I have described in my question?

Marco MaddionaMarco Maddiona
Any other suggestions? Still stuck here