0

I'm attempting to use Google's Developer API Identity Services.

I'm following along with this guide: https://developers.google.com/identity/oauth2/web/guides/use-token-model

I've already created an app in the google cloud console and also created an OAuth Client ID that has my domain name in the authorized Javascript origins. (Like this: "https://hiddenurl.dev"). I've added the the client id to the initTokenClient method where the guide specifies.

I'm able to construct the token client object with the initTokenClient method successfully.

My problem occurs when I try to activate the requestAccessToken method on the token client after clicking on a button. The method successfully opens a popup containing that requests the appropriate scope permissions for the correct application. However, it does execute the callback function.

I've added an error_callback method in the constructor (as described by the API reference here: https://developers.google.com/identity/oauth2/web/reference/js-reference#google.accounts.oauth2.initTokenClient This callback provides me with the following details from the error object:

{
    message: "Popup window closed",
    stack: "Error: Popup window closed
        at new Wq (https://accounts.google.com/gsi/client:269:337)
        at zs.C (https://accounts.google.com/gsi/client:333:288)
        at mf (https://accounts.google.com/gsi/client:170:193)
        at _.l.dispatchEvent (https://accounts.google.com/gsi/client:168:346)
        at _.rf.F (https://accounts.google.com/gsi/client:170:793)",
    type: "popup_closed"
}

This error_callback is triggered immediately after clicking the button that triggers the requestAccessToken method. The strange thing being that the popup window is not closed.

What am I missing? Not sure what steps to look into further to debug this issue.

The requestAccessToken method should not return immediately and should instead perform the regular callback after completing the popup UX.

I tried experimenting with a variety of different scopes and authorized origin url patterns in the Oauth client id (i.e. https://hiddenurl.dev:443, https://www.hiddenurl.dev, https://hiddenurl.dev/myapp)

1
  • Can you include some sample code on how you call requestAccessToken method? Sometimes, the issue is due to browser blocking the popup.
    – hermz
    Commented Aug 3 at 20:48

0