30 lines
617 B
Go
30 lines
617 B
Go
package v1
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func containsValue(m map[string]string, value string) (string, error) {
|
|
for _, v := range m {
|
|
if v == value {
|
|
return v, nil
|
|
}
|
|
}
|
|
return value, errors.New("value is not in the provided map")
|
|
}
|
|
|
|
func (h *Handler) VerifyAuthentication(ctx *gin.Context) (string, error) {
|
|
header := ctx.GetHeader("X-API-KEY")
|
|
if header != "" {
|
|
return containsValue(h.services.Config.Auth.ApiKeys, header)
|
|
}
|
|
|
|
key := ctx.Query("api_key")
|
|
if key != "" {
|
|
return containsValue(h.services.Config.Auth.ApiKeys, key)
|
|
}
|
|
|
|
return "", errors.New("Missing API key")
|
|
}
|