Skip to content

Commit

Permalink
working dex auth flow
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Hildebrandt <[email protected]>
  • Loading branch information
paulphys committed Oct 19, 2024
1 parent 259f8df commit a76bbfd
Show file tree
Hide file tree
Showing 14 changed files with 366 additions and 46 deletions.
7 changes: 6 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
API_URL=https://capi-jsgen.moin.k8s.scs.community
API_URL=https://capi-jsgen.moin.k8s.scs.community

AUTH_SECRET=
DEX_URL=https://dex.k8s.scs.community
DEX_CLIENT_ID=
DEX_CLIENT_SECRET=
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Web UI for creating Cluster objects based on SCS Cluster Stacks.

- [pnpm](https://pnpm.io/installation)


```bash
pnpm i
pnpm dev
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"dependencies": {
"@hookform/resolvers": "^3.9.0",
"@radix-ui/react-avatar": "^1.1.1",
"@radix-ui/react-checkbox": "^1.1.2",
"@radix-ui/react-dropdown-menu": "^2.1.2",
"@radix-ui/react-icons": "^1.3.0",
Expand All @@ -34,6 +35,7 @@
"js-yaml": "^4.1.0",
"lucide-react": "^0.452.0",
"next": "14.2.15",
"next-auth": "5.0.0-beta.22",
"next-themes": "^0.3.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
123 changes: 123 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { handlers } from "@/app/auth";
export const { GET, POST } = handlers;
52 changes: 52 additions & 0 deletions src/app/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import NextAuth from "next-auth";
import type { NextAuthConfig } from "next-auth";

declare module "next-auth" {
interface Session {
accessToken?: string;
profile?: any;
}
}

const config = {
providers: [
{
id: "dex",
name: "SCS Dex",
type: "oidc",
authorization: {
params: { scope: ["openid profile email groups"] },
},
issuer: process.env.DEX_URL,
clientId: process.env.DEX_CLIENT_ID,
client: {
token_endpoint_auth_method: "none",
},
profile(profile) {
return {
id: profile.sub,
name: profile.name,
email: profile.email,
groups: profile.groups,
username: profile.preferred_username,
};
},
},
],
basePath: "/api/auth",
session: { strategy: "jwt" },
callbacks: {
jwt({ token, user, profile }) {
if (user) token.user = user;
if (profile) token.profile = profile;
return token;
},
async session({ session, token, user }) {
if (session.user) session.profile = token.profile;
return session;
},
},
debug: process.env.NODE_ENV !== "production" ? true : false,
} satisfies NextAuthConfig;

export const { handlers, auth, signIn, signOut } = NextAuth(config);
7 changes: 4 additions & 3 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import "./globals.css";
import { Metadata, Viewport } from "next";
import { cn } from "@/lib/utils";
import { fontSans } from "@/lib/utils";
import { ThemeProvider } from "@/components/theme-provider";
import { siteConfig } from "@/config/site";
import { Navbar } from "@/components/navbar";

import { ThemeProvider } from "@/components/theme-provider";
import { TailwindIndicator } from "@/components/tailwind-indicator";
import Header from "@/components/header";

export const metadata: Metadata = {
title: {
Expand Down Expand Up @@ -55,7 +56,7 @@ export default function RootLayout({ children }: RootLayoutProps) {
disableTransitionOnChange
>
<div className="relative flex min-h-screen flex-col bg-background">
<Navbar />
<Header />
<main className="flex-1">{children}</main>
</div>
</ThemeProvider>
Expand Down
Loading

0 comments on commit a76bbfd

Please sign in to comment.