Skip to content

Commit

Permalink
[Identity] Update logging and dependency versions for MSAL (#23960)
Browse files Browse the repository at this point in the history
  • Loading branch information
KarishmaGhiya committed Nov 23, 2022
1 parent f6d4cb8 commit 6357771
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 16 deletions.
36 changes: 25 additions & 11 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion sdk/identity/identity/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Release History

## 3.1.2 (Unreleased)

### Features Added
Expand All @@ -8,8 +7,11 @@

### Bugs Fixed

- Enable msal logging based on log level specified by user.
### Other Changes

- Upgraded version dependencies on msal libraries, since they have additional logging enabled.

## 3.1.1 (2022-11-18)

### Bugs Fixed
Expand Down
6 changes: 3 additions & 3 deletions sdk/identity/identity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@
"@azure/core-tracing": "^1.0.0",
"@azure/core-util": "^1.0.0",
"@azure/logger": "^1.0.0",
"@azure/msal-browser": "^2.26.0",
"@azure/msal-common": "^7.0.0",
"@azure/msal-node": "^1.14.2",
"@azure/msal-browser": "^2.32.0",
"@azure/msal-common": "^9.0.0",
"@azure/msal-node": "^1.14.4",
"events": "^3.0.0",
"jws": "^4.0.0",
"open": "^8.0.0",
Expand Down
4 changes: 3 additions & 1 deletion sdk/identity/identity/src/msal/browserFlows/msalAuthCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

import * as msalBrowser from "@azure/msal-browser";
import { MsalBrowser, MsalBrowserFlowOptions } from "./msalBrowserCommon";
import { defaultLoggerCallback, msalToPublic, publicToMsal } from "../utils";
import { defaultLoggerCallback, msalToPublic, publicToMsal, getMSALLogLevel } from "../utils";
import { AccessToken } from "@azure/core-auth";
import { AuthenticationRecord } from "../types";
import { AuthenticationRequiredError } from "../../errors";
import { CredentialFlowGetTokenOptions } from "../credentials";
import { getLogLevel } from "@azure/logger";

// We keep a copy of the redirect hash.
const redirectHash = self.location.hash;
Expand Down Expand Up @@ -38,6 +39,7 @@ export class MSALAuthCode extends MsalBrowser {
this.msalConfig.system = {
loggerOptions: {
loggerCallback: defaultLoggerCallback(this.logger, "Browser"),
logLevel: getMSALLogLevel(getLogLevel()),
},
};

Expand Down
3 changes: 3 additions & 0 deletions sdk/identity/identity/src/msal/nodeFlows/msalNodeCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import * as msalCommon from "@azure/msal-common";
import * as msalNode from "@azure/msal-node";
import { AccessToken, GetTokenOptions } from "@azure/core-auth";
import { getLogLevel } from "@azure/logger";
import {
MsalBaseUtilities,
defaultLoggerCallback,
getAuthority,
getKnownAuthorities,
msalToPublic,
publicToMsal,
getMSALLogLevel,
} from "../utils";
import { MsalFlow, MsalFlowOptions } from "../flows";
import {
Expand Down Expand Up @@ -163,6 +165,7 @@ export abstract class MsalNode extends MsalBaseUtilities implements MsalFlow {
networkClient: this.identityClient,
loggerOptions: {
loggerCallback: defaultLoggerCallback(options.logger),
logLevel: getMSALLogLevel(getLogLevel()),
},
},
};
Expand Down
20 changes: 20 additions & 0 deletions sdk/identity/identity/src/msal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { AbortError } from "@azure/abort-controller";
import { MsalFlowOptions } from "./flows";
import { isNode } from "@azure/core-util";
import { v4 as uuidv4 } from "uuid";
import { AzureLogLevel } from "@azure/logger";

/**
* Latest AuthenticationRecord version
Expand Down Expand Up @@ -110,6 +111,25 @@ export const defaultLoggerCallback: (
}
};

/**
* @internal
*/
export function getMSALLogLevel(logLevel: AzureLogLevel | undefined): msalCommon.LogLevel {
switch (logLevel) {
case "error":
return msalCommon.LogLevel.Error;
case "info":
return msalCommon.LogLevel.Info;
case "verbose":
return msalCommon.LogLevel.Verbose;
case "warning":
return msalCommon.LogLevel.Warning;
default:
// default msal logging level should be Info
return msalCommon.LogLevel.Info;
}
}

/**
* The common utility functions for the MSAL clients.
* Defined as a class so that the classes extending this one can have access to its methods and protected properties.
Expand Down

0 comments on commit 6357771

Please sign in to comment.