10

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.

Community
  • 1
  • 1
Valarpirai
  • 465
  • 3
  • 14

3 Answers3

2

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

Valarpirai
  • 465
  • 3
  • 14
0

Try changing the first line to:

OAuth.popup("google", {
  'authorize' : {
    "approval_prompt" : "force",
    "access_type" : "offline"}})

Google's docs describe how offline refresh tokens work.

Jay Lee
  • 13,415
  • 3
  • 28
  • 59
  • I tried with access_type :"offline", refresh_token is not received in the response. – Valarpirai Jul 08 '15 at 05:35
  • Can you try running through an OAuth request with Firebug or Chrome Dev Tools to see exactly what URL OAuth.io is hitting? – Jay Lee Jul 08 '15 at 11:20
  • https://oauth.io/auth/google?k=ndXMRv8xxxxxx&d=http://localhost/&opts={"authorize":{"approval_prompt":"force","access_type":"offline"},"state":"nBGE8Rv1ufxxxxxxxx","state_type":"client"} This is the(decoded) URL Oauth.io JS using to open popup window – Valarpirai Jul 09 '15 at 06:33
-1
  1. Go Account Security Settings and click edit
  2. https://www.google.com/settings/u/1/security.
  3. next to "Authorizing applications and sites". Then click "Revoke
  4. Access" next to your app. The next OAuth2 request you make will
  5. return a refresh_token.

You can also play with Open Oauth Here

Mehmet Eren Yener
  • 2,006
  • 1
  • 23
  • 37