Skip to content
Snippets Groups Projects
Commit cbaa5d08 authored by Jano Hendriks's avatar Jano Hendriks
Browse files

Add new auth package for bob API keys, and move oauth package to oauth folder

parent 542e4c81
No related branches found
No related tags found
No related merge requests found
package auth
import (
"github.com/google/uuid"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/utils"
"strings"
)
// GenerateNewApiKey generates a 32 character API key. If the build environment is dev or stage the key will start with
// "dev_" or "stage_" respectively.
func GenerateNewApiKey() string {
uniqueKey := uuid.New().String()
uniqueKey = strings.ReplaceAll(uniqueKey, "-", "")
env := utils.GetEnv("ENVIRONMENT", "")
if env == "dev" || env == "stage" {
uniqueKey = env + "_" + uniqueKey
}
return uniqueKey
}
// GetApiKeyFromHeaders checks if a bearer token is passed as part of the Authorization header and returns that key
func GetApiKeyFromHeaders(headers map[string]string) string {
key := headers["Authorization"]
if strings.HasPrefix(strings.ToLower(key), "bearer ") {
return strings.TrimPrefix(strings.ToLower(key), "bearer")
}
return ""
}
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment