Skip to content

Commit

Permalink
implement different fixes for #1901
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengum committed Mar 13, 2020
1 parent 9f63621 commit 81304f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions libraries/botbuilder-core/src/appCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* Licensed under the MIT License.
*/

/**
* Internal interface representing the "WebResource" from @azure/ms-rest-js@1.2.6
*/
/**
* Internal interface representing the "WebResource" from @azure/ms-rest-js@1.2.6
*/
interface WebResource {}

/**
Expand Down
24 changes: 13 additions & 11 deletions libraries/botbuilder/src/botFrameworkAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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`);
Expand Down Expand Up @@ -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`);
Expand All @@ -588,15 +588,15 @@ 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> {
if (userId && userId != context.activity.from.id) {
throw new ReferenceError(`cannot retrieve OAuth signin link for a user that's different from the conversation`);
}

this.checkEmulatingOAuthCards(context);
const conversation: Partial<ConversationReference> = TurnContext.getConversationReference(context.activity);
const url: string = this.oauthApiUrl(context);
const client: TokenApiClient = this.createTokenApiClient(url, oAuthAppCredentials);
const client: TokenApiClient = this.createTokenApiClient(url, oAuthAppCredentials as AppCredentials);
context.turnState.set(this.TokenApiClientCredentialsKey, client);
const state: any = {
ConnectionName: connectionName,
Expand All @@ -622,7 +622,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`);
Expand All @@ -647,7 +647,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`);
Expand All @@ -671,8 +671,8 @@ 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>
public async getSignInResource(context: TurnContext, connectionName: string, userId?: string, finalRedirect?: string, appCredentials?: AppCredentials): Promise<SignInUrlResponse> {
if (!connectionName) {
throw new Error('getUserToken() requires a connectionName but none was provided.');
}
Expand Down Expand Up @@ -709,6 +709,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.');
Expand Down Expand Up @@ -1119,8 +1120,9 @@ 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 {
const tokenApiClientCredentials = oAuthAppCredentials ? oAuthAppCredentials : this.credentials;
protected createTokenApiClient(serviceUrl: string, oAuthAppCredentials: CoreAppCredentials): TokenApiClient {
const credentials = oAuthAppCredentials as AppCredentials;
const tokenApiClientCredentials = credentials ? credentials : this.credentials;
const client = new TokenApiClient(tokenApiClientCredentials, { baseUri: serviceUrl, userAgent: USER_AGENT });

return client;
Expand Down

0 comments on commit 81304f2

Please sign in to comment.