'Salesforce OAuth User Agent Flow: obtain refresh token with

I am developing 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 the request I use:

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" as redirect uri 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



Solution 1:[1]

Try adding Perform requests at any time (refresh_token, offline_access) under Selected OAuth Scopes in your connected app

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 redparrot