Skip to content

Commit

Permalink
Implemented GitHub Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rgins16 committed Jul 14, 2023
1 parent 422fcfc commit af74365
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 41 deletions.
1 change: 1 addition & 0 deletions lib/msal-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export {
ONE_DAY_IN_MS,
GrantType,
AADAuthorityConstants,
HttpStatus,
} from "./utils/Constants";
export { StringUtils } from "./utils/StringUtils";
export { StringDict } from "./utils/MsalTypes";
Expand Down
2 changes: 1 addition & 1 deletion lib/msal-common/src/response/AuthenticationResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type AuthenticationResult = {
fromCache: boolean;
expiresOn: Date | null;
extExpiresOn?: Date;
refreshOn: Date | null;
refreshOn?: Date;
tokenType: string;
correlationId: string;
requestId?: string;
Expand Down
20 changes: 11 additions & 9 deletions lib/msal-common/src/response/ResponseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
AuthenticationScheme,
Constants,
THE_FAMILY_ID,
ErrorCodeBounds,
HttpStatus,
} from "../utils/Constants";
import { PopTokenGenerator } from "../crypto/PopTokenGenerator";
import { AppMetadataEntity } from "../cache/entities/AppMetadataEntity";
Expand Down Expand Up @@ -169,8 +169,8 @@ export class ResponseHandler {
if (
refreshAccessToken &&
serverResponse.status &&
(serverResponse.status >= ErrorCodeBounds.stsErrorLowerLimit) &&
(serverResponse.status <= ErrorCodeBounds.stsErrorUpperLimit)
(serverResponse.status >= HttpStatus.SERVER_ERROR_RANGE_START) &&
(serverResponse.status <= HttpStatus.SERVER_ERROR_RANGE_END)
) {
this.logger.warning(
"executeTokenRequest:validateTokenResponse - AAD is currently unavailable and the access token is unable to be refreshed."
Expand All @@ -182,8 +182,8 @@ export class ResponseHandler {
} else if (
refreshAccessToken &&
serverResponse.status &&
(serverResponse.status >= ErrorCodeBounds.clientErrorLowerLimit) &&
(serverResponse.status <= ErrorCodeBounds.clientErrorUpperLimit)
(serverResponse.status >= HttpStatus.CLIENT_ERROR_RANGE_START) &&
(serverResponse.status <= HttpStatus.CLIENT_ERROR_RANGE_END)
) {
this.logger.warning(
"executeTokenRequest:validateTokenResponse - AAD is currently available but is unable to refresh the access token."
Expand Down Expand Up @@ -583,7 +583,7 @@ export class ResponseHandler {
let responseScopes: Array<string> = [];
let expiresOn: Date | null = null;
let extExpiresOn: Date | undefined;
let refreshOn: Date | null = null;
let refreshOn: Date | undefined;
let familyId: string = Constants.EMPTY_STRING;

if (cacheRecord.accessToken) {
Expand Down Expand Up @@ -615,9 +615,11 @@ export class ResponseHandler {
extExpiresOn = new Date(
Number(cacheRecord.accessToken.extendedExpiresOn) * 1000
);
refreshOn = new Date(
Number(cacheRecord.accessToken.refreshOn) * 1000
);
if (cacheRecord.accessToken.refreshOn) {
refreshOn = new Date(
Number(cacheRecord.accessToken.refreshOn) * 1000
);
}
}

if (cacheRecord.appMetadata) {
Expand Down
15 changes: 9 additions & 6 deletions lib/msal-common/src/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,16 @@ export const Constants = {
INVALID_INSTANCE: "invalid_instance",
};

export const ErrorCodeBounds = {
clientErrorLowerLimit: 400,
clientErrorUpperLimit: 499,
stsErrorLowerLimit: 500,
stsErrorUpperLimit: 599,
export const HttpStatus = {
SUCCESS_RANGE_START: 200,
SUCCESS_RANGE_END: 299,
REDIRECT: 302,
CLIENT_ERROR_RANGE_START: 400,
CLIENT_ERROR_RANGE_END: 499,
SERVER_ERROR_RANGE_START: 500,
SERVER_ERROR_RANGE_END: 599,
} as const;
export type ErrorCodeBounds = typeof ErrorCodeBounds[keyof typeof ErrorCodeBounds];
export type HttpStatus = typeof HttpStatus[keyof typeof HttpStatus];

export const OIDC_DEFAULT_SCOPES = [
Constants.OPENID_SCOPE,
Expand Down
10 changes: 0 additions & 10 deletions lib/msal-common/test/response/ResponseHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ const testServerTokenResponse = {
scope: TEST_CONFIG.DEFAULT_SCOPES.join(" "),
expires_in: TEST_TOKEN_LIFETIMES.DEFAULT_EXPIRES_IN,
ext_expires_in: TEST_TOKEN_LIFETIMES.DEFAULT_EXPIRES_IN,
refresh_in: TEST_TOKEN_LIFETIMES.DEFAULT_REFESH_IN,
access_token: TEST_TOKENS.ACCESS_TOKEN,
refresh_token: TEST_TOKENS.REFRESH_TOKEN,
id_token: TEST_TOKENS.IDTOKEN_V2,
Expand Down Expand Up @@ -266,9 +265,6 @@ describe("ResponseHandler.ts", () => {
expiresOn: new Date(
Date.now() + testServerTokenResponse.body.expires_in * 1000
),
refreshOn: new Date(
Date.now() + testServerTokenResponse.body.refresh_in * 1000
), // one day in the future
account: testAccount,
tokenType: AuthenticationScheme.BEARER,
};
Expand Down Expand Up @@ -335,9 +331,6 @@ describe("ResponseHandler.ts", () => {
expiresOn: new Date(
Date.now() + testServerTokenResponse.body.expires_in * 1000
),
refreshOn: new Date(
Date.now() + testServerTokenResponse.body.refresh_in * 1000
), // one day in the future
account: testAccount,
tokenType: AuthenticationScheme.BEARER,
};
Expand Down Expand Up @@ -403,9 +396,6 @@ describe("ResponseHandler.ts", () => {
expiresOn: new Date(
Date.now() + testServerTokenResponse.body.expires_in * 1000
),
refreshOn: new Date(
Date.now() + testServerTokenResponse.body.refresh_in * 1000
), // one day in the future
account: testAccount,
tokenType: AuthenticationScheme.BEARER,
};
Expand Down
1 change: 0 additions & 1 deletion lib/msal-common/test/test_kit/StringConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export const ID_TOKEN_CLAIMS = {
// Test Expiration Vals
export const TEST_TOKEN_LIFETIMES = {
DEFAULT_EXPIRES_IN: 3599,
DEFAULT_REFESH_IN: 86400,
TEST_ID_TOKEN_EXP: 1536361411,
TEST_ACCESS_TOKEN_EXP: 1537234948,
};
Expand Down
2 changes: 1 addition & 1 deletion lib/msal-node/src/network/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
INetworkModule,
NetworkRequestOptions,
NetworkResponse,
HttpStatus,
} from "@azure/msal-common";
import {
HttpMethod,
Constants,
HttpStatus,
ProxyStatus,
} from "../utils/Constants";
import { NetworkUtils } from "../utils/NetworkUtils";
Expand Down
2 changes: 1 addition & 1 deletion lib/msal-node/src/network/LoopbackClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import {
Constants as CommonConstants,
ServerAuthorizationCodeResponse,
UrlString,
HttpStatus,
} from "@azure/msal-common";
import { createServer, IncomingMessage, Server, ServerResponse } from "http";
import { NodeAuthError } from "../error/NodeAuthError";
import {
Constants,
HttpStatus,
LOOPBACK_SERVER_CONSTANTS,
} from "../utils/Constants";
import { ILoopbackClient } from "./ILoopbackClient";
Expand Down
11 changes: 0 additions & 11 deletions lib/msal-node/src/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@ export const HttpMethod = {
} as const;
export type HttpMethod = typeof HttpMethod[keyof typeof HttpMethod];

export const HttpStatus = {
SUCCESS_RANGE_START: 200,
SUCCESS_RANGE_END: 299,
REDIRECT: 302,
CLIENT_ERROR_RANGE_START: 400,
CLIENT_ERROR_RANGE_END: 499,
SERVER_ERROR_RANGE_START: 500,
SERVER_ERROR_RANGE_END: 599,
} as const;
export type HttpStatus = typeof HttpStatus[keyof typeof HttpStatus];

export const ProxyStatus = {
SUCCESS_RANGE_START: 200,
SUCCESS_RANGE_END: 299,
Expand Down
1 change: 0 additions & 1 deletion lib/msal-node/test/utils/TestConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ export const mockAuthenticationResult: AuthenticationResult = {
accessToken: TEST_CONSTANTS.ACCESS_TOKEN,
fromCache: false,
expiresOn: new Date(),
refreshOn: new Date(Date.now() + 86400000), // one day in the future
tokenType: "BEARER",
correlationId: "test-correlationId",
};
Expand Down

0 comments on commit af74365

Please sign in to comment.