feat(auth): Add authorize page
This commit is contained in:
33
components/server/authorize.tsx
Normal file
33
components/server/authorize.tsx
Normal 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 };
|
||||
};
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user