Skip to content

Commit 189bb99

Browse files
author
Jonathan Turner
authored
[Identity] Bump msal-node dep (Azure#13179)
* Bump msal-node dependency and update package version * Bump msal-node dependency and update package version * Address feedback * Address feedback * Address feedback * Address feedback
1 parent 8ec4ed1 commit 189bb99

File tree

6 files changed

+383
-301
lines changed

6 files changed

+383
-301
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 338 additions & 278 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/identity/identity/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release History
22

3+
## 1.2.2 (2021-01-12)
4+
5+
- Upgrading to the msal-node dependency due to a severe vulnerability in Axios. Link to the documented vulnerability: [link](https://npmjs.com/advisories/1594). Fixes issue [13088](https://github.com/Azure/azure-sdk-for-js/issues/13088).
6+
37
## 1.2.1 (2021-01-07)
48

59
- Upgrading to Axios 0.21.1 due to a severe vulnerability in Axios. Link to the documented vulnerability: [link](https://npmjs.com/advisories/1594). Fixes issue [13088](https://github.com/Azure/azure-sdk-for-js/issues/13088).

sdk/identity/identity/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@azure/identity",
33
"sdk-type": "client",
4-
"version": "1.2.1",
4+
"version": "1.2.2",
55
"description": "Provides credential implementations for Azure SDK libraries that can authenticate with Azure Active Directory",
66
"main": "dist/index.js",
77
"module": "dist-esm/src/index.js",
@@ -83,7 +83,7 @@
8383
"@azure/core-http": "^1.2.0",
8484
"@azure/core-tracing": "1.0.0-preview.9",
8585
"@azure/logger": "^1.0.0",
86-
"@azure/msal-node": "1.0.0-beta.1",
86+
"@azure/msal-node": "1.0.0-beta.3",
8787
"@opentelemetry/api": "^0.10.2",
8888
"axios": "^0.21.1",
8989
"events": "^3.0.0",

sdk/identity/identity/src/client/msalClient.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,14 @@ export class MsalClient {
111111
try {
112112
const response = await this.pca!.acquireTokenSilent(silentRequest);
113113
logger.info("Successful silent token acquisition");
114-
return {
115-
expiresOnTimestamp: response.expiresOn.getTime(),
116-
token: response.accessToken
117-
};
114+
if (response && response.expiresOn) {
115+
return {
116+
expiresOnTimestamp: response.expiresOn.getTime(),
117+
token: response.accessToken
118+
};
119+
} else {
120+
throw new AuthenticationRequired("Could not authenticate silently using the cache");
121+
}
118122
} catch (e) {
119123
throw new AuthenticationRequired("Could not authenticate silently using the cache");
120124
}
@@ -126,21 +130,23 @@ export class MsalClient {
126130
return this.pca!.getAuthCodeUrl(request);
127131
}
128132

129-
async acquireTokenByCode(request: AuthorizationCodeRequest): Promise<AuthenticationResult> {
133+
async acquireTokenByCode(
134+
request: AuthorizationCodeRequest
135+
): Promise<AuthenticationResult | null> {
130136
await this.prepareClientApplications();
131137

132138
return this.pca!.acquireTokenByCode(request);
133139
}
134140

135-
async acquireTokenByDeviceCode(request: DeviceCodeRequest): Promise<AuthenticationResult> {
141+
async acquireTokenByDeviceCode(request: DeviceCodeRequest): Promise<AuthenticationResult | null> {
136142
await this.prepareClientApplications();
137143

138144
return this.pca!.acquireTokenByDeviceCode(request);
139145
}
140146

141147
async acquireTokenByClientCredential(
142148
request: ClientCredentialRequest
143-
): Promise<AuthenticationResult> {
149+
): Promise<AuthenticationResult | null> {
144150
await this.prepareClientApplications();
145151

146152
return this.cca!.acquireTokenByClientCredential(request);

sdk/identity/identity/src/credentials/deviceCodeCredential.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,16 @@ export class DeviceCodeCredential implements TokenCredential {
160160
): Promise<AccessToken | null> {
161161
try {
162162
const deviceResponse = await this.msalClient.acquireTokenByDeviceCode(deviceCodeRequest);
163-
const expiresOnTimestamp = deviceResponse.expiresOn.getTime();
164-
logger.getToken.info(formatSuccess(scopes));
165-
return {
166-
expiresOnTimestamp,
167-
token: deviceResponse.accessToken
168-
};
163+
if (deviceResponse && deviceResponse.expiresOn) {
164+
const expiresOnTimestamp = deviceResponse.expiresOn.getTime();
165+
logger.getToken.info(formatSuccess(scopes));
166+
return {
167+
expiresOnTimestamp,
168+
token: deviceResponse.accessToken
169+
};
170+
} else {
171+
throw new Error("Did not receive token with a valid expiration");
172+
}
169173
} catch (error) {
170174
throw new Error(`Device Authentication Error "${JSON.stringify(error)}"`);
171175
}

sdk/identity/identity/src/credentials/interactiveBrowserCredential.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,22 @@ export class InteractiveBrowserCredential implements TokenCredential {
137137
try {
138138
const authResponse = await this.msalClient.acquireTokenByCode(tokenRequest);
139139
const successMessage = `Authentication Complete. You can close the browser and return to the application.`;
140-
const expiresOnTimestamp = authResponse?.expiresOn.valueOf();
141-
res.status(200).send(successMessage);
142-
logger.getToken.info(formatSuccess(scopeArray));
143-
144-
resolve({
145-
expiresOnTimestamp,
146-
token: authResponse.accessToken
147-
});
140+
if (authResponse && authResponse.expiresOn) {
141+
const expiresOnTimestamp = authResponse?.expiresOn.valueOf();
142+
res.status(200).send(successMessage);
143+
logger.getToken.info(formatSuccess(scopeArray));
144+
145+
resolve({
146+
expiresOnTimestamp,
147+
token: authResponse.accessToken
148+
});
149+
} else {
150+
reject(
151+
new Error(
152+
`Interactive Browser Authentication Error "Did not receive token with a valid expiration"`
153+
)
154+
);
155+
}
148156
} catch (error) {
149157
const errorMessage = formatError(
150158
scopeArray,

0 commit comments

Comments
 (0)