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

Use AAD Token for Authentication #362

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

bwamie
Copy link

@bwamie bwamie commented Nov 18, 2021

A new policy, DisableLocalAuth, was added to Azure Bot Service to enable bot resource owners to enforce bots in particular subscriptions to explicitly use AAD token instead of secret.

This PR is to update DirectLine client to be able to support using AAD token.

Follow this doc if you would like to test the feature.

@bwamie bwamie requested a review from a team as a code owner November 18, 2021 20:04
@bwamie bwamie changed the title Edwinb/aad token dirctline Use AAD Token for Authentication Nov 18, 2021
@@ -0,0 +1,33 @@
<!--
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this for?

@@ -0,0 +1,9 @@
# Microsoft Open Source Code of Conduct
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this for?

@@ -0,0 +1,45 @@
## Purpose
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this for?

@@ -0,0 +1,349 @@
## Ignore Visual Studio temporary files, build results, and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this for?


### Pre-requisites

1. Open PowerShell (On Windows, press `Windows-R` and type `PowerShell` in the search window)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this only worked on Windows? What about other platforms?

@@ -0,0 +1,76 @@
# Contributing to [project-title]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this for?

@@ -558,9 +564,12 @@ export class DirectLine implements IBotConnection {
} else {
return this.startConversation().do(conversation => {
this.conversationId = conversation.conversationId;
this.token = this.secret || conversation.token;
// Don't invoke acquireToken(), coulf fetch anew AAD token
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/coulf/could

@@ -664,7 +675,7 @@ export class DirectLine implements IBotConnection {
}

private refreshTokenLoop() {
this.tokenRefreshSubscription = Observable.interval(intervalRefreshToken, this.services.scheduler)
this.tokenRefreshSubscription = Observable.interval(3000, this.services.scheduler)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the change here?

@@ -558,9 +564,12 @@ export class DirectLine implements IBotConnection {
} else {
return this.startConversation().do(conversation => {
this.conversationId = conversation.conversationId;
this.token = this.secret || conversation.token;
// Don't invoke acquireToken(), coulf fetch anew AAD token
this.token = (this.acquireToken ? this.token : this.secret) || conversation.token;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we setting the secret as the token ever? This isn't a practice we should follow, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that doesn't look good. However, ABS API expects either a token or secret in the Authentication header. Maybe we should use a variable name that suits both.

this.secret = options.secret;
this.token = options.secret || options.token;
this.token = this.acquireToken ? this.acquireToken() : options.secret || options.token;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned about the async nature of this function. What if the caller needs to do some HTTP call or database operation? I'm not sure this will work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The client calls webchat after fetching the token atleast once. The WebSite code logic keeps refreshing the token. Yes, that code is async. Sample is in this doc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code doesn't look to be async, is what I mean. Can you write a test that exercises this to demonstrate the behavior you mention?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants