Since this is the first time front-end development experience, I need put google calendar on my web app, but Google OAuth didn’t give me the refresh_token
to do CRUD on calendar
I knew the Google OAuth process is:
- Send request url to Google OAuth server
- Google prompts user for consent
- Get OAuth server response which looks like:
{
'access_token':...,
'expires_in':...,
'scope':...,
...,
'refresh_token:,
}
I’ve asked chatgpt that need set access_type='offline'
and prompt: 'consent'
, but that didn’t work.
The partial code is below:
function gisLoaded() {
tokenClient = google.accounts.oauth2.initTokenClient({
client_id: CLIENT_ID,
scope: SCOPES,
callback: '', // defined later
access_type: 'offline',
prompt: 'consent'
});
gisInited = true;
maybeEnableButtons();
}
function maybeEnableButtons() {
if (gapiInited && gisInited) {
// Enable the authorize button here
}
}
function handleAuthClick() {
tokenClient.callback = async (resp) => {
if (resp.error !== undefined) {
throw (resp);
}
setIsAuthorized(true);
setAuthToken(gapi.client.getToken().access_token); // Save the token
await createNewCalendar();
};
if (gapi.client.getToken() === null) {
tokenClient.requestAccessToken({ prompt: 'consent' });
} else {
tokenClient.requestAccessToken({ prompt: '' });
}
}
The response from Google, which lacks the refresh_token
:
Can anyone help me?
Any help is greatly appreciated! Thanks