Samuel Shuert | 3ceeae5 | 2023-11-21 11:32:00 -0500 | [diff] [blame] | 1 | import NextAuth from 'next-auth' |
| 2 | import KeycloakProvider from 'next-auth/providers/keycloak'; |
| 3 | import { decryptSops } from 'sops-wrapper'; |
| 4 | import os from 'os' |
| 5 | const encryptedKeycloakSecrets = 'config/keycloak-auth.json'; |
| 6 | |
| 7 | const secrets = (decryptSops(encryptedKeycloakSecrets)) as { |
| 8 | clientid: string; |
| 9 | clientsecret: string; |
| 10 | }; |
| 11 | |
| 12 | if (["a1d1", "a1d2"].includes(os.hostname())) { |
| 13 | const encryptedNextAuthSecrets = 'config/nextauth.json'; |
| 14 | for (const [key, value] of Object.entries(decryptSops(encryptedNextAuthSecrets) as {NEXTAUTH_URL: string; NEXTAUTH_SECRET: string;})) { |
| 15 | process.env[key] = value; |
| 16 | } |
| 17 | } else { |
| 18 | process.env["NEXTAUTH_URL"] = "http://samueldesktop:3000"; //however you wanna work this one out |
| 19 | process.env["NEXTAUTH_SECRET"] = "non-real-secret"; |
| 20 | } |
| 21 | |
| 22 | export default NextAuth({ |
| 23 | providers: [ |
| 24 | KeycloakProvider({ |
| 25 | clientId: secrets.clientid, |
| 26 | clientSecret: secrets.clientsecret, |
| 27 | issuer: "https://login.clicks.codes/realms/master", |
| 28 | }) |
| 29 | ] |
| 30 | }) |