From 6c13d2e3771871fb118ff97f2a0e10fa04d677ad Mon Sep 17 00:00:00 2001 From: John Livingston Date: Wed, 17 Apr 2024 18:30:39 +0200 Subject: [PATCH] Possibility to configure an OpenID Connect provider on the instance level WIP (#128). --- client/utils/conversejs.ts | 2 +- conversejs/builtin.ts | 13 +++- .../livechat-external-login-modal.js | 10 ++- conversejs/lib/auth.ts | 23 ++++-- server/lib/external-auth/oidc.ts | 75 ++++++++++++++++++- server/lib/external-auth/types.ts | 1 + server/lib/routers/api/auth.ts | 26 +++++++ server/lib/routers/oidc.ts | 6 +- shared/lib/types.ts | 7 +- 9 files changed, 139 insertions(+), 24 deletions(-) diff --git a/client/utils/conversejs.ts b/client/utils/conversejs.ts index b6588e55..fc7ad6c1 100644 --- a/client/utils/conversejs.ts +++ b/client/utils/conversejs.ts @@ -151,7 +151,7 @@ async function displayConverseJS ( (forceType ? '?forcetype=1' : ''), { method: 'GET', - headers: peertubeHelpers.getAuthHeader() + headers: authHeader } ) if (!response.ok) { diff --git a/conversejs/builtin.ts b/conversejs/builtin.ts index 2edb765b..57a1a495 100644 --- a/conversejs/builtin.ts +++ b/conversejs/builtin.ts @@ -107,7 +107,11 @@ async function initConverse ( let isAuthenticated: boolean = false let isRemoteWithNicknameSet: boolean = false - const auth = await getLocalAuthentInfos(authenticationUrl, peertubeAuthHeader) + // OIDC (OpenID Connect): + const tryOIDC = !!initConverseParams.externalAuthOIDC + + const auth = await getLocalAuthentInfos(authenticationUrl, tryOIDC, peertubeAuthHeader) + if (auth) { if (!isRemoteChat) { localRoomAuthenticatedParams(initConverseParams, auth, params) @@ -160,8 +164,11 @@ async function initConverse ( // no viewer mode if authenticated. params.livechat_enable_viewer_mode = autoViewerMode && !isAuthenticated && !isRemoteWithNicknameSet - params.livechat_external_auth_oidc_button_label = initConverseParams.externalAuthOIDC?.buttonLabel - params.livechat_external_auth_oidc_url = initConverseParams.externalAuthOIDC?.url + + if (tryOIDC && !isAuthenticated) { + params.livechat_external_auth_oidc_button_label = initConverseParams.externalAuthOIDC?.buttonLabel + params.livechat_external_auth_oidc_url = initConverseParams.externalAuthOIDC?.url + } if (chatIncludeMode === 'peertube-video') { params.livechat_mini_muc_head = true // we must replace the muc-head by the custom buttons toolbar. diff --git a/conversejs/custom/templates/livechat-external-login-modal.js b/conversejs/custom/templates/livechat-external-login-modal.js index e6065b8b..b7211539 100644 --- a/conversejs/custom/templates/livechat-external-login-modal.js +++ b/conversejs/custom/templates/livechat-external-login-modal.js @@ -11,7 +11,7 @@ export const tplExternalLoginModal = (el, o) => { const externalAuthOIDCButtonLabel = api.settings.get('livechat_external_auth_oidc_button_label') const externalAuthOIDCUrl = api.settings.get('livechat_external_auth_oidc_url') return html`