Possibility to configure an OpenID Connect provider on the instance level WIP (#128).
This commit is contained in:
@ -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.
|
||||
|
@ -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`<div class="modal-body livechat-external-login-modal">
|
||||
${!externalAuthOIDCButtonLabel || !externalAuthOIDCUrl
|
||||
${!externalAuthOIDCButtonLabel || !externalAuthOIDCUrl || !window.sessionStorage
|
||||
? ''
|
||||
: html`
|
||||
<div class="livechat-external-login-modal-external-auth-oidc">
|
||||
@ -45,9 +45,13 @@ export const tplExternalLoginModal = (el, o) => {
|
||||
(data.message ? ` (${data.message})` : '')
|
||||
return
|
||||
}
|
||||
// TODO
|
||||
|
||||
console.info('Got external account information', data)
|
||||
console.error('not implemented yet')
|
||||
// Storing the token in sessionStorage.
|
||||
window.sessionStorage.setItem('peertube-plugin-livechat-oidc-token', data.token)
|
||||
|
||||
// FIXME: do better.
|
||||
window.location.reload()
|
||||
}
|
||||
|
||||
return false
|
||||
|
@ -8,6 +8,7 @@ interface AuthHeader { [key: string]: string }
|
||||
|
||||
async function getLocalAuthentInfos (
|
||||
authenticationUrl: string,
|
||||
tryOIDC: boolean,
|
||||
peertubeAuthHeader?: AuthHeader | null
|
||||
): Promise<false | AuthentInfos> {
|
||||
try {
|
||||
@ -20,11 +21,6 @@ async function getLocalAuthentInfos (
|
||||
return false
|
||||
}
|
||||
|
||||
if (peertubeAuthHeader === null) {
|
||||
console.info('User is not logged in.')
|
||||
return false
|
||||
}
|
||||
|
||||
if (peertubeAuthHeader === undefined) { // parameter not given.
|
||||
// We must be in a page without PeertubeHelpers, so we must get authent token manualy.
|
||||
if (!window.localStorage) {
|
||||
@ -45,12 +41,27 @@ async function getLocalAuthentInfos (
|
||||
}
|
||||
}
|
||||
|
||||
let oidcHeaders: any
|
||||
// When user has used the External OIDC mechanisme to create an account, we got a token in sessionStorage.
|
||||
if (tryOIDC && !peertubeAuthHeader && window.sessionStorage) {
|
||||
const token = window.sessionStorage.getItem('peertube-plugin-livechat-oidc-token')
|
||||
if (token && (typeof token === 'string')) {
|
||||
oidcHeaders = { 'X-Peertube-Plugin-Livechat-OIDC-Token': token }
|
||||
}
|
||||
}
|
||||
|
||||
if (peertubeAuthHeader === null && oidcHeaders === undefined) {
|
||||
console.info('User is not logged in.')
|
||||
return false
|
||||
}
|
||||
|
||||
const response = await window.fetch(authenticationUrl, {
|
||||
method: 'GET',
|
||||
headers: new Headers(
|
||||
Object.assign(
|
||||
{},
|
||||
peertubeAuthHeader,
|
||||
peertubeAuthHeader ?? {},
|
||||
oidcHeaders ?? {},
|
||||
{
|
||||
'content-type': 'application/json;charset=UTF-8'
|
||||
}
|
||||
|
Reference in New Issue
Block a user