Files
directus/api/src/utils/is-directus-jwt.ts
Rijk van Zanten eea9f45624 Add authenticate hook to implement custom auth checks against current request (#11942)
* Add "authenticate" filter hook that allows custom auth check

* Start on test

* Update Jest, restructure API tests, start implementing authenticate test

* Move access token verify to util function

* Ensure jest can show inline warnings on correct lines

* Update is-directus-jwt to use jsonwebtoken decode + add tests

* Remove unused package

* Tweak and finish + test authenticate

* Tweak test

* Add authenticate filter to docs

* Don't scan tests for codeql

* No seriously, ignore tests
2022-03-03 16:29:13 -05:00

16 lines
366 B
TypeScript

import jwt from 'jsonwebtoken';
/**
* Check if a given string conforms to the structure of a JWT
* and whether it is issued by Directus.
*/
export default function isDirectusJWT(string: string): boolean {
try {
const payload = jwt.decode(string, { json: true });
if (payload?.iss !== 'directus') return false;
return true;
} catch {
return false;
}
}