-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(secret-defaults): ♻️ Refactored logic to provide default sec…
…rets
- Loading branch information
Showing
3 changed files
with
47 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { genBase64FromBytes, generateRandomUrlSafeString } from '../utils/security' | ||
import { subtle } from 'uncrypto' | ||
|
||
export default defineNitroPlugin(async () => { | ||
if (!process.env.NUXT_OIDC_SESSION_SECRET || process.env.NUXT_OIDC_SESSION_SECRET.length < 48) { | ||
const randomSecret = generateRandomUrlSafeString() | ||
process.env.NUXT_OIDC_SESSION_SECRET = randomSecret | ||
console.warn('[nuxt-oidc-auth]: No session secret set, using a random secret. Please set NUXT_OIDC_SESSION_SECRET in your environment with at least 48 chars.') | ||
console.info(`[nuxt-oidc-auth]: NUXT_OIDC_SESSION_SECRET=${randomSecret}`) | ||
} | ||
if (!process.env.NUXT_OIDC_TOKEN_KEY) { | ||
const randomKey = genBase64FromBytes(new Uint8Array(await subtle.exportKey('raw', await subtle.generateKey({ name: 'AES-GCM', length: 256, }, true, ['encrypt', 'decrypt'])))) | ||
process.env.NUXT_OIDC_TOKEN_KEY = randomKey | ||
console.warn('[nuxt-oidc-auth]: No refresh token key set, using a random key. Please set NUXT_OIDC_TOKEN_KEY in your environment. Refresh tokens saved in this session will be inaccessible after a server restart.') | ||
console.info(`[nuxt-oidc-auth]: NUXT_OIDC_TOKEN_KEY=${randomKey}`) | ||
} | ||
if (!process.env.NUXT_OIDC_AUTH_SESSION_SECRET) { | ||
const randomKey = generateRandomUrlSafeString() | ||
process.env.NUXT_OIDC_AUTH_SESSION_SECRET = randomKey | ||
console.warn('[nuxt-oidc-auth]: No auth session secret set, using a random secret. Please set NUXT_OIDC_AUTH_SESSION_SECRET in your environment.') | ||
console.info(`[nuxt-oidc-auth]: NUXT_OIDC_AUTH_SESSION_SECRET=${randomKey}`) | ||
} | ||
}) |