Refactors api key functionality
- API Key is now read from env file - API routes won't be set up if no API key is given via ENV file
This commit is contained in:
parent
86a7caa98f
commit
08c7c1f9fa
2 changed files with 22 additions and 9 deletions
|
|
@ -21,15 +21,17 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
func validateAPIKey(_ *fiber.Ctx, key string) (bool, error) {
|
||||
hashedAPIKey := sha256.Sum256([]byte(apiKey))
|
||||
hashedKey := sha256.Sum256([]byte(key))
|
||||
func apiKeyValidator(apiKey string) func(*fiber.Ctx, string) (bool, error) {
|
||||
return func(_ *fiber.Ctx, key string) (bool, error) {
|
||||
hashedAPIKey := sha256.Sum256([]byte(apiKey))
|
||||
hashedKey := sha256.Sum256([]byte(key))
|
||||
|
||||
if subtle.ConstantTimeCompare(hashedAPIKey[:], hashedKey[:]) == 1 {
|
||||
return true, nil
|
||||
if subtle.ConstantTimeCompare(hashedAPIKey[:], hashedKey[:]) == 1 {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, keyauth.ErrMissingOrMalformedAPIKey
|
||||
}
|
||||
|
||||
return false, keyauth.ErrMissingOrMalformedAPIKey
|
||||
}
|
||||
|
||||
func protectedRoutesFilter(ctx *fiber.Ctx) bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue