question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't retrieve token with code when using one-time code flow.

See original GitHub issue
    var code = req.body.code;
    var oauth2Client = new gapis.OAuth2Client(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL);
    oauth2Client.getToken(code, function(err, tokens) {
        oauth2Client.setCredentials(tokens);
        callback.call();
    });

I’m sure of that all the three parameters of new OAuth2Client() are correct, but still got a redirect_uri_mismatch error.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
mhaagenscommented, Oct 30, 2018

How awesome that this is undocumented.

1reaction
jongminjangcommented, May 9, 2014

if you want to use one-time code flow, the login button should look like following. <span id="login" class="g-signin" data-height="short" data-callback="loginToGoogle" data-cookiepolicy="single_host_origin" data-scope="https://www.googleapis.com/auth/userinfo.email" data-clientid="this attribute is set by javascript :)" data-accesstype="offline" data-redirecturi="postmessages">

see data-accesstype and data-redirectuir attributes.

and in your node source, you must create oauth2client like this. var oauth2Client = new googleapis.OAuth2Client( gooClientId, gooClientSecret, ‘postmessage’);

redirect uri argument must be ‘postmessage’ which is undocumented.

oauth2client.getToken(token, function(err, token) { oauth2client.setCredentials(token); //now works. });

hope this helpful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Call Your API Using the Authorization Code Flow - Auth0
This tutorial will help you call your own API using the Authorization Code Flow. If you want to learn how the flow works...
Read more >
ruby - Rails 4 - Google One Time Code Flow with omniauth ...
Refresh Token used to get a new access token when it expires. good until the user removes access. Authorization code. This is the...
Read more >
How to get an access token with Auth Code Grant | DocuSign
This topic demonstrates how to manually generate an access token using Authorization Code Grant authentication or with a refresh token. In the Authorization ......
Read more >
Getting error while getting access token using OAuth 2.0 ...
Getting error while getting access token using OAuth 2.0 device code flow. I am trying to get access token via OAuth 2.0 device ......
Read more >
The Authorization Code grant (in excruciating detail) Part 2 of 2
This is one time use. The code is sent in the URL of a redirect. What is the target redirect URL? It is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found