'google oauth login error Insufficient Permission
While implementing Google oauth login, there was a problem in retrieving user information.
// socialLoginController.js
const { code } = req.query;
const baseUrl = 'https://www.googleapis.com/oauth2/v4/token';
const urlConfig = {
client_id: process.env.GOOGLE_CLIENT_ID,
client_secret: process.env.GOOGLE_CLIENT_SECRET,
code,
grant_type: 'authorization_code',
redirect_uri: 'http://localhost:4000/users/google/oauth',
};
const finalUrl = combineUrlAndParams(baseUrl, urlConfig);
console.log(finalUrl);
const tokenRequest = await (
await fetch(finalUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
})
).json();
if ('access_token' in tokenRequest) {
const { access_token } = tokenRequest;
const userRequest = await (
await fetch('https://www.googleapis.com/drive/v2/files', {
headers: {
Authorization: `Bearer ${access_token}`,
},
})
).json();
console.log(userRequest);
At this time, when I checked the userRequest log, the following error appeared.
{
error: {
errors: [ [Object] ],
code: 403,
message: 'Insufficient Permission: Request had insufficient authentication scopes.'
}
}
It seems to be a scope problem, so I tried setting the scope to openid, profile, email, or not registering the scope at all, etc., but I keep getting the above error. I don't know what the hell is the problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
