Reputation: 1
I want to get access_token from google oauth2 to use it to create google spreadsheet. I found below code but I want to get New token not referesh
async function getNewToken(refreshToken) {
return await fetch('https://oauth2.googleapis.com/token', {
method: 'post',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
client_id: '<MY_CLIENT_ID>',
client_secret: '<MY_CLIENT_SECRET>',
refresh_token: refreshToken,
grant_type: 'refresh_token',
}),
});
}
Upvotes: 0
Views: 82
Reputation: 1197
You cannot, user has to login, what will return CODE. This CODE you can exchange for access token. https://developers.google.com/identity/protocols/oauth2/web-server#httprest
Generally: a code will start authentication on client (browser), this will open classic Google authentication and authorization. It`s result is CODE, that you send to backend and exchange with Google for the access token.
Upvotes: 1