Skip to content

Commit

Permalink
Fixed http(s) import errors in msal-node (#6349)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbie-Microsoft committed Aug 16, 2023
1 parent b0aff05 commit 4d23a90
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Fixed http(s) imports #6349",
"packageName": "@azure/msal-node",
"email": "rginsburg@microsoft.com",
"dependentChangeType": "patch"
}
10 changes: 5 additions & 5 deletions lib/msal-node/src/config/Configuration.ts
Expand Up @@ -16,8 +16,8 @@ import {
INativeBrokerPlugin,
} from "@azure/msal-common";
import { HttpClient } from "../network/HttpClient";
import { AgentOptions as httpAgentOptions } from "http";
import { AgentOptions as httpsAgentOptions } from "https";
import http from "http";
import https from "https";

/**
* - clientId - Client id of the application.
Expand Down Expand Up @@ -82,7 +82,7 @@ export type NodeSystemOptions = {
loggerOptions?: LoggerOptions;
networkClient?: INetworkModule;
proxyUrl?: string;
customAgentOptions?: httpAgentOptions | httpsAgentOptions;
customAgentOptions?: http.AgentOptions | https.AgentOptions;
};

export type NodeTelemetryOptions = {
Expand Down Expand Up @@ -145,7 +145,7 @@ const DEFAULT_SYSTEM_OPTIONS: Required<NodeSystemOptions> = {
loggerOptions: DEFAULT_LOGGER_OPTIONS,
networkClient: new HttpClient(),
proxyUrl: Constants.EMPTY_STRING,
customAgentOptions: {} as httpAgentOptions | httpsAgentOptions,
customAgentOptions: {} as http.AgentOptions | https.AgentOptions,
};

const DEFAULT_TELEMETRY_OPTIONS: Required<NodeTelemetryOptions> = {
Expand Down Expand Up @@ -186,7 +186,7 @@ export function buildAppConfiguration({
...DEFAULT_SYSTEM_OPTIONS,
networkClient: new HttpClient(
system?.proxyUrl,
system?.customAgentOptions as httpAgentOptions | httpsAgentOptions
system?.customAgentOptions as http.AgentOptions | https.AgentOptions
),
loggerOptions: system?.loggerOptions || DEFAULT_LOGGER_OPTIONS,
};
Expand Down
11 changes: 7 additions & 4 deletions lib/msal-node/src/network/LoopbackClient.ts
Expand Up @@ -8,7 +8,7 @@ import {
ServerAuthorizationCodeResponse,
UrlString,
} from "@azure/msal-common";
import { createServer, IncomingMessage, Server, ServerResponse } from "http";
import http from "http";
import { NodeAuthError } from "../error/NodeAuthError";
import {
Constants,
Expand All @@ -18,7 +18,7 @@ import {
import { ILoopbackClient } from "./ILoopbackClient";

export class LoopbackClient implements ILoopbackClient {
private server: Server;
private server: http.Server;

/**
* Spins up a loopback server which returns the server response when the localhost redirectUri is hit
Expand All @@ -36,8 +36,11 @@ export class LoopbackClient implements ILoopbackClient {

const authCodeListener = new Promise<ServerAuthorizationCodeResponse>(
(resolve, reject) => {
this.server = createServer(
async (req: IncomingMessage, res: ServerResponse) => {
this.server = http.createServer(
async (
req: http.IncomingMessage,
res: http.ServerResponse
) => {
const url = req.url;
if (!url) {
res.end(
Expand Down
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import { createServer, IncomingMessage, Server, ServerResponse } from "http";
import http from "http";
import { ILoopbackClient, ServerAuthorizationCodeResponse } from "@azure/msal-node";

/**
Expand All @@ -13,7 +13,7 @@ import { ILoopbackClient, ServerAuthorizationCodeResponse } from "@azure/msal-no
*/
export class CustomLoopbackClient implements ILoopbackClient {
port: number = 0; // default port, which will be set to a random available port
private server: Server;
private server: http.Server;

private constructor(port: number = 0) {
this.port = port;
Expand Down Expand Up @@ -52,7 +52,7 @@ export class CustomLoopbackClient implements ILoopbackClient {
}

const authCodeListener = new Promise<ServerAuthorizationCodeResponse>((resolve, reject) => {
this.server = createServer(async (req: IncomingMessage, res: ServerResponse) => {
this.server = http.createServer(async (req: http.IncomingMessage, res: http.ServerResponse) => {
const url = req.url;
if (!url) {
res.end(errorTemplate || "Error occurred loading redirectUrl");
Expand Down Expand Up @@ -129,7 +129,7 @@ export class CustomLoopbackClient implements ILoopbackClient {
*/
isPortAvailable(port: number): Promise<boolean> {
return new Promise(resolve => {
const server = createServer()
const server = http.createServer()
.listen(port, () => {
server.close();
resolve(true);
Expand Down
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import { createServer, IncomingMessage, Server, ServerResponse } from "http";
import http from "http";
import { CryptoProvider } from "@azure/msal-node";
import open from "open";

Expand All @@ -13,7 +13,7 @@ import open from "open";
* https://learn.microsoft.com/azure/active-directory/develop/single-and-multi-tenant-apps
*/
class ProvisionHandler {
private server: Server;
private server: http.Server;
private cryptoProvider: CryptoProvider;
private state: string;

Expand Down Expand Up @@ -64,7 +64,7 @@ class ProvisionHandler {
}

const adminConsentListener = new Promise<boolean>((resolve, reject) => {
this.server = createServer(async (req: IncomingMessage, res: ServerResponse) => {
this.server = http.createServer(async (req: http.IncomingMessage, res: http.ServerResponse) => {
const url = req.url;

if (!url) {
Expand Down

0 comments on commit 4d23a90

Please sign in to comment.