-
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.
Merge branch '355-api_key' into 'dev'
add api_key middleware for sign route Closes #355 See merge request ergo/rosen-bridge/guard-service!312
- Loading branch information
Showing
7 changed files
with
110 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { blake2b } from 'blakejs'; | ||
import { Buffer } from 'buffer'; | ||
import Configs from '../configs/Configs'; | ||
import { FastifyReply, FastifyRequest } from 'fastify'; | ||
import { HookHandlerDoneFunction } from 'fastify/types/hooks'; | ||
|
||
const authenticateKey = <T extends FastifyRequest, U extends FastifyReply>( | ||
req: T, | ||
res: U, | ||
next: HookHandlerDoneFunction | ||
) => { | ||
const api_key: string = req.headers.api_key as string; | ||
if ( | ||
api_key && | ||
Buffer.from(blake2b(api_key, undefined, 32)).toString('hex') == | ||
Configs.apiKeyHash | ||
) { | ||
next(); | ||
} else { | ||
res.status(403).send({ message: "API_KEY doesn't exist or it's wrong" }); | ||
} | ||
}; | ||
|
||
export { authenticateKey }; |
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