-
Notifications
You must be signed in to change notification settings - Fork 1
/
jwt.go
66 lines (51 loc) · 1.77 KB
/
jwt.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
59
60
61
62
63
64
65
66
package jwt
// secretCodeJWT is the global variable for default secret code
var secretCodeJWT = "54A3E4F19C28CCA4A27E5648871A6"
// useAuthorization is the variable for enable and disable authorization
var useAuthorization = true
// expiredHoursTime is the hours time for duration JWT token
var expiredHoursTime int64 = 1
// expiredMinutesTime is the minutes time for duration JWT token
var expiredMinutesTime int64 = 59
// expiredSecondsTime is the seconds time for duration JWT token
var expiredSecondsTime int64 = 60
// signingHMACMethod is a method for signing and validation JWT
var signingHMACMethod SigningHMAC = HS256()
// GetStringJWTSecretCode is to get JWT secret code as a string
func GetStringJWTSecretCode() string {
return secretCodeJWT
}
// GetJWTSecretCode get JWT secret code as a byte
func GetJWTSecretCode() []byte {
return []byte(secretCodeJWT)
}
// SetJWTSecretCode is to set JWT secret code globally
func SetJWTSecretCode(secretCode string) {
secretCodeJWT = secretCode
}
// IsUseAuthorization is to get status whether use authorization or not
func IsUseAuthorization() bool {
return useAuthorization
}
// EnableAuthorization is to enable authorization
func EnableAuthorization() {
useAuthorization = true
}
// DisableAuthorization is to Disable the authorization
func DisableAuthorization() {
useAuthorization = false
}
// SetExpiredTime is to set expired time for JWT session
func SetExpiredTime(hour int64, minute int64, second int64) {
expiredHoursTime = hour
expiredMinutesTime = minute
expiredSecondsTime = second
}
// SetHMACSigningMethod is to set signing method globally
func SetHMACSigningMethod(s SigningHMAC) {
signingHMACMethod = s
}
// GetHMACSigningMethod is to get signing method
func GetHMACSigningMethod() SigningHMAC {
return signingHMACMethod
}