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.

Cannot retrieve access_token (updated)

See original GitHub issue

Hi, when I use web, the answer comes in the format: { id: string; email: string; name: string; familyName: string; givenName: string; imageUrl: string; serverAuthCode: string; authentication: { accessToken: string; idToken: string; }; }

and I can get accessToken, but when I use this implementation on android, the answer comes in a different format: { id: string; email: string; name: string; familyName: string; givenName: string; imageUrl: string; idToken: string; serverAuthCode: string; authentication: { idToken: string; }; } we get idToken 2 times and there is no accessToken field. How do I get accessToken? Maybe there is another way

Thank you, Alexandr

_Originally posted by @Alexandr-Pivovar in https://github.com/CodetrixStudio/CapacitorGoogleAuth/issues/32#issuecomment-638057611_

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13

github_iconTop GitHub Comments

2reactions
Niravpatel129commented, Aug 18, 2020

any solution? 😦

Hi @mghcs87 , sorry for the slow reply. I managed to take care of serverAuthCode on backend and it works just fine. I simply exchange it for access_token. Unfortunately I didn’t find the solution for access_code on android, but now I don’t feel the need to do it. My Ionic code looks similar to:

import '@codetrix-studio/capacitor-google-auth';
import { Plugins } from '@capacitor/core';
// ...
const GoogleUser = await Plugins.GoogleAuth.signIn();
server_auth_code = GoogleUser.serverAuthCode;

// then I pass this code to backend.

And backend python code:

def get_token_from_gapi(code):
    """Exchange serverAuthCode for access_token"""
    data = {
        "code": code,
        "client_id": CLIENT_ID,
        "client_secret": CLIENT_SECRET,
        "grant_type": "authorization_code",
    }
    r = requests.post("https://oauth2.googleapis.com/token", data=data)
    if r.status_code < 200 or r.status_code >= 300:
        raise HTTPError("Authorization using serverAuthCode failed.")
    token = r.json()["access_token"]
    return token

Please note that CLIENT_ID and CLIENT_SECRET are your credentials for web application, not for android (since this happens on backend). Good luck 🔥

I’m making the same call as you through postman and on my local client, I seem to be getting this error:

{
  "error": "invalid_grant",
  "error_description": "Bad Request"
}

I think that it could be the token being invalid, is there any setting you changed for your client to allow this API call to go through?

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot retrieve access token for oauth2 - Stack Overflow
The way Oauth2 works is that it needs to know where to return the authentication to. This is done by defining a Redirect...
Read more >
Can't get token with update:users scope - Auth0 Community
1 - I have two registered account. One of is email account without social. I m getting it's access token via https://domain_name/oauth/token ......
Read more >
Troubleshooting OAuth App access token request errors
To solve this error, make sure you have the correct credentials for your OAuth App. Double check the client_id and client_secret to make...
Read more >
Your migration failed checking Source credentials. Cannot ...
Cannot retrieve access token. Answer: This error occurs when the access token has expired. Perform the following actions to generate a new ...
Read more >
Cannot get Access Token - Google Groups
A few things I see: (1) your Authorization header is missing the client secret. If you don't have a secret (i.e., aren't requesting...
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