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

@ -21,8 +21,8 @@ async function initAuthApiRouter (options: RegisterServerOptions, router: Router
const token = req.header('X-Peertube-Plugin-Livechat-External-Auth-OIDC-Token')
if (token) {
try {
const oidc = ExternalAuthOIDC.singleton()
if (await oidc.isOk()) {
const oidc = ExternalAuthOIDC.singletonForToken(token)
if (oidc && await oidc.isOk()) {
const unserializedToken = await oidc.unserializeToken(token)
if (unserializedToken) {
res.status(200).json({

View File

@ -36,11 +36,12 @@ async function initOIDCRouter (options: RegisterServerOptions): Promise<Router>
const router = getRouter()
const logger = peertubeHelpers.logger
router.get('/connect', asyncMiddleware(
router.get('/:type?/connect', asyncMiddleware(
async (req: Request, res: Response, next: NextFunction) => {
logger.info('[oidc router] OIDC connect call')
const singletonType = req.params.type ?? 'custom'
logger.info('[oidc router] OIDC connect call (' + singletonType + ')')
try {
const oidc = ExternalAuthOIDC.singleton()
const oidc = ExternalAuthOIDC.singleton(singletonType)
const oidcClient = await oidc.load()
if (!oidcClient) {
throw new Error('[oidc router] External Auth OIDC not loaded yet')
@ -57,9 +58,10 @@ async function initOIDCRouter (options: RegisterServerOptions): Promise<Router>
const cbHandler = asyncMiddleware(
async (req: Request, res: Response, _next: NextFunction) => {
logger.info('[oidc router] OIDC callback call')
const singletonType = req.params.type ?? 'custom'
logger.info('[oidc router] OIDC callback call (' + singletonType + ')')
try {
const oidc = ExternalAuthOIDC.singleton()
const oidc = ExternalAuthOIDC.singleton(singletonType)
const oidcClient = await oidc.load()
if (!oidcClient) {
throw new Error('[oidc router] External Auth OIDC not loaded yet')
@ -102,8 +104,8 @@ async function initOIDCRouter (options: RegisterServerOptions): Promise<Router>
}
}
)
router.get('/cb', cbHandler)
router.post('/cb', cbHandler)
router.get('/:type?/cb', cbHandler)
router.post('/:type?/cb', cbHandler)
return router
}