Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Multiple Authentication Providers #243

Merged
merged 31 commits into from
Nov 7, 2018
Merged

Multiple Authentication Providers #243

merged 31 commits into from
Nov 7, 2018

Conversation

lauren-mills
Copy link
Contributor

Description

This change adds support for multiple authentication providers in the virtual assistant and skills.

Expected Behavior

  • If user is not logged in to any provider, they will be prompted to add an account from the supported providers list
  • If the user has already connected 1 account, that account will be used by default
  • If the user has multiple accounts configured (only possible with Linked Accounts for now) they will be prompted to choose which of their accounts to user
  • Supported providers are configured per skill

Related Issue

fixes #19

Testing Steps

  1. Register a google app - instructions here (instead of the Google+ API, enable the Google Calendar API)
  2. Collect the clientId and clientSecret
  3. Add the google auth provider in the Azure Bot Settings with the clientId and secret, and set the scopes to https://www.googleapis.com/auth/calendar
  4. Add the appName, ClientId, ClientSecret, and scopes for your google app to the appsettings files
  5. Say "logout" to ensure no tokens are cached
  6. Say "what's on my calendar"
  7. See the auth provider prompt
    image

@lauren-mills
Copy link
Contributor Author

lauren-mills commented Nov 6, 2018

Changed to used connectionName to drive choices. This allows for the bot dev to create more meaningful names for the connections, and allows user to have multiple connections of the same type (i.e. personal Microsoft account and corporate 0365 account)

image

AddDialog(new WaterfallDialog(nameof(MultiProviderAuthDialog), auth));
AddDialog(new ChoicePrompt(DialogIds.ProviderPrompt) { Style = ListStyle.SuggestedAction });

foreach (var connection in skillConfiguration.AuthenticationConnections)
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible skillConfiguration.AuthenticationConnections to be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added null checks in all the SkillDialogs


private async Task<DialogTurnResult> PromptForProvider(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
if (_skillConfiguration.AuthenticationConnections.Count() == 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

i think i'd check AuthenticationConnections is null before using it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

catch
{
throw;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

catch block useless if you're just gonna throw

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

//await a.SignOutUserAsync(dc.Context, skillConfiguration.AuthConnectionName, dc.Context.Activity.From.Id, default(CancellationToken));
if (!_useCachedTokens)
{
var a = dc.Context.Adapter as BotFrameworkAdapter;
Copy link
Contributor

@lzc850612 lzc850612 Nov 6, 2018

Choose a reason for hiding this comment

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

'a' is definitely not the worst variable name ever :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed :)

@@ -17,7 +19,7 @@ public class CalendarService : ICalendar
/// <param name="token">the access token.</param>
/// <param name="source">the calendar provider.</param>
/// <param name="timeZoneInfo">the user timezone info.</param>
public CalendarService(string token, EventSource source)
public CalendarService(string token, EventSource source, GoogleClient config)
Copy link
Contributor

Choose a reason for hiding this comment

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

let's think about how to do this in a better way, in a different PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created an issue to track #244

@@ -18,6 +18,16 @@
<CodeAnalysisRuleSet>..\..\VirtualAssistant.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
<None Remove="ServiceClients\WindowsIanaMapping" />
Copy link
Contributor

Choose a reason for hiding this comment

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

is this generated by changing the output policy to 'Always'? feel like it's not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

Copy link
Contributor

@darrenj darrenj left a comment

Choose a reason for hiding this comment

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

Reviewed the comments and changes, makes sense!

@lauren-mills lauren-mills merged commit 5afed84 into master Nov 7, 2018
@lauren-mills lauren-mills deleted the lamil/multi_auth branch November 7, 2018 18:02
lauren-mills added a commit that referenced this pull request Apr 18, 2019
* consolidated skill case statements

* va multi-auth handling

* started skill update for multi auth

* fixed indentation

* updated skill authentication dialog

* updated va authentication to include provider in token response

* updated logout method

* multi auth in skills

* updated calendar skill to pull google config from appsettings

* updated to use t4 template responses

* consolidated skill case statements

* va multi-auth handling

* started skill update for multi auth

* fixed indentation

* updated skill authentication dialog

* updated va authentication to include provider in token response

* updated logout method

* multi auth in skills

* updated calendar skill to pull google config from appsettings

* updated to use t4 template responses

* updated appsettings for va

* turned useCachedTokens on

* Added validator for multi-auth prompts

* Added todo service provider back to appsettings

* change to use the oauth ConnectionName to drive buttons

* stylecop fixes

* reverting trivial appSettings change

* review fixes

* updated email skill test
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

P0: Skills to support multiple authentication providers
4 participants