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:
63
server/lib/diagnostic/external-auth-oidc.ts
Normal file
63
server/lib/diagnostic/external-auth-oidc.ts
Normal file
@ -0,0 +1,63 @@
|
||||
import type { RegisterServerOptions } from '@peertube/peertube-types'
|
||||
import { newResult, TestResult } from './utils'
|
||||
import { ExternalAuthOIDC, ExternalAuthOIDCType } from '../external-auth/oidc'
|
||||
|
||||
export async function diagExternalAuthOIDC (
|
||||
test: string,
|
||||
_options: RegisterServerOptions,
|
||||
singletonType: ExternalAuthOIDCType,
|
||||
next: TestResult['next']
|
||||
): Promise<TestResult> {
|
||||
const result = newResult(test)
|
||||
result.label = 'Test External Auth OIDC: ' + singletonType
|
||||
result.next = next
|
||||
|
||||
try {
|
||||
const oidc = ExternalAuthOIDC.singleton(singletonType)
|
||||
|
||||
if (oidc.isDisabledBySettings()) {
|
||||
result.ok = true
|
||||
result.messages.push('Feature disabled in plugins settings.')
|
||||
return result
|
||||
}
|
||||
|
||||
result.messages.push('Discovery URL: ' + (oidc.getDiscoveryUrl() ?? 'undefined'))
|
||||
|
||||
const oidcErrors = await oidc.check()
|
||||
if (oidcErrors.length) {
|
||||
result.messages.push({
|
||||
level: 'error',
|
||||
message: 'The ExternalAuthOIDC singleton got some errors:'
|
||||
})
|
||||
for (const oidcError of oidcErrors) {
|
||||
result.messages.push({
|
||||
level: 'error',
|
||||
message: oidcError
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
} catch (err) {
|
||||
result.messages.push({
|
||||
level: 'error',
|
||||
message: 'Error while retrieving the ExternalAuthOIDC singleton:' + (err as string)
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
const oidc = ExternalAuthOIDC.singleton(singletonType)
|
||||
const oidcClient = await oidc.load()
|
||||
if (oidcClient) {
|
||||
result.messages.push('Discovery URL loaded: ' + JSON.stringify(oidcClient.issuer.metadata))
|
||||
} else {
|
||||
result.messages.push({
|
||||
level: 'error',
|
||||
message: 'Failed to load the Discovery URL.'
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
result.ok = true
|
||||
result.messages.push('Configuration OK.')
|
||||
return result
|
||||
}
|
Reference in New Issue
Block a user