Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting refresh tokens from Google with OAuth.io JS SDK (Client side)

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.

like image 695
Valarpirai Avatar asked Jul 01 '15 06:07

Valarpirai


People also ask

How do I refresh OAuth access token?

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.

Where is Google refresh token stored?

The Refresh Tokens will be available in the identities array, under the element for the particular connection.


1 Answers

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);
                });

enter image description here

like image 196
Valarpirai Avatar answered Oct 17 '22 21:10

Valarpirai