OAuthPrompt Class

public class OAuthPrompt
extends Dialog

Creates a new prompt that asks the user to sign in using the Bot Frameworks Single Sign On (SSO)service. The prompt will attempt to retrieve the users current token and if the user isn't signed in, itwill send them an `OAuthCard` containing a button they can press to signin. Depending on thechannel, 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 botthe 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 SSOservice to send the bot a six digit code confirming their identity. This code will be sent as astandard `message` activity. Both flows are automatically supported by the `OAuthPrompt` and the only thing you need to becareful of is that you don't block the `event` and `invoke` activities that the prompt mightbe waiting on. **Note**:You should avoid persisting the access token with your bots other state. The Bot FrameworksSSO service will securely store the token on your behalf. If you store it in your bots stateit could expire or be revoked in between turns. When calling the prompt from within a waterfall step you should use the token within the stepfollowing the prompt and then let the token go out of scope at the end of your function.

Constructor Summary

Constructor Description
OAuthPrompt(String dialogId, OAuthPromptSettings settings)

Initializes a new instance of the OAuthPrompt class.

OAuthPrompt(String dialogId, OAuthPromptSettings settings, PromptValidator<TokenResponse> validator)

Initializes a new instance of the OAuthPrompt class.

Method Summary

Modifier and Type Method and Description
java.util.concurrent.CompletableFuture<DialogTurnResult> beginDialog(DialogContext dc, Object options)

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

java.util.concurrent.CompletableFuture<DialogTurnResult> continueDialog(DialogContext dc)

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

java.util.concurrent.CompletableFuture<TokenResponse> getUserToken(TurnContext turnContext)

Attempts to get the user's token.

static java.util.concurrent.CompletableFuture<PromptRecognizerResult<TokenResponse>> recognizeToken(OAuthPromptSettings settings, DialogContext dc)

Shared implementation of the RecognizeToken function.

static java.util.concurrent.CompletableFuture<java.lang.Void> sendOAuthCard(OAuthPromptSettings settings, TurnContext turnContext, Activity prompt)

Shared implementation of the SendOAuthCard function.

static void setCallerInfoInDialogState(Map<String,Object> state, TurnContext context)

Shared implementation of the SetCallerInfoInDialogState function.

java.util.concurrent.CompletableFuture<java.lang.Void> signOutUser(TurnContext turnContext)

Signs out the user.

Methods inherited from Dialog

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Constructor Details

OAuthPrompt

public OAuthPrompt(String dialogId, OAuthPromptSettings settings)

Initializes a new instance of the OAuthPrompt class.

Parameters:

dialogId - The D to assign to this prompt.
settings - Additional OAuth settings to use with this instance of the prompt.
              The value of <xref uid="" data-throw-if-not-resolved="false" data-raw-source="dialogId"></xref> must be unique within the
              <xref uid="com.microsoft.bot.dialogs.DialogSet" data-throw-if-not-resolved="false" data-raw-source="DialogSet"></xref> or <xref uid="com.microsoft.bot.dialogs.ComponentDialog" data-throw-if-not-resolved="false" data-raw-source="ComponentDialog"></xref> to which the
              prompt is added.

OAuthPrompt

public OAuthPrompt(String dialogId, OAuthPromptSettings settings, PromptValidator validator)

Initializes a new instance of the OAuthPrompt class.

Parameters:

dialogId - The D to assign to this prompt.
settings - Additional OAuth settings to use with this instance of the prompt.
validator - Optional, a {@link PromptValidator{FoundChoice}} that contains additional, custom validation for this prompt.
              The value of <xref uid="" data-throw-if-not-resolved="false" data-raw-source="dialogId"></xref> must be unique within the
              <xref uid="com.microsoft.bot.dialogs.DialogSet" data-throw-if-not-resolved="false" data-raw-source="DialogSet"></xref> or <xref uid="com.microsoft.bot.dialogs.ComponentDialog" data-throw-if-not-resolved="false" data-raw-source="ComponentDialog"></xref> to which the
              prompt is added.

Method Details

beginDialog

public CompletableFuture beginDialog(DialogContext dc, Object options)

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

Overrides:

OAuthPrompt.beginDialog(DialogContext dc, Object options)

Parameters:

dc - The dialog context for the current turn of the conversation.
options - Optional, additional information to pass to the prompt being started.

Returns:

A CompletableFuture representing the hronous operation. If the task is successful, the result indicates whether the prompt is still active after the turn has been processed by the prompt.

continueDialog

public CompletableFuture continueDialog(DialogContext dc)

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

Overrides:

OAuthPrompt.continueDialog(DialogContext dc)

Parameters:

dc - The dialog context for the current turn of conversation.

Returns:

A CompletableFuture representing the hronous operation. If the task is successful, the result indicates whether the dialog is still active after the turn has been processed by the dialog. The prompt generally continues to receive the user's replies until it accepts the user's reply as valid input for the prompt.

getUserToken

public CompletableFuture getUserToken(TurnContext turnContext)

Attempts to get the user's token.

Parameters:

turnContext - Context for the current turn of conversation with the user.

Returns:

A task that represents the work queued to execute.
     If the task is successful and user already has a token or the user
     successfully signs in, the result contains the user's token.

recognizeToken

public static CompletableFuture> recognizeToken(OAuthPromptSettings settings, DialogContext dc)

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

Parameters:

settings - OAuthPromptSettings.
dc - DialogContext.

Returns:

PromptRecognizerResult.

sendOAuthCard

public static CompletableFuture sendOAuthCard(OAuthPromptSettings settings, TurnContext turnContext, Activity prompt)

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

Parameters:

settings - OAuthSettings.
turnContext - TurnContext.
prompt - MessageActivity.

Returns:

A CompletableFuture representing the result of the hronous operation.

setCallerInfoInDialogState

public static void setCallerInfoInDialogState(Map state, TurnContext context)

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.

Parameters:

state - The dialog state.
context - TurnContext.

signOutUser

public CompletableFuture signOutUser(TurnContext turnContext)

Signs out the user.

Parameters:

turnContext - Context for the current turn of conversation with the user.

Returns:

A task that represents the work queued to execute.

Applies to