feat: SW-162 MFA for Profile implemented

This commit is contained in:
Hrishikesh Vaipurkar
2024-07-16 14:38:57 +02:00
parent 0c0fc1d08b
commit dde2b828cb
7 changed files with 177 additions and 12 deletions

23
auth.ts
View File

@@ -1,3 +1,5 @@
import { decode,encode } from "@auth/core/jwt"
import { cookies } from "next/headers"
import NextAuth from "next-auth"
import { env } from "@/env/server"
@@ -55,6 +57,7 @@ const customProvider = {
sub: profile.sub,
given_name: profile.given_name,
login_with: profile.login_with,
acr: profile.acr,
}
},
} satisfies OIDCConfig<User>
@@ -114,6 +117,26 @@ export const config = {
return true
},
async jwt({ account, session, token, trigger, user }) {
if (
user?.acr ==
"urn:se:curity:authentication:otp-authenticator:OTP-Authenticator_web"
) {
const cookieStore = cookies()
const value = token.access_token
const secret = env.NEXTAUTH_SECRET
const maxAge = 60 * 15
const name = "_SecureMFA-token"
const mfaCookie = await encode({
secret,
maxAge,
token: value,
salt: name,
})
cookieStore.set("_SecureMFA-token", mfaCookie.toString(), {
maxAge: maxAge,
})
}
const loginType = getLoginType(user)
if (account) {
return {