'how to verify google sign in chrome extension using launchWebAuthFlow on nodejs server
I want to signin using google to my server in chrome extension. So I am using launchWebAuthFlow
in background.js. Here is the code
function showAuthDialog(url, sendResponse) {
try {
chrome.identity.launchWebAuthFlow(
{
url: url,
interactive: true,
},
// returns promise only if authorization is successfull
function (redirectUrl) {
// URL will include a parameter that either is an access token or can be exchanged for an access token
if (redirectUrl) {
sendResponse({ data: { redirectUrl } });
} else {
sendResponse({ err: "Something went wrong." });
}
}
);
}
catch (err) {
alert("Something went wrong");
}
}
and
showAuthDialog(identityUrl, sendResponse);
identityUrl = getGoogleAuthEndpoint();
and here is getGoogleAuthEndpoint
function getGoogleAuthEndpoint() {
const nonce = encodeURIComponent(
Math.random().toString(36).substring(2, 15) +
Math.random().toString(36).substring(2, 15)
);
const googleOpenIdEndpointUrl =
`https://accounts.google.com/o/oauth2/v2/auth?client_id=${googleLoginInfo.clientId}` +
`&response_type=id_token&redirect_uri=https://${config.chromeAppId}.chromiumapp.org` +
`&state=dxchgv&scope=openid email profile&prompt=consent&nonce=${nonce}`;
return googleOpenIdEndpointUrl;
}
now this will return redirectUrl
from which i can extract the email
and name
with this user I want to login/signup on my own nodejs server. So i can call my nodejs login api call with name/email
but by this mean users can login with just email
only and get JWT token.
Is there any other way that i can verify on my node server that this email is coming from authenticated flow?
I read on this that google will return u the code that you can verify on server and get user info on server, but with launchWebAuthFlow
, I am not getting any code?
Any help? or the way to achieve the same?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|