-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
110 fix server side authentification (#133)
Co-authored-by: Sigrid Elnan <[email protected]>
- Loading branch information
1 parent
f15390a
commit ffab112
Showing
24 changed files
with
304 additions
and
531 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
NEXT_PUBLIC_CLIENT_ID=<client-id> # App Registrations (Azure portal) -> select app reg -> Copy client ID | ||
NEXT_PUBLIC_TENANT_ID=<tenant-id> # App Registrations (Azure portal) -> select app reg -> Copy tenant ID | ||
NEXT_PUBLIC_APP_SCOPE= # App Registrations (Azure portal) -> select app reg -> Expose an API -> Copy scope ID (i.e. api://oidajwoig/...) | ||
|
||
# NEXT_PUBLIC_VIBES_BACKEND_URL= #Not necessary for local development, defaults to localhost api | ||
AZURE_AD_CLIENT_ID= # App Registrations (Azure portal) -> select app reg -> Copy client ID | ||
AZURE_AD_TENANT_ID= # App Registrations (Azure portal) -> select app reg -> Copy tenant ID | ||
AZURE_AD_APP_SCOPE= # App Registrations (Azure portal) -> select app reg -> Expose an API -> Copy scope ID (i.e. api://oidajwoig/...) | ||
AZURE_AD_CLIENT_SECRET= #Generate from app registration | ||
NEXTAUTH_SECRET= # High-entroy random secret | ||
NEXTAUTH_URL= # i.e. http://localhost:3000 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { AuthOptions, getServerSession, Session } from "next-auth"; | ||
import AzureADProvider from "next-auth/providers/azure-ad"; | ||
|
||
export type CustomSession = { | ||
id_token?: string; | ||
access_token?: string; | ||
} & Session; | ||
|
||
export const authOptions: AuthOptions = { | ||
// Configure one or more authentication providers | ||
providers: [ | ||
AzureADProvider({ | ||
clientId: process.env.AZURE_AD_CLIENT_ID!, | ||
clientSecret: process.env.AZURE_AD_CLIENT_SECRET!, | ||
tenantId: process.env.AZURE_AD_TENANT_ID!, | ||
authorization: { | ||
params: { | ||
scope: `openid profile email ${process.env.AZURE_AD_APP_SCOPE}`, | ||
}, | ||
}, | ||
idToken: true, | ||
}), | ||
], | ||
session: { | ||
strategy: "jwt", | ||
maxAge: 30 * 24 * 60 * 60, // 30 days | ||
}, | ||
|
||
callbacks: { | ||
async redirect({ baseUrl }) { | ||
return baseUrl; | ||
}, | ||
async jwt({ token, account }) { | ||
if (account) { | ||
token.id_token = account.id_token; | ||
token.access_token = account.access_token; | ||
} | ||
return token; | ||
}, | ||
async session({ session, token }) { | ||
if (session) { | ||
session = Object.assign({}, session, { | ||
id_token: token.id_token, | ||
access_token: token.access_token, | ||
}); | ||
} | ||
return session; | ||
}, | ||
}, | ||
}; | ||
|
||
export async function getCustomServerSession(authOptions: AuthOptions) { | ||
return (await getServerSession(authOptions)) as CustomSession; | ||
} |
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,22 +1,14 @@ | ||
"use client"; | ||
|
||
import FilteredConsultantsList from "@/components/FilteredConsultantsList"; | ||
import useVibesApi from "@/hooks/useVibesApi"; | ||
import { CircularProgress } from "@mui/material"; | ||
|
||
export default function Bemanning() { | ||
const { data, isLoading } = useVibesApi(true); | ||
|
||
if (isLoading) { | ||
return <CircularProgress />; | ||
} | ||
|
||
if (data) { | ||
return ( | ||
<div> | ||
<h1>Konsulenter</h1> | ||
<FilteredConsultantsList consultants={data} /> | ||
</div> | ||
); | ||
} | ||
import { fetchWithToken } from "@/data/fetchWithToken"; | ||
import { Variant } from "@/types"; | ||
|
||
export default async function Bemanning() { | ||
const consultants = (await fetchWithToken<Variant[]>("variants")) ?? []; | ||
|
||
return ( | ||
<div> | ||
<h1>Konsulenter</h1> | ||
<FilteredConsultantsList consultants={consultants} /> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.