-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving configuration fetching inside getUniloginClient
No need to repeat configuration fetching outside of it.
- Loading branch information
Showing
15 changed files
with
250 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,39 @@ | ||
import { generators } from "openid-client" | ||
|
||
import { getUniloginClient } from "@/lib/session/oauth/uniloginClient" | ||
import { | ||
getOpenIdClientUniloginClientConfig, | ||
getUniloginClient, | ||
} from "@/lib/session/oauth/uniloginClient" | ||
import { getSession } from "@/lib/session/session" | ||
|
||
export const revalidate = 1 | ||
|
||
export async function GET() { | ||
const configResponse = await fetch(`${process.env.NEXT_PUBLIC_APP_URL}/auth/config`) | ||
if (!configResponse.ok) { | ||
throw new Error("Failed to fetch config") | ||
} | ||
const config = await configResponse.json() | ||
const uniloginConfig = config?.dplConfiguration?.unilogin | ||
|
||
const session = await getSession() | ||
session.code_verifier = generators.codeVerifier() | ||
|
||
const client = await getUniloginClient({ | ||
client_id: uniloginConfig.unilogin_api_client_id, | ||
client_secret: uniloginConfig.unilogin_api_client_secret, | ||
redirect_uri: `${process.env.NEXT_PUBLIC_APP_URL}/auth/callback/unilogin`, | ||
wellKnownUrl: uniloginConfig.unilogin_api_wellknown_url, | ||
}) | ||
session.code_verifier = generators.codeVerifier() | ||
|
||
const code_challenge = generators.codeChallenge(session.code_verifier) | ||
|
||
const openIdClientConfig = await getOpenIdClientUniloginClientConfig() | ||
|
||
if ( | ||
!openIdClientConfig || | ||
!openIdClientConfig.scope || | ||
!openIdClientConfig.redirect_uri || | ||
!openIdClientConfig.audience | ||
) { | ||
throw new Error("Unilogin client config is invalid.") | ||
} | ||
|
||
const client = await getUniloginClient() | ||
|
||
const url = client.authorizationUrl({ | ||
scope: "openid", | ||
audience: process.env.UNILOGIN_API_URL, | ||
redirect_uri: `${process.env.NEXT_PUBLIC_APP_URL}/auth/callback/unilogin`, | ||
scope: openIdClientConfig.scope, | ||
audience: openIdClientConfig.audience, | ||
redirect_uri: openIdClientConfig.redirect_uri, | ||
code_challenge, | ||
code_challenge_method: "S256", | ||
}) | ||
|
||
await session.save() | ||
|
||
return Response.redirect(url) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.