aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/oauth-model.ts
diff options
context:
space:
mode:
authorChocobozzz <chocobozzz@framasoft.org>2020-11-20 15:36:43 +0100
committerChocobozzz <chocobozzz@framasoft.org>2020-11-20 15:36:43 +0100
commit74fd2643b43057c25558b3da79398efe104e2660 (patch)
tree4fd7dd84775780eed82bc4b3caaa328c3526a14c /server/lib/oauth-model.ts
parent8f3ad70874f8769f5340632754dc2ca7f4c82733 (diff)
downloadPeerTube-74fd2643b43057c25558b3da79398efe104e2660.tar.gz
PeerTube-74fd2643b43057c25558b3da79398efe104e2660.tar.zst
PeerTube-74fd2643b43057c25558b3da79398efe104e2660.zip
Provide express request to onLogout call
+ pluginInfo related changes
Diffstat (limited to 'server/lib/oauth-model.ts')
-rw-r--r--server/lib/oauth-model.ts10
1 files changed, 6 insertions, 4 deletions
diff --git a/server/lib/oauth-model.ts b/server/lib/oauth-model.ts
index 3273c6c2d..f7ea98b41 100644
--- a/server/lib/oauth-model.ts
+++ b/server/lib/oauth-model.ts
@@ -141,13 +141,15 @@ async function getUser (usernameOrEmail?: string, password?: string) {
141 return user 141 return user
142} 142}
143 143
144async function revokeToken (tokenInfo: { refreshToken: string }) { 144async function revokeToken (tokenInfo: { refreshToken: string }): Promise<{ success: boolean, redirectUrl?: string }> {
145 const res: express.Response = this.request.res 145 const res: express.Response = this.request.res
146 const token = await OAuthTokenModel.getByRefreshTokenAndPopulateUser(tokenInfo.refreshToken) 146 const token = await OAuthTokenModel.getByRefreshTokenAndPopulateUser(tokenInfo.refreshToken)
147 147
148 if (token) { 148 if (token) {
149 let redirectUrl: string
150
149 if (res.locals.explicitLogout === true && token.User.pluginAuth && token.authName) { 151 if (res.locals.explicitLogout === true && token.User.pluginAuth && token.authName) {
150 PluginManager.Instance.onLogout(token.User.pluginAuth, token.authName, token.User) 152 redirectUrl = await PluginManager.Instance.onLogout(token.User.pluginAuth, token.authName, token.User, this.request)
151 } 153 }
152 154
153 clearCacheByToken(token.accessToken) 155 clearCacheByToken(token.accessToken)
@@ -155,10 +157,10 @@ async function revokeToken (tokenInfo: { refreshToken: string }) {
155 token.destroy() 157 token.destroy()
156 .catch(err => logger.error('Cannot destroy token when revoking token.', { err })) 158 .catch(err => logger.error('Cannot destroy token when revoking token.', { err }))
157 159
158 return true 160 return { success: true, redirectUrl }
159 } 161 }
160 162
161 return false 163 return { success: false }
162} 164}
163 165
164async function saveToken (token: TokenInfo, client: OAuthClientModel, user: UserModel) { 166async function saveToken (token: TokenInfo, client: OAuthClientModel, user: UserModel) {