Browse Source

Client calls revoke-token endpoint on logout

Chocobozzz 4 years ago
parent
commit
dadc90bca2
3 changed files with 14 additions and 3 deletions
  1. 12 1
      client/src/app/core/auth/auth.service.ts
  2. 1 1
      server/controllers/plugins.ts
  3. 1 1
      server/lib/auth.ts

+ 12 - 1
client/src/app/core/auth/auth.service.ts

@@ -29,6 +29,7 @@ type UserLoginWithUserInformation = UserLoginWithUsername & User
 export class AuthService {
   private static BASE_CLIENT_URL = environment.apiUrl + '/api/v1/oauth-clients/local'
   private static BASE_TOKEN_URL = environment.apiUrl + '/api/v1/users/token'
+  private static BASE_REVOKE_TOKEN_URL = environment.apiUrl + '/api/v1/users/revoke-token'
   private static BASE_USER_INFORMATION_URL = environment.apiUrl + '/api/v1/users/me'
   private static LOCAL_STORAGE_OAUTH_CLIENT_KEYS = {
     CLIENT_ID: 'client_id',
@@ -170,7 +171,17 @@ export class AuthService {
   }
 
   logout () {
-    // TODO: make an HTTP request to revoke the tokens
+    const authHeaderValue = this.getRequestHeaderValue()
+    const headers = new HttpHeaders().set('Authorization', authHeaderValue)
+
+    this.http.post<void>(AuthService.BASE_REVOKE_TOKEN_URL, {}, { headers })
+    .subscribe(
+      () => { /* nothing to do */ },
+
+      err => console.error(err)
+    )
+
+
     this.user = null
 
     AuthUser.flush()

+ 1 - 1
server/controllers/plugins.ts

@@ -149,6 +149,6 @@ function handleAuthInPlugin (req: express.Request, res: express.Response) {
     logger.debug('Forwarding auth plugin request in %s of plugin %s.', authOptions.authName, res.locals.registeredPlugin.npmName)
     authOptions.onAuthRequest(req, res)
   } catch (err) {
-    logger.error('Forward request error in auth %s of plugin %s.', authOptions.authName, res.locals.registeredPlugin.npmName)
+    logger.error('Forward request error in auth %s of plugin %s.', authOptions.authName, res.locals.registeredPlugin.npmName, { err })
   }
 }

+ 1 - 1
server/lib/auth.ts

@@ -68,7 +68,7 @@ async function handleTokenRevocation (req: express.Request, res: express.Respons
   //   }
   // })
 
-  return res.sendStatus(200)
+  return res.json()
 }
 
 async function onExternalUserAuthenticated (options: {