GoogleAuthProvider and Google APIs

5 views
Skip to first unread message

Mario Aleo

unread,
6:23 PM (5 hours ago) 6:23 PM
to Firebase Google Group
I'm using the Google Calendar API to access the user calendar and schedule appointments, but I'm having issues when the access token expires.

Using the signInWithRedirect with GoogleAuthProvider with addScope('https://www.googleapis.com/auth/calendar') and setCustomParameters({
 addDoc: 'https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest',
 }) I can get the access token on getRedirectResult using the GoogleAuthProvider.credentialFromResult, with this access token I'm able to do a gapi.client.setToken and have access to the user's calendar without any issue.

The problem is, I'm using the getIdToken method to retrieve a new access token on both onIdTokenChanged and onAuthStateChanged (outside the getRedirectResult case) to set the new gapi token using the  gapi.client.setToken, when the token is retrieved from this getIdToken method, the Google Calendar API returns a: "401 Unauthorized" with the message:  "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential."
Using the gapi.client.getToken() I can see that the access token is set and when I inspect the  Google Calendar API request I can confirm that the token has been passed as Authorization: Bearer.

I would appreciate it if someone could help me solve this issue.
Reply all
Reply to author
Forward
0 new messages