Add full OpenID connect provider support

This commit is contained in:
Jesse Wierzbinski 2023-12-06 12:10:22 -10:00
parent 14d96ac9e6
commit 947c1f4991
No known key found for this signature in database
47 changed files with 604 additions and 247 deletions

View file

@ -32,6 +32,17 @@ export interface ConfigType {
enabled: boolean;
};
oidc: {
providers: {
name: string;
id: string;
url: string;
client_id: string;
client_secret: string;
icon: string;
}[];
};
http: {
base_url: string;
bind: string;
@ -189,6 +200,9 @@ export const configDefaults: ConfigType = {
api_key: "",
enabled: false,
},
oidc: {
providers: [],
},
instance: {
banner: "",
description: "",

6
utils/constants.ts Normal file
View file

@ -0,0 +1,6 @@
import { getConfig } from "@config";
const config = getConfig();
export const oauthRedirectUri = (issuer: string) =>
`${config.http.base_url}/oauth/callback/${issuer}`;

View file

@ -59,3 +59,5 @@ export const checkIfOauthIsValid = (
return false;
};
export const oauthCodeVerifiers: Record<string, string> = {};

20
utils/temp.ts Normal file
View file

@ -0,0 +1,20 @@
import { join } from "path";
import { exists, mkdir, writeFile, readFile } from "fs/promises";
export const writeToTempDirectory = async (filename: string, data: string) => {
const tempDir = join(process.cwd(), "temp");
if (!(await exists(tempDir))) await mkdir(tempDir);
const tempFile = join(tempDir, filename);
await writeFile(tempFile, data);
return tempFile;
};
export const readFromTempDirectory = async (filename: string) => {
const tempDir = join(process.cwd(), "temp");
if (!(await exists(tempDir))) await mkdir(tempDir);
const tempFile = join(tempDir, filename);
return readFile(tempFile, "utf-8");
};