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 AppCredentials compilation error in BotFrameworkAdapter #1902

Merged
merged 7 commits into from
Mar 13, 2020
Merged
Changes from 4 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
6 changes: 3 additions & 3 deletions libraries/botbuilder-core/src/appCredentials.ts
Original file line number Diff line number Diff line change
@@ -6,9 +6,9 @@
* Licensed under the MIT License.
*/

/**
* Internal interface representing the "WebResource" from @azure/[email protected]
*/
/**
* Internal interface representing the "WebResource" from @azure/[email protected]
*/
interface WebResource {}

/**
24 changes: 14 additions & 10 deletions libraries/botbuilder/src/botFrameworkAdapter.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
import { STATUS_CODES } from 'http';
import * as os from 'os';

import { Activity, ActivityTypes, BotAdapter, BotCallbackHandlerKey, ChannelAccount, ConversationAccount, ConversationParameters, ConversationReference, ConversationsResult, DeliveryModes, ExpectedReplies, InvokeResponse, ExtendedUserTokenProvider, ResourceResponse, StatusCodes, TokenResponse, TurnContext, INVOKE_RESPONSE_KEY } from 'botbuilder-core';
import { Activity, ActivityTypes, AppCredentials as CoreAppCredentials, BotAdapter, BotCallbackHandlerKey, ChannelAccount, ConversationAccount, ConversationParameters, ConversationReference, ConversationsResult, DeliveryModes, ExpectedReplies, InvokeResponse, ExtendedUserTokenProvider, ResourceResponse, StatusCodes, TokenResponse, TurnContext, INVOKE_RESPONSE_KEY } from 'botbuilder-core';
import { AuthenticationConfiguration, AuthenticationConstants, ChannelValidation, Claim, ClaimsIdentity, ConnectorClient, EmulatorApiClient, GovernmentConstants, GovernmentChannelValidation, JwtTokenValidation, MicrosoftAppCredentials, AppCredentials, CertificateAppCredentials, SimpleCredentialProvider, TokenApiClient, TokenStatus, TokenApiModels, SignInUrlResponse, SkillValidation, TokenExchangeRequest } from 'botframework-connector';

import { INodeBuffer, INodeSocket, IReceiveRequest, ISocket, IStreamingTransportServer, NamedPipeServer, NodeWebSocketFactory, NodeWebSocketFactoryBase, RequestHandler, StreamingResponse, WebSocketServer } from 'botframework-streaming';
@@ -530,7 +530,7 @@ export class BotFrameworkAdapter extends BotAdapter implements ExtendedUserToken
* @returns A [TokenResponse](xref:botframework-schema.TokenResponse) object that contains the user token.
*/
public async getUserToken(context: TurnContext, connectionName: string, magicCode?: string): Promise<TokenResponse>;
public async getUserToken(context: TurnContext, connectionName: string, magicCode?: string, oAuthAppCredentials?: AppCredentials): Promise<TokenResponse>;
public async getUserToken(context: TurnContext, connectionName: string, magicCode?: string, oAuthAppCredentials?: CoreAppCredentials): Promise<TokenResponse>;
public async getUserToken(context: TurnContext, connectionName: string, magicCode?: string, oAuthAppCredentials?: AppCredentials): Promise<TokenResponse> {
if (!context.activity.from || !context.activity.from.id) {
throw new Error(`BotFrameworkAdapter.getUserToken(): missing from or from.id`);
@@ -561,7 +561,7 @@ export class BotFrameworkAdapter extends BotAdapter implements ExtendedUserToken
* @param oAuthAppCredentials AppCredentials for OAuth.
*/
public async signOutUser(context: TurnContext, connectionName?: string, userId?: string): Promise<void>;
public async signOutUser(context: TurnContext, connectionName?: string, userId?: string, oAuthAppCredentials?: AppCredentials): Promise<void>;
public async signOutUser(context: TurnContext, connectionName?: string, userId?: string, oAuthAppCredentials?: CoreAppCredentials): Promise<void>;
public async signOutUser(context: TurnContext, connectionName?: string, userId?: string, oAuthAppCredentials?: AppCredentials): Promise<void> {
if (!context.activity.from || !context.activity.from.id) {
throw new Error(`BotFrameworkAdapter.signOutUser(): missing from or from.id`);
@@ -588,6 +588,8 @@ export class BotFrameworkAdapter extends BotAdapter implements ExtendedUserToken
* @param userId The user id that will be associated with the token.
* @param finalRedirect The final URL that the OAuth flow will redirect to.
*/
public async getSignInLink(context: TurnContext, connectionName: string, oAuthAppCredentials?: AppCredentials, userId?: string, finalRedirect?: string): Promise<string>
public async getSignInLink(context: TurnContext, connectionName: string, oAuthAppCredentials?: CoreAppCredentials, userId?: string, finalRedirect?: string): Promise<string>
public async getSignInLink(context: TurnContext, connectionName: string, oAuthAppCredentials?: AppCredentials, userId?: string, finalRedirect?: string): Promise<string> {
if (userId && userId != context.activity.from.id) {
throw new ReferenceError(`cannot retrieve OAuth signin link for a user that's different from the conversation`);
@@ -622,7 +624,7 @@ export class BotFrameworkAdapter extends BotAdapter implements ExtendedUserToken
* @returns The [TokenStatus](xref:botframework-connector.TokenStatus) objects retrieved.
*/
public async getTokenStatus(context: TurnContext, userId?: string, includeFilter?: string): Promise<TokenStatus[]>;
public async getTokenStatus(context: TurnContext, userId?: string, includeFilter?: string, oAuthAppCredentials?: AppCredentials): Promise<TokenStatus[]>;
public async getTokenStatus(context: TurnContext, userId?: string, includeFilter?: string, oAuthAppCredentials?: CoreAppCredentials): Promise<TokenStatus[]>;
public async getTokenStatus(context: TurnContext, userId?: string, includeFilter?: string, oAuthAppCredentials?: AppCredentials): Promise<TokenStatus[]> {
if (!userId && (!context.activity.from || !context.activity.from.id)) {
throw new Error(`BotFrameworkAdapter.getTokenStatus(): missing from or from.id`);
@@ -647,7 +649,7 @@ export class BotFrameworkAdapter extends BotAdapter implements ExtendedUserToken
* @returns A map of the [TokenResponse](xref:botframework-schema.TokenResponse) objects by resource URL.
*/
public async getAadTokens(context: TurnContext, connectionName: string, resourceUrls: string[]): Promise<{[propertyName: string]: TokenResponse}>;
public async getAadTokens(context: TurnContext, connectionName: string, resourceUrls: string[], oAuthAppCredentials?: AppCredentials): Promise<{[propertyName: string]: TokenResponse}>;
public async getAadTokens(context: TurnContext, connectionName: string, resourceUrls: string[], oAuthAppCredentials?: CoreAppCredentials): Promise<{[propertyName: string]: TokenResponse}>;
public async getAadTokens(context: TurnContext, connectionName: string, resourceUrls: string[], oAuthAppCredentials?: AppCredentials): Promise<{[propertyName: string]: TokenResponse}> {
if (!context.activity.from || !context.activity.from.id) {
throw new Error(`BotFrameworkAdapter.getAadTokens(): missing from or from.id`);
@@ -671,8 +673,7 @@ export class BotFrameworkAdapter extends BotAdapter implements ExtendedUserToken
*
* @returns The [BotSignInGetSignInResourceResponse](xref:botframework-connector.BotSignInGetSignInResourceResponse) object.
*/
public async getSignInResource(context: TurnContext, connectionName: string, userId?: string, finalRedirect?: string, appCredentials?: AppCredentials): Promise<SignInUrlResponse>
{
public async getSignInResource(context: TurnContext, connectionName: string, userId?: string, finalRedirect?: string, appCredentials?: CoreAppCredentials): Promise<SignInUrlResponse> {
if (!connectionName) {
throw new Error('getUserToken() requires a connectionName but none was provided.');
}
@@ -687,7 +688,8 @@ export class BotFrameworkAdapter extends BotAdapter implements ExtendedUserToken
}

const url: string = this.oauthApiUrl(context);
const client: TokenApiClient = this.createTokenApiClient(url, appCredentials);
const credentials = appCredentials as AppCredentials;
const client: TokenApiClient = this.createTokenApiClient(url, credentials);
const conversation: Partial<ConversationReference> = TurnContext.getConversationReference(context.activity);

const state: any = {
@@ -709,6 +711,7 @@ export class BotFrameworkAdapter extends BotAdapter implements ExtendedUserToken
* @param userId The user id that will be associated with the token.
* @param tokenExchangeRequest The exchange request details, either a token to exchange or a uri to exchange.
*/
public async exchangeToken(context: TurnContext, connectionName: string, userId: string, tokenExchangeRequest: TokenExchangeRequest, appCredentials?: CoreAppCredentials): Promise<TokenResponse>
public async exchangeToken(context: TurnContext, connectionName: string, userId: string, tokenExchangeRequest: TokenExchangeRequest, appCredentials?: AppCredentials): Promise<TokenResponse> {
if (!connectionName) {
throw new Error('exchangeToken() requires a connectionName but none was provided.');
@@ -742,7 +745,7 @@ export class BotFrameworkAdapter extends BotAdapter implements ExtendedUserToken
public async emulateOAuthCards(contextOrServiceUrl: TurnContext | string, emulate: boolean): Promise<void> {
this.isEmulatingOAuthCards = emulate;
const url: string = this.oauthApiUrl(contextOrServiceUrl);
await EmulatorApiClient.emulateOAuthCards(this.credentials as AppCredentials, url, emulate);
await EmulatorApiClient.emulateOAuthCards(this.credentials, url, emulate);
}

/**
@@ -1119,7 +1122,8 @@ export class BotFrameworkAdapter extends BotAdapter implements ExtendedUserToken
* @remarks
* Override this in a derived class to create a mock OAuth API client for unit testing.
*/
protected createTokenApiClient(serviceUrl: string, oAuthAppCredentials: AppCredentials): TokenApiClient {
protected createTokenApiClient(serviceUrl: string, oAuthAppCredentials?: CoreAppCredentials): TokenApiClient;
protected createTokenApiClient(serviceUrl: string, oAuthAppCredentials?: AppCredentials): TokenApiClient {
const tokenApiClientCredentials = oAuthAppCredentials ? oAuthAppCredentials : this.credentials;
const client = new TokenApiClient(tokenApiClientCredentials, { baseUri: serviceUrl, userAgent: USER_AGENT });

6 changes: 3 additions & 3 deletions libraries/botbuilder/src/botFrameworkHttpClient.ts
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ export class BotFrameworkHttpClient implements BotFrameworkClient {
* Cache for appCredentials to speed up token acquisition (a token is not requested unless is expired)
* AppCredentials are cached using appId + scope (this last parameter is only used if the app credentials are used to call a skill)
*/
private static readonly appCredentialMapCache: Map<string, MicrosoftAppCredentials> = new Map<string, MicrosoftAppCredentials>();
private static readonly appCredentialMapCache: Map<string, AppCredentials> = new Map<string, AppCredentials>();
private readonly credentialProvider: ICredentialProvider;

public constructor(credentialProvider: ICredentialProvider, channelService?: string) {
@@ -71,7 +71,7 @@ export class BotFrameworkHttpClient implements BotFrameworkClient {
}

// Get token for the skill call
const token = appCredentials.appId === '' && appCredentials.appPassword === '' ? null : await appCredentials.getToken();
const token = appCredentials.appId ? await appCredentials.getToken() : null;

// Capture current activity settings before changing them.
// TODO: DO we need to set the activity ID? (events that are created manually don't have it).
@@ -142,7 +142,7 @@ export class BotFrameworkHttpClient implements BotFrameworkClient {
* @param appId The application identifier (AAD Id for the bot).
* @param oAuthScope The scope for the token, skills will use the Skill App Id.
*/
private async getAppCredentials(appId: string, oAuthScope?: string): Promise<MicrosoftAppCredentials> {
private async getAppCredentials(appId: string, oAuthScope?: string): Promise<AppCredentials> {
if (!appId) {
return new MicrosoftAppCredentials('', '');
}