Possibility to configure an OpenID Connect provider on the instance level WIP (#128).

This commit is contained in:
John Livingston
2024-04-17 18:30:39 +02:00
parent 3a5f27e751
commit 6c13d2e377
9 changed files with 139 additions and 24 deletions

View File

@ -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'
}