I am trying to get access token & refresh token using OAuth.io for Google provider. I have chosen offline for the access_type in OAuth.io.
Following is the code
OAuth.popup("google", {'authorize' : { "approval_prompt" : 'force'}})
.done(function(result) {
console.log(result);
})
.fail(function (err) {
//handle error with err
console.log(err);
});
I am not receiving refresh_token in the response. I am getting only access_token from response.
JSON response for access token is:
{
"status": "success",
"data": {
"access_token": "ya29.pAGQWe3yxxxxxx",
"token_type": "Bearer",
"expires_in": 3600,
"request": {
"url": "https://www.googleapis.com",
"headers": {
"Authorization": "Bearer {{token}}"
}
},
"id_token": "eyJhbGciOiJSUzIxxxxxxxx"
},
"state": "Q9nfocQXJxxxx",
"provider": "google"
}
Reference
I have found this SO link Getting refresh tokens from Google with OAuth.io Here they have explained how to get refresh token in server side.
I want to get refresh token in client side JS.
To use the refresh token, make a POST request to the service's token endpoint with grant_type=refresh_token , and include the refresh token as well as the client credentials if required.
The Refresh Tokens will be available in the identities array, under the element for the particular connection.
Goto OAuth.io app general settings page, select Show advanced options and then select Send refresh token to front-end.
In the integrated APIs, select the access_type as offline. This will send the refresh token to front end while using the following code
var oauthOptions = { 'authorize' : { "approval_prompt" : "force" } };
OAuth.popup("google", oauthOptions)
.done(function(result) {
console.log("Post postProcessing");
console.log(result);
})
.fail(function (err) {
console.log(err);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With