@@ -110,24 +110,32 @@ func (a *Algorithm) Decode(encoded string) (*Claims, error) {
110
110
111
111
// Validate verifies a tokens validity. It returns nil if it is valid, and an error if invalid.
112
112
func (a * Algorithm ) Validate (encoded string ) error {
113
- claims , err := a .Decode (encoded )
113
+ _ , err := a .DecodeAndValidate (encoded )
114
+ return err
115
+ }
116
+
117
+ // DecodeAndValidate returns a map representing the token's claims, and it's valid.
118
+ func (a * Algorithm ) DecodeAndValidate (encoded string ) (claims * Claims , err error ) {
119
+ claims , err = a .Decode (encoded )
114
120
if err != nil {
115
- return err
121
+ return
116
122
}
117
123
118
- if err := a .validateSignature (encoded ); err != nil {
119
- return errors .Wrap (err , "failed to validate signature" )
124
+ if err = a .validateSignature (encoded ); err != nil {
125
+ err = errors .Wrap (err , "failed to validate signature" )
126
+ return
120
127
}
121
128
122
- if err := a .validateExp (claims ); err != nil {
123
- return errors .Wrap (err , "failed to validate exp" )
129
+ if err = a .validateExp (claims ); err != nil {
130
+ err = errors .Wrap (err , "failed to validate exp" )
131
+ return
124
132
}
125
133
126
- if err : = a .validateNbf (claims ); err != nil {
127
- return errors .Wrap (err , "failed to validate nbf" )
134
+ if err = a .validateNbf (claims ); err != nil {
135
+ err = errors .Wrap (err , "failed to validate nbf" )
128
136
}
129
137
130
- return nil
138
+ return
131
139
}
132
140
133
141
func (a * Algorithm ) validateSignature (encoded string ) error {
@@ -152,7 +160,6 @@ func (a *Algorithm) validateSignature(encoded string) error {
152
160
return nil
153
161
}
154
162
155
-
156
163
func (a * Algorithm ) validateExp (claims * Claims ) error {
157
164
if claims .HasClaim ("exp" ) {
158
165
exp , err := claims .GetTime ("exp" )
0 commit comments