diff --git a/.env b/.env deleted file mode 100644 index a495c0a..0000000 --- a/.env +++ /dev/null @@ -1,5 +0,0 @@ -api=http://localhost:3000/api - -GITHUB_ID=66146c5effe18f4b6170 -GITHUB_SECRET=df8625a822f87d19dc188a8ffec590f5e2809a15 -NEXTAUTH_URL=http://localhost:3000 diff --git a/.env-example b/.env-example new file mode 100644 index 0000000..be58c11 --- /dev/null +++ b/.env-example @@ -0,0 +1,7 @@ +api= + +AZURE_AD_CLIENT_ID= +AZURE_AD_CLIENT_SECRET= +AZURE_AD_TENANT_ID= + +NEXTAUTH_URL=http://localhost:3000 diff --git a/.gitignore b/.gitignore index 2442b5b..6153c18 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ .next node_modules -.env \ No newline at end of file +.env.local \ No newline at end of file diff --git a/package.json b/package.json index b399d9a..982015d 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "dependencies": { "axios": "^0.21.4", "next": "^11.1.2", - "next-auth": "^4.0.0-beta.2", + "next-auth": "^4.0.0-beta.4", "react": "^17.0.2", "react-dom": "^17.0.2" }, diff --git a/pages/api/auth/[...nextauth].js b/pages/api/auth/[...nextauth].js index 15e0b43..bf7b540 100644 --- a/pages/api/auth/[...nextauth].js +++ b/pages/api/auth/[...nextauth].js @@ -1,11 +1,34 @@ import NextAuth from 'next-auth' -import GithubProvider from 'next-auth/providers/github' export default NextAuth({ + // next-auth azure-ad provider wasnt working for me, credit here + // https://github.com/nextauthjs/next-auth/discussions/2690 providers: [ - GithubProvider({ - clientId: process.env.GITHUB_ID, - clientSecret: process.env.GITHUB_SECRET, - }), + { + id: 'azure-ad', + name: 'Azure Active Directory', + type: 'oauth', + authorization: { + url: `https://login.microsoftonline.com/${process.env.AZURE_AD_TENANT_ID}/oauth2/v2.0/authorize?response_mode=query`, + params: { + scope: 'user.read offline_access', + }, + }, + token: `https://login.microsoftonline.com/${process.env.AZURE_AD_TENANT_ID}/oauth2/v2.0/token`, + userinfo: 'https://graph.microsoft.com/oidc/userinfo', + profile(profile) { + return { + id: profile.sub, + ...profile, + } + }, + options: { + clientId: process.env.AZURE_AD_CLIENT_ID, + clientSecret: process.env.AZURE_AD_CLIENT_SECRET, + }, + }, ], + jwt: { + signingKey: process.env.JWT_SIGNING_PRIVATE_KEY, + }, }) diff --git a/pages/index.jsx b/pages/index.jsx index 925e925..25cac7d 100644 --- a/pages/index.jsx +++ b/pages/index.jsx @@ -2,9 +2,12 @@ import axios from 'axios' import { getSession, useSession, signOut } from 'next-auth/react' export default function App({ message }) { + const { data: session } = useSession() return (