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.

Sometimes getAuthResponse returned access_token to undefined.

See original GitHub issue

hi.

Sometimes access_token is not defined after logging in.

So I debugged and found that function getAuthResponse, which is used in the library, was returning undefined.

The official document states that access_token is not returned when:

By default, the access token and requested scopes are not returned when fetched_basic_profile is true (the default value) and no additional scopes are required.

I have to specify fetched_basic_profile as true, and scope as profile email. The default value for this library is the same as the value I should use, so I didn’t specify it in the code.

I am using the login component as below.

  <GoogleLogin
      render={LoginButton}
      clientId={googleClientId}
      onRequest={onGoogleLoginRequest}
      onSuccess={onGoogleLoginSuccess}
      onFailure={onGoogleLoginFailure}
      cookiePolicy=“single_host_origin”
    />

To solve this problem, I would like to modify the parameter of function getAuthResponse.

Or is there another better solution?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

6reactions
NevenLiangcommented, Jun 13, 2020

@Sultanyaron As the README and GoogleUser object said, You should add true as a parameter to getAuthResponse().

// You can always get the `access_token` in this way
res.getAuthResponse(true).access_token;  
1reaction
Sultanyaroncommented, Jun 23, 2020

@phanshiwen It is working properly and i am getting the token with the following:

       //@ts-ignore
	const googleAccessToken = loginResponse.getAuthResponse(true).access_token;

According to the definition file getAuthResponse don’t accept args, this is something that need to get fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

gapi.auth2 can not get access_token - Stack Overflow
access_token and g-signin . So I've been trying to use the auth2 functions to get the access tokens, but the access_token property is...
Read more >
getTokenSilently returns undefined token for lots of concurrent ...
I have an API utility making all my requests from my fronted React app. It calls getTokenSilently each time I make an API...
Read more >
Migrate to Google Identity Services | Authorization
Access tokens are short-lived, and often valid only for a few minutes. ... After consent, an access token is returned along with a...
Read more >
"Failed to obtain access token" callback message when ...
Occasionally I am getting below and mostly Failed to Obtain access token. BadRequest-Cannot read property 'idp' of undefined.
Read more >
Client API - NextAuth.js
The session data returned to the client does not contain sensitive ... when the session hasn't been fetched yet, data will be undefined...
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