3333
3434class OAuthPrompt (Dialog ):
3535 """
36- Creates a new prompt that asks the user to sign in using the Bot Framework Single Sign On (SSO) service.
37- The prompt will attempt to retrieve the users current token and if the user isn't signed in, it
38- will send them an `OAuthCard` containing a button they can press to sign in. Depending on the channel,
39- the user will be sent through one of two possible sign-in flows:
40- - The automatic sign-in flow where once the user signs in, the SSO service will forward
41- the bot the users access token using either an `event` or `invoke` activity.
42- - The "magic code" flow where once the user signs in, they will be prompted by the SSO service
43- to send the bot a six digit code confirming their identity. This code will be sent as a
44- standard `message` activity.
45- Both flows are automatically supported by the `OAuthPrompt` and they only thing you need to be careful of
46- is that you don't block the `event` and `invoke` activities that the prompt might be waiting on.
47- Note:
48- You should avaoid persisting the access token with your bots other state. The Bot Frameworks SSO service
49- will securely store the token on your behalf. If you store it in your bots state,
50- it could expire or be revoked in between turns.
51- When calling the prompt from within a waterfall step, you should use the token within the step
52- following the prompt and then let the token go out of scope at the end of your function
53- Prompt Usage
54- When used with your bots `DialogSet`, you can simply add a new instance of the prompt as a named dialog using
55- `DialogSet.add()`.
56- You can then start the prompt from a waterfall step using either
57- `DialogContext.begin()` or `DialogContext.prompt()`.
58- The user will be prompted to sign in as needed and their access token will be passed as an argument to the callers
59- next waterfall step.
36+ Creates a new prompt that asks the user to sign in, using the Bot Framework Single Sign On (SSO) service.
37+
38+ .. remarks::
39+ The prompt will attempt to retrieve the users current token and if the user isn't signed in, it
40+ will send them an `OAuthCard` containing a button they can press to sign in. Depending on the channel,
41+ the user will be sent through one of two possible sign-in flows:
42+ - The automatic sign-in flow where once the user signs in, the SSO service will forward
43+ the bot the users access token using either an `event` or `invoke` activity.
44+ - The "magic code" flow where once the user signs in, they will be prompted by the SSO service
45+ to send the bot a six digit code confirming their identity. This code will be sent as a
46+ standard `message` activity.
47+ Both flows are automatically supported by the `OAuthPrompt` and they only thing you need to be careful of
48+ is that you don't block the `event` and `invoke` activities that the prompt might be waiting on.
49+
50+ .. note::
51+ You should avoid persisting the access token with your bots other state. The Bot Frameworks SSO service
52+ will securely store the token on your behalf. If you store it in your bots state,
53+ it could expire or be revoked in between turns.
54+ When calling the prompt from within a waterfall step, you should use the token within the step
55+ following the prompt and then let the token go out of scope at the end of your function.
56+
57+ **Prompt Usage**
58+ When used with your bots :class:`DialogSet`, you can simply add a new instance of the prompt as a named dialog using
59+ :meth`DialogSet.add()`.
60+ You can then start the prompt from a waterfall step using either :meth:`DialogContext.begin()` or :meth:`DialogContext.prompt()`.
61+ The user will be prompted to sign in as needed and their access token will be passed as an argument to the callers
62+ next waterfall step.
6063 """
61-
6264 def __init__ (
6365 self ,
6466 dialog_id : str ,
6567 settings : OAuthPromptSettings ,
6668 validator : Callable [[PromptValidatorContext ], Awaitable [bool ]] = None ,
6769 ):
70+ """
71+ Creates a new instance of the :class:`OAuthPrompt` class.
72+
73+ :param dialogId: The Id to assign to this prompt.
74+ :type dialogId: str
75+ :param settings: Additional authentication settings to use with this instance of the prompt
76+ :type settings: :class:`OAuthPromptSettings`
77+ :param validator: Optional, a :class:`PromptValidator` that contains additional, custom validation for this prompt
78+ :type validator: :class:`PromptValidatorContext`
79+
80+ .. note::
81+ The value of :param dialogId: must be unique within the :class:`DialogSet`or :class:`ComponentDialog` to which the prompt is added.
82+ """
6883 super ().__init__ (dialog_id )
6984 self ._validator = validator
7085
@@ -79,6 +94,19 @@ def __init__(
7994 async def begin_dialog (
8095 self , dialog_context : DialogContext , options : PromptOptions = None
8196 ) -> DialogTurnResult :
97+ """
98+ Starts an authentication prompt dialog. Called when an authentication prompt dialog is pushed onto the dialog stack and is being activated.
99+
100+ :param dialog_context: The dialog context for the current turn of the conversation
101+ :type dialog_context: :class:`DialogContext`
102+ :param options: Optional, additional information to pass to the prompt being started
103+ :type options: :class:PromptOptions
104+ :return: Dialog turn result
105+ :rtype: :class:DialogTurnResult
106+
107+ .. note::
108+ If the task is successful, the result indicates whether the prompt is still active after the turn has been processed by the prompt.
109+ """
82110 if dialog_context is None :
83111 raise TypeError (
84112 f"OAuthPrompt.begin_dialog: Expected DialogContext but got NoneType instead"
@@ -120,6 +148,20 @@ async def begin_dialog(
120148 return Dialog .end_of_turn
121149
122150 async def continue_dialog (self , dialog_context : DialogContext ) -> DialogTurnResult :
151+ """
152+ Continues a dialog. Called when a prompt dialog is the active dialog and the user replied with a new activity.
153+
154+ :param dialog_context: The dialog context for the current turn of the conversation
155+ :type dialog_context: :class:`DialogContext`
156+ :return: Dialog turn result
157+ :rtype: :class:DialogTurnResult
158+
159+ .. note::
160+ If the task is successful, the result indicates whether the dialog is still
161+ active after the turn has been processed by the dialog.
162+ The prompt generally continues to receive the user's replies until it accepts the
163+ user's reply as valid input for the prompt.
164+ """
123165 # Recognize token
124166 recognized = await self ._recognize_token (dialog_context .context )
125167
@@ -167,6 +209,18 @@ async def continue_dialog(self, dialog_context: DialogContext) -> DialogTurnResu
167209 async def get_user_token (
168210 self , context : TurnContext , code : str = None
169211 ) -> TokenResponse :
212+ """
213+ Gets the user's tokeN.
214+
215+ :param context: Context for the current turn of conversation with the user
216+ :type context: :class:TurnContext
217+ :return: A response that includes the user's token
218+ :rtype: :class:TokenResponse
219+
220+ .. note::
221+ If the task is successful and the user already has a token or the user successfully signs in,
222+ the result contains the user's token.
223+ """
170224 adapter = context .adapter
171225
172226 # Validate adapter type
@@ -180,6 +234,18 @@ async def get_user_token(
180234 )
181235
182236 async def sign_out_user (self , context : TurnContext ):
237+ """
238+ Signs out the user
239+
240+ :param context: Context for the current turn of conversation with the user
241+ :type context: :class:`TurnContext`
242+ :return: A :class:`Task` representing the work queued to execute
243+ :rtype: :class:`Task`
244+
245+ .. note::
246+ If the task is successful and the user already has a token or the user successfully signs in,
247+ the result contains the user's token.
248+ """
183249 adapter = context .adapter
184250
185251 # Validate adapter type
0 commit comments