feat(auth): Add authorize page

This commit is contained in:
Björn Benouarets
2026-01-21 06:40:53 +01:00
parent 74232ad2d2
commit 9e7841ee35
8 changed files with 90 additions and 38 deletions

View File

@@ -15,7 +15,7 @@ import { Separator } from "@/components/ui/separator";
import { Spinner } from "@/components/ui/spinner";
import { ShieldCheck } from "lucide-react";
import { IconExternalLink, IconHomeFilled, IconUserCircle, IconUser, IconMail, IconChevronRight, IconCheck } from "@tabler/icons-react";
import { IconExternalLink, IconHomeFilled, IconUserCircle, IconChevronRight, IconCheck } from "@tabler/icons-react";
import permissions from "@/permissions.json";
@@ -27,6 +27,7 @@ export interface AuthorizeContainerProps {
applicationName: string;
applicationUrl: string;
applicationLogo?: string;
returnTo: string;
}
export interface AuthorizeLoadingProps {
@@ -98,18 +99,6 @@ export const AuthorizeContainer = (props: AuthorizeContainerProps) => {
const router = useRouter();
// const handleLogout = async () => {
// const response = await fetch("/api/logout");
// const data = await response.json();
// if (data.success) {
// toast.success(data.message);
// router.refresh();
// } else {
// toast.error(data.message);
// }
// };
// Get for each scope the permission name and description
const scopePermissions = React.useMemo(() => {
return props.scope.split(" ").map((scope) => {
return {

View File

@@ -0,0 +1,33 @@
"use server";
export interface AuthorizeParams {
client_id: string;
redirect_uri: string;
response_type: string;
scope: string;
state: string;
}
export interface AuthorizeResponse {
success: boolean;
message: string;
code?: string;
state?: string;
}
export const authorize = async (params: AuthorizeParams, token: string): Promise<AuthorizeResponse> => {
if (!process.env.SECNEX_OAUTH2_API_HOST) {
return { success: false, message: "SecNex OAuth2 API host is not set" };
}
const response = await fetch(`${process.env.SECNEX_OAUTH2_API_HOST}/authorize`, {
method: "POST",
body: JSON.stringify(params),
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`,
},
});
const data = await response.json();
return { success: true, message: data.message, code: data.code, state: data.state };
};

View File

@@ -3,18 +3,18 @@
import { cookies } from "next/headers";
export const login = async (username: string, password: string): Promise<{ success: boolean, message: string, token?: string }> => {
if (!process.env.SECNEX_API_HOST || !process.env.SECNEX_API_KEY) {
if (!process.env.SECNEX_AUTH_API_HOST || !process.env.SECNEX_AUTH_API_KEY) {
return { success: false, message: "SecNex API host or key is not set" };
}
const cookieStore = await cookies();
try {
const response = await fetch(`${process.env.SECNEX_API_HOST}/login`, {
const response = await fetch(`${process.env.SECNEX_AUTH_API_HOST}/login`, {
method: "POST",
body: JSON.stringify({ username, password }),
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${process.env.SECNEX_API_KEY}`,
"Authorization": `Bearer ${process.env.SECNEX_AUTH_API_KEY}`,
},
});
const dataResponse = await response.json();