feat(xo-server-auth-oidc): make well-known suffix optional

This commit is contained in:
Julien Fontanet
2023-03-14 10:00:50 +01:00
parent 7adfc195dc
commit 3c4dcde1d4
2 changed files with 16 additions and 1 deletions

View File

@@ -8,6 +8,7 @@
> Users must be able to say: “Nice enhancement, I'm eager to test it”
- [Plugin/auth-oidc] Support `email` for _username field_ setting [Forum#59587](https://xcp-ng.org/forum/post/59587)
- [Plugin/auth-oidc] Well-known suffix is now optional in _auto-discovery URL_
### Bug fixes

View File

@@ -1,5 +1,6 @@
'use strict'
const { join } = require('node:path/posix')
const { Strategy } = require('passport-openidconnect')
// ===================================================================
@@ -46,6 +47,8 @@ exports.configurationSchema = {
// ===================================================================
const WELL_KNOWN_ENDPOINT = '/.well-known/openid-configuration'
class AuthOidc {
#conf
#unregisterPassportStrategy
@@ -69,7 +72,18 @@ class AuthOidc {
const { discoveryURL, usernameField, ...conf } = this.#conf
if (discoveryURL !== undefined) {
const res = await this.#xo.httpRequest(discoveryURL)
let url = discoveryURL
let onError
// try with the well-known path first
if (!url.endsWith(WELL_KNOWN_ENDPOINT)) {
url = join(url, WELL_KNOWN_ENDPOINT)
// on error, retry with the original URL
onError = () => this.#xo.httpRequest(discoveryURL)
}
const res = await this.#xo.httpRequest(url).catch(onError)
const data = await res.json()
for (const key of DISCOVERABLE_SETTINGS) {