After obtaining authorization token:
const tokenClient = google.accounts.oauth2.initTokenClient({
client_id, scope, callback,
});
// ...
tokenClient.requestAccessToken({ prompt: ''})
I need to obtain authorization code and send it to backend:
let code;
const codeClient = google.accounts.oauth2.initCodeClient({
scope, client_id,
callback: codeResponse => code = codeResponse.code,
});
codeClient.requestCode();
Despite the user has authorized once, and gapi.client.getToken() is not null the popup window appears another time.
Is there any solution to avoid redundant user authorization?
Most likely it's because user's consent on obtaining token (initTokenClient) does not automatically mean consent on obtaining authorization code (initCodeClient).
You can obtain authorization code and translate it to a token in backend which could be then used in frontend as gapi.client.setToken(token) if the scope matches.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With