@@ -62,7 +62,7 @@ export class JoseUtil {
62
62
}
63
63
}
64
64
65
- static _validateJwt ( jwt , key , issuer , audience , clockSkew , now ) {
65
+ static validateJwtAttributes ( jwt , issuer , audience , clockSkew , now ) {
66
66
if ( ! clockSkew ) {
67
67
clockSkew = 0 ;
68
68
}
@@ -91,6 +91,10 @@ export class JoseUtil {
91
91
Log . error ( "JoseUtil._validateJwt: Invalid audience in token" , payload . aud ) ;
92
92
return Promise . reject ( new Error ( "Invalid audience in token: " + payload . aud ) ) ;
93
93
}
94
+ if ( payload . azp && payload . azp !== audience ) {
95
+ Log . error ( "JoseUtil._validateJwt: Invalid azp in token" , payload . azp ) ;
96
+ return Promise . reject ( new Error ( "Invalid azp in token: " + payload . azp ) ) ;
97
+ }
94
98
95
99
var lowerNow = now + clockSkew ;
96
100
var upperNow = now - clockSkew ;
@@ -118,18 +122,25 @@ export class JoseUtil {
118
122
return Promise . reject ( new Error ( "exp is in the past:" + payload . exp ) ) ;
119
123
}
120
124
121
- try {
122
- if ( ! jws . JWS . verify ( jwt , key , AllowedSigningAlgs ) ) {
123
- Log . error ( "JoseUtil._validateJwt: signature validation failed" ) ;
125
+ return Promise . resolve ( payload ) ;
126
+ }
127
+
128
+ static _validateJwt ( jwt , key , issuer , audience , clockSkew , now ) {
129
+
130
+ return JoseUtil . validateJwtAttributes ( jwt , issuer , audience , clockSkew , now ) . then ( payload => {
131
+ try {
132
+ if ( ! jws . JWS . verify ( jwt , key , AllowedSigningAlgs ) ) {
133
+ Log . error ( "JoseUtil._validateJwt: signature validation failed" ) ;
134
+ return Promise . reject ( new Error ( "signature validation failed" ) ) ;
135
+ }
136
+
137
+ return payload ;
138
+ }
139
+ catch ( e ) {
140
+ Log . error ( e && e . message || e ) ;
124
141
return Promise . reject ( new Error ( "signature validation failed" ) ) ;
125
142
}
126
- }
127
- catch ( e ) {
128
- Log . error ( e && e . message || e ) ;
129
- return Promise . reject ( new Error ( "signature validation failed" ) ) ;
130
- }
131
-
132
- return Promise . resolve ( ) ;
143
+ } ) ;
133
144
}
134
145
135
146
static hashString ( value , alg ) {
0 commit comments