Adding some standard OpenID Connect providers (Google, Facebook) (WIP):

* refactoring, to allow several OIDC singletons
* settings for google and facebook
* backend code
This commit is contained in:
John Livingston
2024-04-22 13:03:31 +02:00
parent 4bc2d4fd51
commit 024186ba2c
16 changed files with 341 additions and 142 deletions

View File

@ -1,14 +1,19 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import { newResult, TestResult } from './utils'
import { ExternalAuthOIDC } from '../external-auth/oidc'
import { ExternalAuthOIDC, ExternalAuthOIDCType } from '../external-auth/oidc'
export async function diagExternalAuthCustomOIDC (test: string, _options: RegisterServerOptions): Promise<TestResult> {
export async function diagExternalAuthOIDC (
test: string,
_options: RegisterServerOptions,
singletonType: ExternalAuthOIDCType,
next: TestResult['next']
): Promise<TestResult> {
const result = newResult(test)
result.label = 'Test External Auth Custom OIDC'
result.next = 'everything-ok'
result.label = 'Test External Auth OIDC: ' + singletonType
result.next = next
try {
const oidc = ExternalAuthOIDC.singleton()
const oidc = ExternalAuthOIDC.singleton(singletonType)
if (oidc.isDisabledBySettings()) {
result.ok = true
@ -40,7 +45,7 @@ export async function diagExternalAuthCustomOIDC (test: string, _options: Regist
return result
}
const oidc = ExternalAuthOIDC.singleton()
const oidc = ExternalAuthOIDC.singleton(singletonType)
const oidcClient = await oidc.load()
if (oidcClient) {
result.messages.push('Discovery URL loaded: ' + JSON.stringify(oidcClient.issuer.metadata))

View File

@ -4,7 +4,7 @@ import { TestResult, newResult } from './utils'
import { diagDebug } from './debug'
import { diagProsody } from './prosody'
import { diagVideo } from './video'
import { diagExternalAuthCustomOIDC } from './external-auth-custom-oidc'
import { diagExternalAuthOIDC } from './external-auth-oidc'
import { helpUrl } from '../../../shared/lib/help'
export async function diag (test: string, options: RegisterServerOptions): Promise<TestResult> {
@ -19,7 +19,11 @@ export async function diag (test: string, options: RegisterServerOptions): Promi
} else if (test === 'prosody') {
result = await diagProsody(test, options)
} else if (test === 'external-auth-custom-oidc') {
result = await diagExternalAuthCustomOIDC(test, options)
result = await diagExternalAuthOIDC(test, options, 'custom', 'external-auth-google-oidc')
} else if (test === 'external-auth-google-oidc') {
result = await diagExternalAuthOIDC(test, options, 'google', 'external-auth-facebook-oidc')
} else if (test === 'external-auth-facebook-oidc') {
result = await diagExternalAuthOIDC(test, options, 'facebook', 'everything-ok')
} else if (test === 'everything-ok') {
result = newResult(test)
result.label = 'Everything seems fine'

View File

@ -1,4 +1,6 @@
type nextValue = 'backend' | 'debug' | 'webchat-video' | 'prosody' | 'external-auth-custom-oidc' | 'everything-ok'
type NextValue = 'backend' | 'debug' | 'webchat-video' | 'prosody'
| 'external-auth-custom-oidc' | 'external-auth-google-oidc' | 'external-auth-facebook-oidc'
| 'everything-ok'
interface MessageWithLevel {
level: 'info' | 'warning' | 'error'
@ -15,7 +17,7 @@ export interface TestResult {
title: string
message: string
}>
next: nextValue | null
next: NextValue | null
ok: boolean
test: string
}