-
Notifications
You must be signed in to change notification settings - Fork 5
Proof-of-concept: Support OAuth and OIDC auth providers #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
de87cf5
a4286c0
2bd357e
d7051df
8716ea7
f5e94ff
4fac2f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
####################################### | ||
# Authentication | ||
####################################### | ||
|
||
# A random string used for encrypting tokens and verification hashes. | ||
# Generate its value by running `openssl rand -base64 32` | ||
# or via https://generate-secret.vercel.app/32 | ||
NEXTAUTH_SECRET="Replace me" | ||
|
||
# The template provides a Cognito authentication example by default. To make it work, | ||
# you'll need to set these. Using Cognito is not required! See the setup-authentication.md | ||
# documentation for more details. | ||
COGNITO_CLIENT_ID= | ||
COGNITO_CLIENT_SECRET= | ||
COGNITO_DOMAIN= | ||
COGNITO_ISSUER=https://cognito-idp.{PUT REGION HERE}.amazonaws.com/{PUT USER POOL ID HERE} | ||
COGNITO_DOMAIN=https://{PUT SUBDOMAIN HERE}.auth.{PUT REGION HERE}.amazoncognito.com |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ npm-debug.log* | |
|
||
# local env files | ||
.env*.local | ||
!.env.local.example | ||
|
||
# vercel | ||
.vercel | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
/// <reference types="next/navigation-types/compat/navigation" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* @file Behind the scenes, this creates all the relevant OAuth API routes within /api/auth/* | ||
* such as GET /api/auth/signin and POST /api/auth/signin/:provider | ||
* | ||
* @see https://authjs.dev/getting-started/providers/oauth-tutorial | ||
*/ | ||
export { GET, POST } from "src/auth"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this looks a little different from the snippet in the tutorial, which looks like
just curious for my own understanding the choice to do it this way. my guess is because you wanted to use the new App Router and the NextAuth snippet is using the old method of routing?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this branch is using the 5.0 beta version so some of the existing docs are out of date |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"use client"; | ||
|
||
import { federateSignOut } from "src/auth"; | ||
|
||
import { useEffect } from "react"; | ||
|
||
export default function Page() { | ||
/** | ||
* Not super sure why this needs to be called on the client-side, but at the | ||
* moment the Auth.js signOut method has a dependency on `window`, at a minimum. | ||
*/ | ||
Comment on lines
+8
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my guess is they need to clear some cookies, which only get sent to the matching domain by the browser for security reasons |
||
useEffect(() => { | ||
federateSignOut().catch(console.error); | ||
}, []); | ||
|
||
return <div>Signing out...</div>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const metadata = { | ||
title: "Next.js template", | ||
}; | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body>{children}</body> | ||
</html> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { auth } from "src/auth"; | ||
|
||
import Link from "next/link"; | ||
|
||
export default async function Page() { | ||
const session = await auth(); | ||
|
||
if (session) { | ||
return ( | ||
<> | ||
<p> | ||
<Link href="/auth/signout">Sign out</Link> | ||
</p> | ||
<strong>User ID: {session.sub}</strong> | ||
<code>{JSON.stringify(session, null, 2)}</code> | ||
</> | ||
); | ||
} | ||
|
||
return <Link href="/api/auth/signin">Sign in</Link>; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Not auth related. Added due to Next.js App router being utilized in this branch