feat(SW-158): Implemented seamless login in magic link login

This commit is contained in:
Hrishikesh Vaipurkar
2024-08-14 18:08:37 +02:00
parent ce51402443
commit 710730a9e9
4 changed files with 79 additions and 36 deletions

View File

@@ -16,6 +16,7 @@ export async function GET(
const returnUrl = request.headers.get("x-returnurl")
const isMFA = request.headers.get("x-mfa-login")
const isMagicLinkLogin = !!request.headers.get("x-magic-link")
if (returnUrl) {
// Seamless login request from Current web
@@ -86,33 +87,37 @@ export async function GET(
console.log({ login_env: process.env })
console.log({ login_redirectTo: redirectTo })
const params = isMFA
? {
ui_locales: context.params.lang,
scope: ["profile_update", "openid", "profile"].join(" "),
/**
* The below acr value is required as for New Web same Curity Client is used for MFA
* while in current web it is being setup using different Curity Client
*/
acr_values:
"urn:se:curity:authentication:otp-authenticator:OTP-Authenticator_web",
for_origin: env.PUBLIC_URL ? env.PUBLIC_URL : "",
}
: {
ui_locales: context.params.lang,
scope: ["openid", "profile"].join(" "),
/**
* The `acr_values` param is used to make Curity display the proper login
* page for Scandic. Without the parameter Curity presents some choices
* to the user which we do not want.
*/
acr_values: "acr",
/**
* The `for_origin` param is used to make Curity email login functionality working.
* Without the parameter Curity gives Internal Error issue for login with Email link.
*/
for_origin: env.PUBLIC_URL ? env.PUBLIC_URL : "",
}
const params = {
ui_locales: context.params.lang,
scope: ["openid", "profile"].join(" "),
/**
* The `acr_values` param is used to make Curity display the proper login
* page for Scandic. Without the parameter Curity presents some choices
* to the user which we do not want.
*/
acr_values: "acr",
/**
* The `for_origin` param is used to make Curity email login functionality working.
* Without the parameter Curity gives Internal Error issue for login with Email link.
*/
for_origin: env.PUBLIC_URL ? env.PUBLIC_URL : "",
/**
* This is new param set for differentiate between
* the Magic link login of New web and current web
*/
version: "2",
}
if (isMFA) {
params.scope = ["profile_update", "openid", "profile"].join(" ")
/**
* The below acr value is required as for New Web same Curity Client is used for MFA
* while in current web it is being setup using different Curity Client
*/
params.acr_values =
"urn:se:curity:authentication:otp-authenticator:OTP-Authenticator_web"
} else if (isMagicLinkLogin) {
params.acr_values = "abc"
}
const redirectUrl = await signIn(
"curity",
{

View File

@@ -27,13 +27,14 @@ export async function GET(
}
// Remove Seamless login as it doesn't work with Magic link login due to different authenticators
if (redirectTo.indexOf("updatelogin?returnurl") !== -1) {
// Additional URL decode required as url in the query parameter is encoded twice as
// passed in query param and further in cookie value.
redirectTo = decodeURIComponent(
redirectTo.substring(redirectTo.indexOf("returnurl") + 10)
)
}
// if (redirectTo.indexOf("updatelogin?returnurl") !== -1) {
// // Additional URL decode required as url in the query parameter is encoded twice as
// // passed in query param and further in cookie value.
// redirectTo = decodeURIComponent(
// redirectTo.substring(redirectTo.indexOf("returnurl") + 10)
// )
// }
redirectTo = redirectTo.replace("updatelogin", "updateloginemail")
loginKey = request.nextUrl.searchParams.get("loginKey")
@@ -61,9 +62,11 @@ export async function GET(
},
{
ui_locales: context.params.lang,
scope: ["openid", "profile"].join(" "),
loginKey: loginKey,
acr_values: "cat",
prompt: "login",
for_origin: env.PUBLIC_URL ? env.PUBLIC_URL : "",
acr_values: "abc",
version: "2",
}
)