-
Notifications
You must be signed in to change notification settings - Fork 9
/
auth.go
58 lines (49 loc) · 1.07 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package auth
import (
"github.com/gin-gonic/gin"
"hfrd/api/resource/auth/interfaces"
"hfrd/api/resource/auth/jwt"
"hfrd/api/resource/auth/jwt/jwk"
"hfrd/api/utils"
"hfrd/api/utils/hfrdlogging"
"strings"
)
const (
JWT = "jwt"
)
var (
logger = hfrdlogging.MustGetLogger(hfrdlogging.MODULE_AUTH)
nonAuth = &NonAuth{}
authEnabled bool
authType string
)
func init() {
if enabled, ok := utils.GetValue("auth.enabled").(bool); ok {
authEnabled = enabled
}
if auth, ok := utils.GetValue("auth.type").(string); ok {
authType = auth
}
}
func Auth() interfaces.Auth {
if !authEnabled {
logger.Info("Auth is disabled")
return nonAuth
}
logger.Infof("Auth type from configuration: \"%s\"", authType)
switch strings.ToLower(authType) {
case JWT:
return jwt.NewJwtAuth(jwk.NewIbmJwksManager())
default:
// Unsupported auth type
logger.Warningf("Unsupported auth type: \"%s\"", authType)
return nonAuth
}
}
type NonAuth struct {
}
func (nonAuth *NonAuth) Handler() func(*gin.Context) {
return func(*gin.Context) {}
}
func (NonAuth *NonAuth) Stop() {
}