@@ -53,18 +53,19 @@ export class AzureServiceWorkflow extends ServiceWorkflow {
53
53
throw new MongoAzureError ( TOKEN_AUDIENCE_MISSING_ERROR ) ;
54
54
}
55
55
let token ;
56
+ let response ;
56
57
const entry = this . cache . getEntry ( tokenAudience ) ;
57
58
if ( entry ?. isValid ( ) ) {
58
59
token = entry . token ;
59
60
} else {
60
61
this . cache . deleteEntry ( tokenAudience ) ;
61
- const response = await getAzureTokenData ( tokenAudience ) ;
62
+ response = await getAzureTokenData ( tokenAudience ) ;
62
63
console . log ( 'response' , response ) ;
63
64
this . cache . addEntry ( tokenAudience , response ) ;
64
65
token = response . access_token ;
65
66
}
66
67
console . log ( 'token' , token ) ;
67
- if ( isEndpointResultInvalid ( token ) ) {
68
+ if ( isEndpointResultInvalid ( response ) ) {
68
69
this . cache . deleteEntry ( tokenAudience ) ;
69
70
throw new MongoAzureError ( ENDPOINT_RESULT_ERROR ) ;
70
71
}
@@ -88,9 +89,9 @@ async function getAzureTokenData(tokenAudience: string): Promise<AzureAccessToke
88
89
/**
89
90
* Determines if a result returned from the endpoint is invalid.
90
91
* This means the result is nullish, doesn't contain the access_token required field,
91
- * the expires_in required field, and does not contain extra fields .
92
+ * the expires_in required field.
92
93
*/
93
94
function isEndpointResultInvalid ( token : unknown ) : boolean {
94
95
if ( token == null || typeof token !== 'object' ) return true ;
95
- return ! ( 'access_token' in token ) || ! ( 'expires_in' in token ) ;
96
+ return ! ( 'access_token' in token ) && ! ( 'expires_in' in token ) ;
96
97
}
0 commit comments