OAuthPrompt Class

Definition

Creates a new prompt that asks the user to sign in using the Bot Frameworks Single Sign On (SSO) service.

public class OAuthPrompt : Microsoft.Bot.Builder.Dialogs.Dialog
type OAuthPrompt = class
    inherit Dialog
Public Class OAuthPrompt
Inherits Dialog
Inheritance
OAuthPrompt

Remarks

The prompt will attempt to retrieve the users current token and if the user isn't signed in, it will send them an OAuthCard containing a button they can press to signin. Depending on the channel, the user will be sent through one of two possible signin flows:

  • The automatic signin flow where once the user signs in and the SSO service will forward the bot the users access token using either an event or invoke activity.
  • The "magic code" flow where once the user signs in they will be prompted by the SSO service to send the bot a six digit code confirming their identity. This code will be sent as a standard message activity.

Both flows are automatically supported by the OAuthPrompt and the only thing you need to be careful of is that you don't block the event and invoke activities that the prompt might be waiting on.

**Note**: You should avoid persisting the access token with your bots other state. The Bot Frameworks SSO service will securely store the token on your behalf. If you store it in your bots state it could expire or be revoked in between turns.

When calling the prompt from within a waterfall step you should use the token within the step following the prompt and then let the token go out of scope at the end of your function.

Prompt Usage

When used with your bot's DialogSet you can simply add a new instance of the prompt as a named dialog using Add(Dialog). You can then start the prompt from a waterfall step using either BeginDialogAsync(String, Object, CancellationToken) or PromptAsync(String, PromptOptions, CancellationToken). The user will be prompted to signin as needed and their access token will be passed as an argument to the callers next waterfall step.

Constructors

OAuthPrompt(String, OAuthPromptSettings, PromptValidator<TokenResponse>)

Initializes a new instance of the OAuthPrompt class.

Properties

Id

Gets or sets id for the dialog.

(Inherited from Dialog)
Source

Gets the information of the cref="SourceRange"/>.

(Inherited from Dialog)
TelemetryClient

Gets or sets the IBotTelemetryClient to use for logging.

(Inherited from Dialog)

Methods

BeginDialogAsync(DialogContext, Object, CancellationToken)

Called when a prompt dialog is pushed onto the dialog stack and is being activated.

ContinueDialogAsync(DialogContext, CancellationToken)

Called when a prompt dialog is the active dialog and the user replied with a new activity.

EndDialogAsync(ITurnContext, DialogInstance, DialogReason, CancellationToken)

Called when the dialog is ending.

(Inherited from Dialog)
GetUserTokenAsync(ITurnContext, CancellationToken)

Attempts to get the user's token.

GetVersion()

Gets a unique string which represents the version of this dialog. If the version changes between turns the dialog system will emit a DialogChanged event.

(Inherited from Dialog)
OnComputeId()

Computes an unique ID for a dialog.

(Inherited from Dialog)
OnDialogEventAsync(DialogContext, DialogEvent, CancellationToken)

Called when an event has been raised, using DialogContext.emitEvent(), by either the current dialog or a dialog that the current dialog started.

(Inherited from Dialog)
OnPostBubbleEventAsync(DialogContext, DialogEvent, CancellationToken)

Called after an event was bubbled to all parents and wasn't handled.

(Inherited from Dialog)
OnPreBubbleEventAsync(DialogContext, DialogEvent, CancellationToken)

Called before an event is bubbled to its parent.

(Inherited from Dialog)
RecognizeTokenAsync(OAuthPromptSettings, DialogContext, CancellationToken)

Shared implementation of the RecognizeTokenAsync function. This is intended for internal use, to consolidate the implementation of the OAuthPrompt and OAuthInput. Application logic should use those dialog classes.

RegisterSourceLocation(String, Int32)

Registers a cref="SourceRange"/> in the provided location.

(Inherited from Dialog)
RepromptDialogAsync(ITurnContext, DialogInstance, CancellationToken)

Called when the dialog should re-prompt the user for input.

(Inherited from Dialog)
ResumeDialogAsync(DialogContext, DialogReason, Object, CancellationToken)

Called when a child dialog completed this turn, returning control to this dialog.

(Inherited from Dialog)
SendOAuthCardAsync(OAuthPromptSettings, ITurnContext, IMessageActivity, CancellationToken)

Shared implementation of the SendOAuthCardAsync function. This is intended for internal use, to consolidate the implementation of the OAuthPrompt and OAuthInput. Application logic should use those dialog classes.

SetCallerInfoInDialogState(IDictionary<String,Object>, ITurnContext)

Shared implementation of the SetCallerInfoInDialogState function. This is intended for internal use, to consolidate the implementation of the OAuthPrompt and OAuthInput. Application logic should use those dialog classes.

SignOutUserAsync(ITurnContext, CancellationToken)

Signs out the user.

Extension Methods

RunAsync(Dialog, ITurnContext, IStatePropertyAccessor<DialogState>, CancellationToken)

Creates a dialog stack and starts a dialog, pushing it onto the stack.

Applies to