-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JWT tokens working with oidc somewhat working
- Loading branch information
Showing
8 changed files
with
95 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use client"; | ||
import Skeleton from "@/components/Skeleton"; | ||
import { userManager } from "@/lib/auth"; | ||
import { useEffect } from "react"; | ||
import { AuthProvider, AuthProviderProps, useAuth } from "react-oidc-context"; | ||
import { permanentRedirect } from "next/navigation"; | ||
|
||
const config = { | ||
userManager, | ||
onSigninCallback: (user) => { | ||
console.log(user); | ||
permanentRedirect("/review"); | ||
}, | ||
} satisfies AuthProviderProps; | ||
|
||
export default function AuthLayout({ | ||
children, | ||
}: Readonly<{ | ||
children: React.ReactNode; | ||
}>) { | ||
return <AuthProvider {...config}>{children}</AuthProvider>; | ||
} |
35 changes: 35 additions & 0 deletions
35
frontend/review-nextjs/app/(header)/(auth)/review/page.tsx
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"use client"; | ||
import Skeleton from "@/components/Skeleton"; | ||
import { cn } from "@/lib/utils"; | ||
import { useEffect } from "react"; | ||
import { useAuth } from "react-oidc-context"; | ||
|
||
/* | ||
On error with fetching data | ||
try { | ||
userManager.signinSilent() | ||
} catch (error) { | ||
userManager.signinRedirect() | ||
} | ||
*/ | ||
|
||
export default function Review() { | ||
const auth = useAuth(); | ||
|
||
return ( | ||
<div id="review" className={cn("mx-[20%]")}> | ||
{auth.isLoading ? <Skeleton /> : <ReviewPage />} | ||
</div> | ||
); | ||
} | ||
|
||
function ReviewPage() { | ||
const auth = useAuth(); | ||
|
||
return ( | ||
<p> | ||
Secret data that needs authentication {auth.isAuthenticated}{" "} | ||
{auth.user?.profile.email} | ||
</p> | ||
); | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Skeleton() { | ||
return ( | ||
<div> | ||
<h1>Skeleton data</h1> | ||
</div> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"use client"; | ||
import { UserManager, WebStorageStateStore } from "oidc-client-ts"; | ||
import { BASE_URL, CLIENT_ID } from "@/lib/api"; | ||
|
||
export const userManager = new UserManager({ | ||
authority: "https://platform.pennlabs.org/", | ||
client_id: CLIENT_ID, | ||
redirect_uri: `${BASE_URL}/callback`, | ||
scope: "openid read", | ||
metadataUrl: | ||
"https://platform.pennlabs.org/accounts/.well-known/openid-configuration/", | ||
metadata: { | ||
authorization_endpoint: | ||
"https://platform.pennlabs.org/accounts/authorize/", | ||
token_endpoint: "https://platform.pennlabs.org/accounts/token/", | ||
jwks_uri: | ||
"https://platform.pennlabs.org/accounts/.well-known/jwks.json", | ||
}, | ||
automaticSilentRenew: true, | ||
includeIdTokenInSilentRenew: true, | ||
userStore: new WebStorageStateStore({ store: window?.localStorage }), | ||
}); | ||
console.log(userManager); |
This file was deleted.
Oops, something went wrong.