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

Add default middleware to patch location of tenantId for MS Teams #886

Merged
merged 6 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
11 changes: 11 additions & 0 deletions libraries/botbuilder/src/botFrameworkAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide
this.credentials.oAuthEndpoint = GovernmentConstants.ToChannelFromBotLoginUrl;
this.credentials.oAuthScope = GovernmentConstants.ToChannelFromBotOAuthScope;
}

// Relocate the tenantId field used by MS Teams to a new location (from channelData to conversation)
// This will only occur on actities from teams that include tenant info in channelData but NOT in conversation,
// thus should be future friendly. However, once the the transition is complete. we can remove this.
this.use(async(context, next) => {
if (context.activity.channelId === 'msteams' && context.activity && context.activity.conversation && !context.activity.conversation.tenantId && context.activity.channelData && context.activity.channelData.tenant) {
context.activity.conversation.tenantId = context.activity.channelData.tenant.id;
}
await next();
});
benbrown marked this conversation as resolved.
Show resolved Hide resolved

}

/**
Expand Down
11 changes: 11 additions & 0 deletions libraries/botbuilder/tests/botFrameworkAdapter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,17 @@ describe(`BotFrameworkAdapter`, function () {
});
});

it(`should migrate location of tenantId for MS Teams processActivity().`, function (done) {
const incoming = TurnContext.applyConversationReference({ type: 'message', text: 'foo', channelData: { tenant: { id: '1234' } } }, reference, true);
const req = new MockBodyRequest(incoming);
const res = new MockResponse();
const adapter = new AdapterUnderTest();
adapter.processActivity(req, res, (context) => {
assert(context.activity.conversation.tenantId === '1234', `should have copied tenant id from channelData to conversation address`);
done();
});
});

it(`should fail to auth on call to processActivity().`, function (done) {
const req = new MockRequest(incomingMessage);
const res = new MockResponse();
Expand Down