X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fauth.ts;h=3f8e186334bef7d6b01eb79b6a015ab6cad7bfe7;hb=284ef529113ad61de30ff30a28c699b97d9ca02f;hp=1fa896f6ef6ec9324f3b497c1ea1f82ed7cb3f77;hpb=dadc90bca257f2d785713a37949c3a1bf6a5243d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/auth.ts b/server/lib/auth.ts index 1fa896f6e..3f8e18633 100644 --- a/server/lib/auth.ts +++ b/server/lib/auth.ts @@ -10,7 +10,7 @@ import { RegisterServerAuthenticatedResult, RegisterServerAuthPassOptions, RegisterServerExternalAuthenticatedResult -} from '@shared/models/plugins/register-server-auth.model' +} from '@server/types/plugins/register-server-auth.model' import * as express from 'express' import * as OAuthServer from 'express-oauth-server' @@ -83,10 +83,13 @@ async function onExternalUserAuthenticated (options: { return } - if (!isAuthResultValid(npmName, authName, authResult)) return - const { res } = authResult + if (!isAuthResultValid(npmName, authName, authResult)) { + res.redirect('/login?externalAuthError=true') + return + } + logger.info('Generating auth bypass token for %s in auth %s of plugin %s.', authResult.username, authName, npmName) const bypassToken = await generateRandomString(32) @@ -102,6 +105,14 @@ async function onExternalUserAuthenticated (options: { authName }) + // Cleanup + const now = new Date() + for (const [ key, value ] of authBypassTokens) { + if (value.expires.getTime() < now.getTime()) { + authBypassTokens.delete(key) + } + } + res.redirect(`/login?externalAuthToken=${bypassToken}&username=${user.username}`) } @@ -238,24 +249,27 @@ function proxifyExternalAuthBypass (req: express.Request, res: express.Response) function isAuthResultValid (npmName: string, authName: string, result: RegisterServerAuthenticatedResult) { if (!isUserUsernameValid(result.username)) { - logger.error('Auth method %s of plugin %s did not provide a valid username.', authName, npmName, { result }) + logger.error('Auth method %s of plugin %s did not provide a valid username.', authName, npmName, { username: result.username }) return false } if (!result.email) { - logger.error('Auth method %s of plugin %s did not provide a valid email.', authName, npmName, { result }) + logger.error('Auth method %s of plugin %s did not provide a valid email.', authName, npmName, { email: result.email }) return false } // role is optional if (result.role && !isUserRoleValid(result.role)) { - logger.error('Auth method %s of plugin %s did not provide a valid role.', authName, npmName, { result }) + logger.error('Auth method %s of plugin %s did not provide a valid role.', authName, npmName, { role: result.role }) return false } // display name is optional if (result.displayName && !isUserDisplayNameValid(result.displayName)) { - logger.error('Auth method %s of plugin %s did not provide a valid display name.', authName, npmName, { result }) + logger.error( + 'Auth method %s of plugin %s did not provide a valid display name.', + authName, npmName, { displayName: result.displayName } + ) return false }