]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix external on logout hook
authorChocobozzz <me@florianbigard.com>
Fri, 12 Mar 2021 16:19:02 +0000 (17:19 +0100)
committerChocobozzz <me@florianbigard.com>
Wed, 24 Mar 2021 17:18:41 +0000 (18:18 +0100)
server/controllers/api/users/token.ts
server/lib/auth/oauth-model.ts

index 3eae28b34b9242515e4cef915697be3d1f68eaa5..694bb0a9294130bfbc9905fb8b0f82c5b7c9c671 100644 (file)
@@ -88,7 +88,7 @@ async function handleToken (req: express.Request, res: express.Response, next: e
 async function handleTokenRevocation (req: express.Request, res: express.Response) {
   const token = res.locals.oauth.token
 
-  const result = await revokeToken(token, true)
+  const result = await revokeToken(token, { req, explicitLogout: true })
 
   return res.json(result)
 }
index c74869ee25cc8e70a1b67587503ef47bdf7d43c8..b9c69eb2db59f4b2fb7fd8dbc834ae2b8a889e34 100644 (file)
@@ -1,3 +1,4 @@
+import * as express from 'express'
 import { AccessDeniedError } from 'oauth2-server'
 import { PluginManager } from '@server/lib/plugins/plugin-manager'
 import { ActorModel } from '@server/models/activitypub/actor'
@@ -125,15 +126,20 @@ async function getUser (usernameOrEmail?: string, password?: string, bypassLogin
 
 async function revokeToken (
   tokenInfo: { refreshToken: string },
-  explicitLogout?: boolean
+  options: {
+    req?: express.Request
+    explicitLogout?: boolean
+  } = {}
 ): Promise<{ success: boolean, redirectUrl?: string }> {
+  const { req, explicitLogout } = options
+
   const token = await OAuthTokenModel.getByRefreshTokenAndPopulateUser(tokenInfo.refreshToken)
 
   if (token) {
     let redirectUrl: string
 
     if (explicitLogout === true && token.User.pluginAuth && token.authName) {
-      redirectUrl = await PluginManager.Instance.onLogout(token.User.pluginAuth, token.authName, token.User, this.request)
+      redirectUrl = await PluginManager.Instance.onLogout(token.User.pluginAuth, token.authName, token.User, req)
     }
 
     TokensCache.Instance.clearCacheByToken(token.accessToken)