feat(xo-server-auth-oidc): make well-known suffix optional
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user