Skip to content

Commit

Permalink
wire up oauthinput to cloudadapter via oauthprompt, rewire oauthprompt (
Browse files Browse the repository at this point in the history
#5213)

* wire up oauthinput to cloudadapter via oauthprompt, rewire oauthprompt

* fix race in streaming code

* code review feedback and a fix to oauthinput
  • Loading branch information
johnataylor authored Feb 15, 2021
1 parent 180eaa9 commit c000b4a
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,7 @@ public class OAuthInput : InputDialog
OAuthPrompt.SetCallerInfoInDialogState(state, dc.Context);

// Attempt to get the users token
if (!(dc.Context.Adapter is IUserTokenProvider adapter))
{
throw new InvalidOperationException("OAuthInput.BeginDialog(): not supported by the current adapter");
}

var output = await adapter.GetUserTokenAsync(dc.Context, ConnectionName.GetValue(dc.State), null, cancellationToken).ConfigureAwait(false);
var output = await GetUserTokenAsync(dc, cancellationToken).ConfigureAwait(false);
if (output != null)
{
if (this.Property != null)
Expand Down Expand Up @@ -282,12 +277,8 @@ public class OAuthInput : InputDialog
/// the result contains the user's token.</remarks>
public async Task<TokenResponse> GetUserTokenAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
{
if (!(dc.Context.Adapter is IUserTokenProvider adapter))
{
throw new InvalidOperationException("OAuthPrompt.GetUserToken(): not supported by the current adapter");
}

return await adapter.GetUserTokenAsync(dc.Context, ConnectionName.GetValue(dc.State), null, cancellationToken).ConfigureAwait(false);
var settings = new OAuthPromptSettings { ConnectionName = ConnectionName?.GetValue(dc.State) };
return await new OAuthPrompt(nameof(OAuthPrompt), settings).GetUserTokenAsync(dc.Context, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -299,13 +290,8 @@ public class OAuthInput : InputDialog
/// <returns>A task that represents the work queued to execute.</returns>
public async Task SignOutUserAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
{
if (!(dc.Context.Adapter is IUserTokenProvider adapter))
{
throw new InvalidOperationException("OAuthPrompt.SignOutUser(): not supported by the current adapter");
}

// Sign out user
await adapter.SignOutUserAsync(dc.Context, ConnectionName.GetValue(dc.State), dc.Context.Activity?.From?.Id, cancellationToken).ConfigureAwait(false);
var settings = new OAuthPromptSettings { ConnectionName = ConnectionName?.GetValue(dc.State) };
await new OAuthPrompt(nameof(OAuthPrompt), settings).SignOutUserAsync(dc.Context, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -330,7 +316,7 @@ private async Task SendOAuthCardAsync(DialogContext dc, IMessageActivity prompt,

private Task<PromptRecognizerResult<TokenResponse>> RecognizeTokenAsync(DialogContext dc, CancellationToken cancellationToken)
{
var settings = new OAuthPromptSettings { ConnectionName = ConnectionName.GetValue(dc.State) };
var settings = new OAuthPromptSettings { ConnectionName = ConnectionName?.GetValue(dc.State) };
return OAuthPrompt.RecognizeTokenAsync(settings, dc, cancellationToken);
}

Expand Down
140 changes: 0 additions & 140 deletions libraries/Microsoft.Bot.Builder.Dialogs/Prompts/CloudOAuthPrompt.cs

This file was deleted.

Loading

0 comments on commit c000b4a

Please sign in to comment.