Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [#4470] Migrate off @azure/ms-rest-js bf-connector #378

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions libraries/botbuilder/tests/teamsInfo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ describe('TeamsInfo', function () {
try {
await TeamsInfo.sendMeetingNotification(context, notification, meetingId);
} catch (e) {
assert.deepEqual(errorResponse, e.body);
assert.deepEqual(errorResponse, e.details);
isErrorThrown = true;
}

Expand Down Expand Up @@ -1214,7 +1214,7 @@ describe('TeamsInfo', function () {
try {
await TeamsInfo.sendMessageToListOfUsers(context, activity, tenantId, members);
} catch (e) {
assert.deepEqual(errorResponse, e.errors[0].body);
assert.deepEqual(errorResponse, e.errors[0].details);
isErrorThrown = true;
}

Expand Down Expand Up @@ -1307,7 +1307,7 @@ describe('TeamsInfo', function () {
try {
await TeamsInfo.sendMessageToAllUsersInTenant(context, activity, tenantId);
} catch (e) {
assert.deepEqual(errorResponse, e.errors[0].body);
assert.deepEqual(errorResponse, e.errors[0].details);
isErrorThrown = true;
}

Expand Down Expand Up @@ -1395,7 +1395,7 @@ describe('TeamsInfo', function () {
try {
await TeamsInfo.sendMessageToAllUsersInTeam(context, activity, tenantId, teamId);
} catch (e) {
assert.deepEqual(errorResponse, e.errors[0].body);
assert.deepEqual(errorResponse, e.errors[0].details);
isErrorThrown = true;
}

Expand Down Expand Up @@ -1502,7 +1502,7 @@ describe('TeamsInfo', function () {
try {
await TeamsInfo.sendMessageToListOfChannels(context, activity, tenantId, members);
} catch (e) {
assert.deepEqual(errorResponse, e.errors[0].body);
assert.deepEqual(errorResponse, e.errors[0].details);
isErrorThrown = true;
}

Expand Down Expand Up @@ -1579,7 +1579,7 @@ describe('TeamsInfo', function () {
try {
await TeamsInfo.getOperationState(context, operationId);
} catch (e) {
assert.deepEqual(errorResponse, e.errors[0].body);
assert.deepEqual(errorResponse, e.errors[0].details);
isErrorThrown = true;
}

Expand Down Expand Up @@ -1648,7 +1648,7 @@ describe('TeamsInfo', function () {
try {
await TeamsInfo.getFailedEntries(context, operationId);
} catch (e) {
assert.deepEqual(errorResponse, e.errors[0].body);
assert.deepEqual(errorResponse, e.errors[0].details);
isErrorThrown = true;
}

Expand Down Expand Up @@ -1697,7 +1697,7 @@ describe('TeamsInfo', function () {
try {
await TeamsInfo.cancelOperation(context, operationId);
} catch (e) {
assert.deepEqual(errorResponse, e.errors[0].body);
assert.deepEqual(errorResponse, e.errors[0].details);
isErrorThrown = true;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/botframework-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
}
},
"dependencies": {
"@azure/core-http": "^3.0.2",
"@azure/identity": "^2.0.4",
"@azure/ms-rest-js": "^2.7.0",
"@azure/msal-node": "^1.2.0",
"axios": "^0.25.0",
"base64url": "^3.0.0",
Expand Down
9 changes: 5 additions & 4 deletions libraries/botframework-connector/src/auth/appCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
* Licensed under the MIT License.
*/

import * as msrest from '@azure/ms-rest-js';
import { ConfidentialClientApplication } from '@azure/msal-node';
import { ServiceClientCredentials, WebResource } from '@azure/core-http';
import { TokenCredentials } from './tokenCredentials';
import { AuthenticationConstants } from './authenticationConstants';
import { AuthenticatorResult } from './authenticatorResult';

/**
* General AppCredentials auth implementation and cache.
* Subclasses can implement refreshToken to acquire the token.
*/
export abstract class AppCredentials implements msrest.ServiceClientCredentials {
export abstract class AppCredentials implements ServiceClientCredentials {
private static readonly cache: Map<string, AuthenticatorResult> = new Map<string, AuthenticatorResult>();

appId: string;
Expand Down Expand Up @@ -148,9 +149,9 @@ export abstract class AppCredentials implements msrest.ServiceClientCredentials
* @param webResource The WebResource HTTP request.
* @returns A Promise representing the asynchronous operation.
*/
async signRequest(webResource: msrest.WebResource): Promise<msrest.WebResource> {
async signRequest(webResource: WebResource): Promise<WebResource> {
if (this.shouldSetToken()) {
return new msrest.TokenCredentials(await this.getToken()).signRequest(webResource);
return new TokenCredentials(await this.getToken()).signRequest(webResource);
}

return webResource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { BotFrameworkClient } from '../skills';
import { ConversationIdHttpHeaderName } from '../conversationConstants';
import { ServiceClientCredentialsFactory } from './serviceClientCredentialsFactory';
import { USER_AGENT } from './connectorFactoryImpl';
import { WebResource } from '@azure/ms-rest-js';
import { WebResource } from '@azure/core-http';
import { ok } from 'assert';

const botFrameworkClientFetchImpl: typeof fetch = async (input, init) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT License.
*/

import type { ServiceClientCredentials } from '@azure/ms-rest-js';
import type { ServiceClientCredentials } from '@azure/core-http';
import { ServiceClientCredentialsFactory } from './serviceClientCredentialsFactory';
import { ok } from 'assert';
import { CertificateAppCredentials } from './certificateAppCredentials';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { getDefaultUserAgentValue, RequestPolicyFactory, userAgentPolicy } from '@azure/ms-rest-js';
import { getDefaultUserAgentValue, RequestPolicyFactory, userAgentPolicy } from '@azure/core-http';
import { ConnectorClient } from '../connectorApi/connectorClient';
import { ConnectorClientOptions } from '../connectorApi/models';
import { ConnectorFactory } from './connectorFactory';
Expand Down
1 change: 1 addition & 0 deletions libraries/botframework-connector/src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ export * from './userTokenClient';

export { MsalAppCredentials } from './msalAppCredentials';
export { MsalServiceClientCredentialsFactory } from './msalServiceClientCredentialsFactory';
export { TokenCredentials } from './tokenCredentials';
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import type { IJwtTokenProviderFactory } from './jwtTokenProviderFactory';
import type { ServiceClientCredentials } from '@azure/ms-rest-js';
import type { ServiceClientCredentials } from '@azure/core-http';
import { ManagedIdentityAppCredentials } from './managedIdentityAppCredentials';
import { ServiceClientCredentialsFactory } from './serviceClientCredentialsFactory';
import { ok } from 'assert';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { ConfidentialClientApplication } from '@azure/msal-node';
import { MsalAppCredentials } from './msalAppCredentials';
import { ServiceClientCredentials } from '@azure/ms-rest-js';
import { ServiceClientCredentials } from '@azure/core-http';
import { ServiceClientCredentialsFactory } from './serviceClientCredentialsFactory';
import { AuthenticationConstants } from './authenticationConstants';
import { GovernmentConstants } from './governmentConstants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import type { ServiceClientCredentials } from '@azure/ms-rest-js';
import type { ServiceClientCredentials } from '@azure/core-http';
import { AuthenticationConstants } from './authenticationConstants';
import { GovernmentConstants } from './governmentConstants';
import { MicrosoftAppCredentials } from './microsoftAppCredentials';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { ServiceClientCredentials } from '@azure/ms-rest-js';
import { ServiceClientCredentials } from '@azure/core-http';

// Export underlying type for convenience
export { ServiceClientCredentials };
Expand Down
42 changes: 42 additions & 0 deletions libraries/botframework-connector/src/auth/tokenCredentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

import { HttpHeaders, Constants, WebResourceLike, ServiceClientCredentials } from '@azure/core-http';

const HeaderConstants = Constants.HeaderConstants;
const DEFAULT_AUTHORIZATION_SCHEME = 'Bearer';

/**
* A credentials object that uses a token string and a authorzation scheme to authenticate.
*/
export class TokenCredentials implements ServiceClientCredentials {
token: string;
authorizationScheme: string = DEFAULT_AUTHORIZATION_SCHEME;

/**
* Creates a new TokenCredentials object.
*
* @class
* @param {string} token The token.
* @param {string} [authorizationScheme] The authorization scheme.
*/
constructor(token: string, authorizationScheme: string = DEFAULT_AUTHORIZATION_SCHEME) {
if (!token) {
throw new Error('token cannot be null or undefined.');
}
this.token = token;
this.authorizationScheme = authorizationScheme;
}

/**
* Signs a request with the Authentication header.
*
* @param {WebResourceLike} webResource The WebResourceLike to be signed.
* @returns {Promise<WebResourceLike>} The signed request object.
*/
signRequest(webResource: WebResourceLike) {
if (!webResource.headers) webResource.headers = new HttpHeaders();
webResource.headers.set(HeaderConstants.AUTHORIZATION, `${this.authorizationScheme} ${this.token}`);
return Promise.resolve(webResource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import * as z from 'zod';
import type { ServiceClientCredentials } from '@azure/ms-rest-js';
import type { ServiceClientCredentials } from '@azure/core-http';
import { Activity, SignInUrlResponse, TokenExchangeRequest, TokenResponse, TokenStatus } from 'botframework-schema';
import { ConnectorClientOptions } from '../connectorApi/models';
import { TokenApiClient } from '../tokenApi/tokenApiClient';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as Mappers from './models/mappers';
import * as Models from './models';
import * as msRest from '@azure/ms-rest-js';
import { ServiceClientCredentials } from "@azure/core-http"
import * as operations from './operations';
import { ConnectorClientContext } from './connectorClientContext';

Expand All @@ -20,7 +20,7 @@ class ConnectorClient extends ConnectorClientContext {
* @param credentials Subscription credentials which uniquely identify client subscription.
* @param [options] The parameter options
*/
constructor(credentials: msRest.ServiceClientCredentials, options?: Models.ConnectorClientOptions) {
constructor(credentials: ServiceClientCredentials, options?: Models.ConnectorClientOptions) {
super(credentials, options);
this.attachments = new operations.Attachments(this);
this.conversations = new operations.Conversations(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
* Licensed under the MIT License.
*/

import * as msRest from "@azure/ms-rest-js";
import { ServiceClient, ServiceClientCredentials, getDefaultUserAgentValue } from "@azure/core-http";
import * as Models from "./models";

const packageName = "botframework-connector";
const packageVersion = "4.0.0";

export class ConnectorClientContext extends msRest.ServiceClient {
credentials: msRest.ServiceClientCredentials;
export class ConnectorClientContext extends ServiceClient {
credentials: ServiceClientCredentials;

/**
* Initializes a new instance of the ConnectorClientContext class.
* @param credentials Subscription credentials which uniquely identify client subscription.
* @param [options] The parameter options
*/
constructor(credentials: msRest.ServiceClientCredentials, options?: Models.ConnectorClientOptions) {
constructor(credentials: ServiceClientCredentials, options?: Models.ConnectorClientOptions) {
if (credentials === null || credentials === undefined) {
throw new Error('\'credentials\' cannot be null.');
}
Expand All @@ -27,7 +27,7 @@ export class ConnectorClientContext extends msRest.ServiceClient {
options = {} as Models.ConnectorClientOptions;
}
// TODO This is to workaround fact that AddUserAgent() was removed.
const defaultUserAgent = msRest.getDefaultUserAgentValue();
const defaultUserAgent = getDefaultUserAgentValue();
options.userAgent = `${packageName}/${packageVersion} ${defaultUserAgent} ${options.userAgent || ''}`;

super(credentials, options);
Expand Down
Loading
Loading