Google Oauth popup cancellation callback

Viewed 382

When using Google Identity Services (GSI) I can display a popup to ask users to connect with their Google account. This is pretty well documented and it works well with this code:

const client = window.google.accounts.oauth2.initCodeClient({
  client_id: 'CLIENT_ID',
  scope: 'SCOPE',
  ux_mode: 'popup',
  callback: async (response) => {
    console.log('Response Google', response);
  },
});
client.requestCode();

However, I wish to do something if the user close the popup. I can't find anything in the documentation and in examples online. I tried intermediate_iframe_close_callback and native_callback, but neither are called when closing the popup.

So, is it possible ? How can I do it ?

Thanks

1 Answers

It appears that this is not working for the current version of GSI.

It did work for the old gapi version and if the popup were to be closed you would get a response with the error: {error: "popup_closed_by_user"}. As referenced in this answer: Google SSO login error: "popup_closed_by_user"

Hopefully adding the #google-oauth tag will allow someone at Google to see this and hopefully update this script.

Related