Possibility to configure an OpenID Connect provider on the instance level WIP (#128).
This commit is contained in:
@ -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