-
Notifications
You must be signed in to change notification settings - Fork 1
/
auth.go
37 lines (30 loc) · 1.01 KB
/
auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package goutils
import (
"fmt"
"strings"
)
var clientSecrets map[string]string
// Load client secrets from environment variables
func EnableAPISecretKeys() {
apiClients := Env("API_CLIENTS", []string{})
if len(apiClients) != 0 {
fmt.Printf("\r\n┌─────── CLIENT_SECRET: ─────────\r\n")
clientSecrets = make(map[string]string)
for _, client := range apiClients {
clientSecrets[client] = Env(fmt.Sprintf("API_%s_SECRET", strings.TrimSpace(strings.ToUpper(client))), "")
fmt.Printf("│ %s: %s\r\n", client, clientSecrets[client])
}
fmt.Println("└──────────────────────────────────────")
}
}
// Check an API secret key is valid or not
func CheckAPISecretKey(apiKey string) error {
key, err := Decrypt(apiKey)
if err != nil {
return fmt.Errorf("error decrypting your classified --> %v", err)
}
if _, ok := clientSecrets[key]; ok {
return nil
}
return fmt.Errorf("secret key not found")
}