const onLogin = () => {
const nonce = uuid();
window.localStorage.set("nonce", nonce);
window.location.href = `https://accounts.google.com/o/oauth2/v2/auth?` +
`identity_provider=Google&` +
`redirect_uri=${process.env.WEB_DOMAIN}/auth/link/google&` +
"response_type=id_token token&" +
`client_id=${process.env.CLIENT_ID}&` +
"scope=email openid profile&" +
`nonce=${nonce}`,
}
const parsedHash = new URLSearchParams(window.location.hash.substring(1));
const idToken = parsedHash.get("id_token");
const tokenType = parsedHash.get("token_type");
await fetch("몰루", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer tokenText"
},
body: {
idToken: `${tokenType} ${idToken}`,
nonce: window.localStorage.get("nonce")
}
}
const { idToken, nonce: clientNonce } = await request.json();
const { sub, nonce: tokenNonce } = await parseJwt(idToken.split(" ")[1]);
// Nonce value error
if (clientNonce !== tokenNonce) {
return NextResponse.json({ error: "Replay Attack" }, { status: 403 });
}
출처:
https://academy.gopax.co.kr/ripeulrei-gonggyeogiran-mueosingayo/
https://developers.google.com/identity/openid-connect/openid-connect#appsetup