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.

Missing accessToken on native device

See original GitHub issue

const user = await GoogleAuth.signIn();

Ionic 5 Capacitor 3

If I testing this on web all working fine, but if I am on native device (in my case android) user.authentication object has missing accessToken field. There is only idToken

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
jeqchocommented, Aug 30, 2021

Thanks to the steps from @Mersal-Mohamed, the following code solves the problem

const googleUser = await GoogleAuth.signIn();
let accessToken = googleUser.authentication.accessToken;
if (!accessToken) {
    const body = {
      client_id: YOUR_CLIENT_ID,
      client_secret: YOUR_CLIENT_SECRET,
      code: googleUser.serverAuthCode,
      grant_type: 'authorization_code',
      redirect_uri: 'urn:ietf:wg:oauth:2.0:oob'
    };
    const authResponse = await this.http.post('https://oauth2.googleapis.com/token', body).toPromise();
    accessToken = authResponse['access_token'];
}

From the guide, redirect_uri must be set like that for “installed apps”. Use firstValueFrom if toPromise is deprecated.

1reaction
Mersal-Mohamedcommented, Jul 14, 2021

google has an end point which return access_token if you give it serverAuthCode

you can get server auth code through the ordinary request which you made by await GoogleAuth.signIn().

this is the end point link https://oauth2.googleapis.com/token

it’s post request which should have this body const body = client_id=yourclientid&client_secret=yourclientsecret&code=serverAuthCode&grant_type=authorization_code&redirect_uri=${redirect_uri};

redirect uri you can get it through these steps : go to https://console.cloud.google.com/ open your project credentials page click on android which under OAuth 2.0 Client IDs download json from android client page you will find redirect uri inside it

response of this request contain ACCESS_TOKEN which you could use it in your sign in process

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native, unable to get access token - Stack Overflow
I'm using react-native-app-auth to get access token from azure ad b2c but I'm facing issues in android and in IOS in android it's...
Read more >
Retrieve an Access Token and Refresh Token
The Device Token Request implements section 3.4 of the OAuth 2.0 Device Flow ... the error {"error_description":"The request is missing a required parameter...
Read more >
Unable to login due to missing access token parameter for ...
The app is on the SF Mobile SDK 9.2.1 and it is only happening on iOS. The odd thing is that it seems...
Read more >
OAuth 2.0 for Mobile & Desktop Apps - Google Developers
Obtaining OAuth 2.0 access tokens ... Installed apps are distributed to individual devices, and it is assumed that these apps cannot keep ...
Read more >
Get access token with no human interaction - Cisco Community
1. You can create an Integration which will then allow you to create an OAuth Access token. There is a mandatory requirement to...
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