Files
login/components/server/authorize.tsx
2026-01-21 06:40:53 +01:00

33 lines
880 B
TypeScript

"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 };
};