auth

Main authentication module for my projects
git clone git://git.finwo.net/app/auth
Log | Files | Refs

revoke-realm.js (1067B)


      1 import { app } from '../../../app.js';
      2 import { authenticateAdminRequest } from '../../../lib/admin-auth.js';
      3 import { findAdminRealmSession } from '../../../lib/admin-sessions.js';
      4 import { HttpError } from '../../../lib/http/http-error.js';
      5 import { revokeSessionRealm } from '../../../lib/session.js';
      6 
      7 export default {
      8   method: 'delete',
      9   path: '/api/v1/admin/realms/:realm/sessions/:publicId/realm',
     10   name: 'admin.sessions.revoke-realm',
     11   async handler(req) {
     12     const auth = await authenticateAdminRequest(req, {
     13       realmSlug: req.params.realm,
     14     });
     15     const session = await findAdminRealmSession(auth.systemDb, {
     16       realmId: auth.realm.id,
     17       publicId: req.params.publicId,
     18     });
     19     if (!session) {
     20       throw new HttpError(404, 'session_not_found', 'Session not found');
     21     }
     22 
     23     const binding = await revokeSessionRealm(auth.systemDb, {
     24       sessionId: session.id,
     25       realmId: auth.realm.id,
     26       revokedBy: auth.user.id,
     27     });
     28 
     29     return new app.HttpOk({
     30       ok: true,
     31       revoked_at: binding.revoked_at,
     32     });
     33   },
     34 };