This repository has been archived by the owner on Feb 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add AUTH_TYPE env * made open api auth conditional * refactor auth location * use test.env * conditional security handlers and auth envs * helm auth ifs
- Loading branch information
1 parent
a393eed
commit 822d899
Showing
17 changed files
with
181 additions
and
125 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
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,64 @@ | ||
const jwksRsa = require('jwks-rsa') | ||
const jwt = require('jsonwebtoken') | ||
|
||
const { AUTH_JWKS_URI, AUTH_AUDIENCE, AUTH_ISSUER, AUTH_TYPE } = require('../env') | ||
const logger = require('../logger') | ||
|
||
const client = jwksRsa({ | ||
cache: true, | ||
rateLimit: true, | ||
jwksRequestsPerMinute: 5, | ||
jwksUri: AUTH_JWKS_URI, | ||
}) | ||
|
||
async function getKey(header, cb) { | ||
client.getSigningKey(header.kid, (err, key) => { | ||
if (err) { | ||
logger.warn(`An error occurred getting jwks key ${err}`) | ||
cb(err, null) | ||
} else if (key) { | ||
const signingKey = key.publicKey || key.rsaPublicKey | ||
cb(null, signingKey) | ||
} | ||
}) | ||
} | ||
|
||
const verifyJwks = async (authHeader) => { | ||
const authToken = authHeader ? authHeader.replace('Bearer ', '') : '' | ||
|
||
const verifyOptions = { | ||
audience: AUTH_AUDIENCE, | ||
issuer: [AUTH_ISSUER], | ||
algorithms: ['RS256'], | ||
header: authToken, | ||
} | ||
|
||
return new Promise((resolve, reject) => { | ||
jwt.verify(authToken, getKey, verifyOptions, (err, decoded) => { | ||
if (err) { | ||
resolve(false) | ||
} else if (decoded) { | ||
resolve(true) | ||
} else { | ||
logger.warn(`Error verifying jwks`) | ||
reject({ message: 'An error occurred during jwks verification' }) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
const getDefaultSecurity = () => { | ||
switch (AUTH_TYPE) { | ||
case 'NONE': | ||
return [] | ||
case 'JWT': | ||
return [{ bearerAuth: [] }] | ||
default: | ||
return [] | ||
} | ||
} | ||
|
||
module.exports = { | ||
verifyJwks, | ||
getDefaultSecurity, | ||
} |
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
Oops, something went wrong.