Fix external on logout hook

pull/3888/head
Chocobozzz 2021-03-12 17:19:02 +01:00
parent c2bd7a6fcf
commit 97aeb3cc46
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 9 additions and 3 deletions

View 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)
}

View 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)