@@ -34,30 +34,38 @@ func (m MapClaims) VerifyAudience(cmp string, req bool) bool {
34
34
// Compares the exp claim against cmp.
35
35
// If required is false, this method will return true if the value matches or is unset
36
36
func (m MapClaims ) VerifyExpiresAt (cmp int64 , req bool ) bool {
37
- switch exp := m ["exp" ].(type ) {
37
+ exp , ok := m ["exp" ]
38
+ if ! ok {
39
+ return ! req
40
+ }
41
+ switch expType := exp .(type ) {
38
42
case float64 :
39
- return verifyExp (int64 (exp ), cmp , req )
43
+ return verifyExp (int64 (expType ), cmp , req )
40
44
case json.Number :
41
- v , _ := exp .Int64 ()
45
+ v , _ := expType .Int64 ()
42
46
return verifyExp (v , cmp , req )
43
47
}
44
- return ! req
48
+ return false
45
49
}
46
50
47
51
// Compares the iat claim against cmp.
48
52
// If required is false, this method will return true if the value matches or is unset
49
53
func (m MapClaims ) VerifyIssuedAt (cmp int64 , req bool ) bool {
50
- switch iat := m ["iat" ].(type ) {
54
+ iat , ok := m ["iat" ]
55
+ if ! ok {
56
+ return ! req
57
+ }
58
+ switch iatType := iat .(type ) {
51
59
case float64 :
52
- return verifyIat (int64 (iat ), cmp , req )
60
+ return verifyIat (int64 (iatType ), cmp , req )
53
61
case json.Number :
54
- v , _ := iat .Int64 ()
62
+ v , _ := iatType .Int64 ()
55
63
return verifyIat (v , cmp , req )
56
64
}
57
- return ! req
65
+ return false
58
66
}
59
67
60
- // Compares the iss claim against cmp.
68
+ // Compares the iss claim against cmp.``
61
69
// If required is false, this method will return true if the value matches or is unset
62
70
func (m MapClaims ) VerifyIssuer (cmp string , req bool ) bool {
63
71
iss , _ := m ["iss" ].(string )
@@ -67,14 +75,18 @@ func (m MapClaims) VerifyIssuer(cmp string, req bool) bool {
67
75
// Compares the nbf claim against cmp.
68
76
// If required is false, this method will return true if the value matches or is unset
69
77
func (m MapClaims ) VerifyNotBefore (cmp int64 , req bool ) bool {
70
- switch nbf := m ["nbf" ].(type ) {
78
+ nbf , ok := m ["nbf" ]
79
+ if ! ok {
80
+ return ! req
81
+ }
82
+ switch nbfType := nbf .(type ) {
71
83
case float64 :
72
- return verifyNbf (int64 (nbf ), cmp , req )
84
+ return verifyNbf (int64 (nbfType ), cmp , req )
73
85
case json.Number :
74
- v , _ := nbf .Int64 ()
86
+ v , _ := nbfType .Int64 ()
75
87
return verifyNbf (v , cmp , req )
76
88
}
77
- return ! req
89
+ return false
78
90
}
79
91
80
92
// Validates time based claims "exp, iat, nbf".
0 commit comments