No refresh_token in SalesForce OAuth Response
Asked Answered
K

2

8

I'm interacting with a custom APEX service which obviously require OAuth authentication. I can easily authenticate and authorise my application. Everything works fine.

However, the access token I receive tends to expire.

Of course, I can refresh it by sending a refresh_token. Sounds great.

The problem is I don't receieve a refresh_token in a response from SalesForce.

I do send requests to [instance].salesforce.com/services/oauth2/token, I also tried to using login.salesforce.com/services/oauth2/token, but I cannot find 'refresh_token' in the response. There's everything apart from it there!..

Keefe answered 13/6, 2012 at 22:42 Comment(2)
which oauth flow are you using? what's your callback uri ?Winna
@Winna Everything was correct, apart from the scope. See my answer below. Thanks anyway :)!Keefe
K
4

I've solved the problem thanks to my wonderful colleague.

I should have added 'refresh_token' to the scope when retrieiving an auth code.

Keefe answered 14/6, 2012 at 0:29 Comment(2)
Actually, refresh_tokens aren't (or are no longer) handed out unless you're building a mobile app or In-SalesForce app. See wiki.developerforce.com/page/… and search for "Note that refresh_token is only sent if either of the following is the case". I found this out after 4 hours of trying to figure out why it wasn't giving me one. :) I'm happy to be proven wrong, though..Wimbush
Did you ever get this to work? I'm not getting a refresh token despite the scope settings.Boddie
S
12

Please check Selected OAuth Scopes section, which is needed to be enabled Perform requests on your behalf at any time in order to get the refresh token.

Сreate > Apps > API (Enable OAuth Settings) > Selected OAuth Scopes.

Spinning answered 26/10, 2015 at 13:10 Comment(2)
I'm not sure why "Full access (full)" scope is not enough ... but it's not. You also have to do the above. Thanks so much.Distrustful
Note that, by default, the refresh token will expire immediately. You have to go into "Manage Connected Apps", edit your app, and change the setting for refresh token expiry, otherwise you get "token validity expired" when you try to refresh it. 😶Birch
K
4

I've solved the problem thanks to my wonderful colleague.

I should have added 'refresh_token' to the scope when retrieiving an auth code.

Keefe answered 14/6, 2012 at 0:29 Comment(2)
Actually, refresh_tokens aren't (or are no longer) handed out unless you're building a mobile app or In-SalesForce app. See wiki.developerforce.com/page/… and search for "Note that refresh_token is only sent if either of the following is the case". I found this out after 4 hours of trying to figure out why it wasn't giving me one. :) I'm happy to be proven wrong, though..Wimbush
Did you ever get this to work? I'm not getting a refresh token despite the scope settings.Boddie

© 2022 - 2024 — McMap. All rights reserved.