-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: bearer token authentication for public APIs (#6376)
* feat: add user middleware * fix: use api key hash instead of api key * feat: add apiKeySalt as a new config * feat: add getApiKeyHash * chore: add API_KEY_SALT to docker-compose.yml * feat: add separate namespace for external apis * feat: add handleListDashboardForms to external APIs * docs: add comments to api auth functions * fix: add more env vars to config * feat: add rate limit env var * tests: add fake API key salt env var * fix: use salt rounds instead of salt to generate hash * fix: remove more occurrences of apiKeySalt * feat: findUserById instead of by hash * feat: add user ID to req.body.formSg.userId when authenticating with API token * ref: refine error states, move constants into separate file * fix: remove API_KEY_SALT from docker-compose * fix: split API Key in auth middleware * fix: type ReqBody as unknown * fix: update types for req body * ref: remove unused comment * fix: remove unique from apiKeyHash in user model * fix: remove extra test env file * ref: rename external to public * ref: rename external api to public api * fix: check length of api key * docs: add comments * ref: rename external to public * fix: check length * fix: fix typo * feat: use req.session to store user id * feat: Store API key in a structure * feat: increase number of salting round used for API token hashing * refactor: use local regexes to test auth header * chore: add TODO to update lastUseAt time * fix: retrieve user._id (not user.id) * fix: read keyHash from correct location in user * refactor: remove unecessary default value * fix: add dots to match bcrypt\'s base64 alphabet Documentation on base64 and bcrypt encoding https://en.wikipedia.org/wiki/Base64#Applications_not_compatible_with_RFC_4648_Base64 * refactor: rename mapRouteExternalApiError into mapRoutePublicApiError * feat: allow retrieving submissions by api --------- Co-authored-by: Timothee Groleau <[email protected]>
- Loading branch information
Showing
19 changed files
with
315 additions
and
2 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
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 @@ | ||
export const DEFAULT_SALT_ROUNDS = 2 |
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,7 @@ | ||
import { Router } from 'express' | ||
|
||
import { AdminFormsPublicRouter } from './forms' | ||
|
||
export const AdminRouter = Router() | ||
|
||
AdminRouter.use('/forms', AdminFormsPublicRouter) |
Oops, something went wrong.