9 // Claims type that uses the map[string]interface{} for JSON decoding
10 // This is the default claims type if you don't supply one
11 type MapClaims map[string]interface{}
13 // Compares the aud claim against cmp.
14 // If required is false, this method will return true if the value matches or is unset
15 func (m MapClaims) VerifyAudience(cmp string, req bool) bool {
16 aud, _ := m["aud"].(string)
17 return verifyAud(aud, cmp, req)
20 // Compares the exp claim against cmp.
21 // If required is false, this method will return true if the value matches or is unset
22 func (m MapClaims) VerifyExpiresAt(cmp int64, req bool) bool {
23 switch exp := m["exp"].(type) {
25 return verifyExp(int64(exp), cmp, req)
28 return verifyExp(v, cmp, req)
33 // Compares the iat claim against cmp.
34 // If required is false, this method will return true if the value matches or is unset
35 func (m MapClaims) VerifyIssuedAt(cmp int64, req bool) bool {
36 switch iat := m["iat"].(type) {
38 return verifyIat(int64(iat), cmp, req)
41 return verifyIat(v, cmp, req)
46 // Compares the iss claim against cmp.
47 // If required is false, this method will return true if the value matches or is unset
48 func (m MapClaims) VerifyIssuer(cmp string, req bool) bool {
49 iss, _ := m["iss"].(string)
50 return verifyIss(iss, cmp, req)
53 // Compares the nbf claim against cmp.
54 // If required is false, this method will return true if the value matches or is unset
55 func (m MapClaims) VerifyNotBefore(cmp int64, req bool) bool {
56 switch nbf := m["nbf"].(type) {
58 return verifyNbf(int64(nbf), cmp, req)
61 return verifyNbf(v, cmp, req)
66 // Validates time based claims "exp, iat, nbf".
67 // There is no accounting for clock skew.
68 // As well, if any of the above claims are not in the token, it will still
69 // be considered a valid claim.
70 func (m MapClaims) Valid() error {
71 vErr := new(ValidationError)
72 now := TimeFunc().Unix()
74 if m.VerifyExpiresAt(now, false) == false {
75 vErr.Inner = errors.New("Token is expired")
76 vErr.Errors |= ValidationErrorExpired
79 if m.VerifyIssuedAt(now, false) == false {
80 vErr.Inner = errors.New("Token used before issued")
81 vErr.Errors |= ValidationErrorIssuedAt
84 if m.VerifyNotBefore(now, false) == false {
85 vErr.Inner = errors.New("Token is not valid yet")
86 vErr.Errors |= ValidationErrorNotValidYet