This repository has been archived by the owner on Dec 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40ac74c
commit 389487a
Showing
10 changed files
with
319 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { ServerResponse, IncomingMessage } from 'http'; | ||
import { $log } from 'ts-log-debug'; | ||
import { extractAccessToken } from '../utils/RequestUtil'; | ||
import { sendError } from '../utils/ResponseUtil'; | ||
import { sendJSONResponse } from '../utils/ResponseUtil'; | ||
import { JWT } from '../models/JWT'; | ||
import { findResourceByPathAndMethod } from '../utils/ResourceUtils'; | ||
import { parse } from 'url'; | ||
|
||
const handler = async (req: IncomingMessage, res: ServerResponse) => { | ||
$log.debug('Handling logout request'); | ||
const { path, method } = parse(req.url, true).query; | ||
|
||
if (!path) { | ||
return await sendError(res, 400, '"path" query parameter is missing'); | ||
} | ||
|
||
if (!method) { | ||
return await sendError(res, 400, '"method" query parameter is missing'); | ||
} | ||
|
||
const targetPath = findResourceByPathAndMethod(path.toString(), method.toString()); | ||
|
||
if (!targetPath) { | ||
return await sendError(res, 404, 'Mapping not found'); | ||
} | ||
|
||
if (!targetPath.resource.public) { | ||
const accessToken = extractAccessToken(req); | ||
|
||
if (!accessToken) { | ||
return await sendJSONResponse(res, { | ||
allowed: false, | ||
}); | ||
} | ||
|
||
const jwtToken = new JWT(accessToken); | ||
if (targetPath.resource.roles) { | ||
if (!jwtToken.verifyRoles(targetPath.resource.roles)) { | ||
return await sendJSONResponse(res, { | ||
allowed: false, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
return await sendJSONResponse(res, { | ||
allowed: true, | ||
}); | ||
}; | ||
|
||
export default handler; |
Oops, something went wrong.