this my post request
app.post('/auth/google', async (req, res) => {
try {
const {
code
} = req.body;
} catch (error) {
}
});
i’m getting the token from my front end
4/0AbUR2VMmkydX1bHZeUIq6xm8558a8EyxdNhc0q2ouILfp2Cc3gL3mSd3w83Qn6JJ4jaqdg
please how can i verify the code and get the user details using google-auth-library
const verifyGoogleAccessToken = async (accessToken) => {
oauth2Client.setCredentials({
access_token: accessToken
});
const userinfo = await oauth2Client.request({
url: "https://www.googleapis.com/oauth2/v3/userinfo",
});
return userinfo.data;
};
please i need help,i’ve been on this for days
2
Answers
Retrieve access token via authorization code. After setting the credentials for
oauth2Client
, there are two choices to get the user info:googleapis
libraryoauth2Client.request({url: 'https://www.googleapis.com/oauth2/v3/userinfo'})
A working example:
Server logs:
package versions: