Refresh Token, Resource Owner not getting sent back
dougblackjr opened this issue · comments
I am calling the OAuth function and getting a successful access token. However, when using the ->getRefreshToken()
function, I am not getting anything back and it is coming back null.
Controller function
if($code = request()->get('code')) {
try {
// Try to get an access token using the authorization code grant.
// We have an access token, which we may use in authenticated
// requests against the service provider's API.
// 'Access Token: ' . $accessToken->getToken()
// 'Refresh Token: ' . $accessToken->getRefreshToken()
// 'Expired in: ' . $accessToken->getExpires()
// 'Already expired? ' . $accessToken->hasExpired()
$accessToken = $this->provider->getAccessToken(
'authorization_code',
[
'code' => request()->get('code'),
]
);
$resourceOwner = $this->provider->getResourceOwner($accessToken);
$data = [
'access_token' => $accessToken->getToken(),
'refresh_token' => $accessToken->getRefreshToken(),
'expires' => Carbon::parse($accessToken->getExpires()),
'resource_owner' => json_encode($resourceOwner),
'data' => [
'instance_url' => $accessToken->getInstanceUrl(),
]
];
$userResource = UserResource::updateOrCreate(
[
'type' => 'salesforce',
'user_id' => Auth::id(),
],
$data
);
event(new AccessTokenAdded($userResource));
return redirect(config('salesforce.redirect_url') . '?success=true');
} catch (IdentityProviderException|ErrorException|Exception $e) {
// Failed to get the access token or user details.
$message = json_encode([
$e->getMessage(),
]);
return redirect(config('salesforce.redirect_url') . '?success=false');
}
} else {
$loginUrl = 'https://login.salesforce.com/services/oauth2/authorize'
. '?response_type=code&client_id=' . config('salesforce.client_id')
. '&redirect_uri=' . config('salesforce.callback_url');
return redirect($loginUrl);
}
The response data ($data
variable in example above) looks like this:
{
"access_token": "reallylongtoken",
"refresh_token": null,
"expires": "2020-12-15T12:21:57.060855Z",
"resource_owner": "{}",
"data": {
"instance_url": "https://mycustomdomain.my.salesforce.com"
}
}