microsoft-agents-hosting-core 0.4.0.dev18__py3-none-any.whl → 0.5.0.dev5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. microsoft_agents/hosting/core/_oauth/_flow_state.py +2 -2
  2. microsoft_agents/hosting/core/_oauth/_oauth_flow.py +26 -23
  3. microsoft_agents/hosting/core/activity_handler.py +19 -17
  4. microsoft_agents/hosting/core/app/agent_application.py +31 -6
  5. microsoft_agents/hosting/core/app/input_file.py +15 -11
  6. microsoft_agents/hosting/core/app/oauth/_handlers/_authorization_handler.py +4 -4
  7. microsoft_agents/hosting/core/app/oauth/_handlers/_user_authorization.py +2 -2
  8. microsoft_agents/hosting/core/app/oauth/_handlers/agentic_user_authorization.py +3 -3
  9. microsoft_agents/hosting/core/app/oauth/authorization.py +38 -20
  10. microsoft_agents/hosting/core/app/state/state.py +50 -6
  11. microsoft_agents/hosting/core/channel_adapter.py +9 -9
  12. microsoft_agents/hosting/core/channel_service_adapter.py +64 -6
  13. microsoft_agents/hosting/core/connector/client/user_token_client.py +40 -43
  14. microsoft_agents/hosting/core/connector/user_token_base.py +77 -1
  15. microsoft_agents/hosting/core/connector/user_token_client_base.py +3 -0
  16. microsoft_agents/hosting/core/state/agent_state.py +16 -20
  17. {microsoft_agents_hosting_core-0.4.0.dev18.dist-info → microsoft_agents_hosting_core-0.5.0.dev5.dist-info}/METADATA +5 -3
  18. {microsoft_agents_hosting_core-0.4.0.dev18.dist-info → microsoft_agents_hosting_core-0.5.0.dev5.dist-info}/RECORD +21 -20
  19. microsoft_agents_hosting_core-0.5.0.dev5.dist-info/licenses/LICENSE +21 -0
  20. {microsoft_agents_hosting_core-0.4.0.dev18.dist-info → microsoft_agents_hosting_core-0.5.0.dev5.dist-info}/WHEEL +0 -0
  21. {microsoft_agents_hosting_core-0.4.0.dev18.dist-info → microsoft_agents_hosting_core-0.5.0.dev5.dist-info}/top_level.txt +0 -0
@@ -3,7 +3,7 @@
3
3
 
4
4
  from __future__ import annotations
5
5
 
6
- from datetime import datetime
6
+ from datetime import datetime, timezone
7
7
  from enum import Enum
8
8
  from typing import Optional
9
9
 
@@ -60,7 +60,7 @@ class _FlowState(BaseModel, StoreItem):
60
60
  return _FlowState.model_validate(json_data)
61
61
 
62
62
  def is_expired(self) -> bool:
63
- return datetime.now().timestamp() >= self.expiration
63
+ return datetime.now(timezone.utc).timestamp() >= self.expiration
64
64
 
65
65
  def reached_max_attempts(self) -> bool:
66
66
  return self.attempts_remaining <= 0
@@ -6,7 +6,7 @@ from __future__ import annotations
6
6
  import logging
7
7
 
8
8
  from pydantic import BaseModel
9
- from datetime import datetime
9
+ from datetime import datetime, timezone
10
10
  from typing import Optional
11
11
 
12
12
  from microsoft_agents.activity import (
@@ -30,7 +30,6 @@ class _FlowResponse(BaseModel):
30
30
  flow_error_tag: _FlowErrorTag = _FlowErrorTag.NONE
31
31
  token_response: Optional[TokenResponse] = None
32
32
  sign_in_resource: Optional[SignInResource] = None
33
- continuation_activity: Optional[Activity] = None
34
33
 
35
34
 
36
35
  class _OAuthFlow:
@@ -112,7 +111,7 @@ class _OAuthFlow:
112
111
  """Get the user token based on the context.
113
112
 
114
113
  Args:
115
- magic_code (str, optional): Defaults to None. The magic code for user authentication.
114
+ magic_code (str, Optional): Defaults to None. The magic code for user authentication.
116
115
 
117
116
  Returns:
118
117
  TokenResponse
@@ -137,7 +136,7 @@ class _OAuthFlow:
137
136
  if token_response:
138
137
  logger.info("User token obtained successfully: %s", token_response)
139
138
  self._flow_state.expiration = (
140
- datetime.now().timestamp() + self._default_flow_duration
139
+ datetime.now(timezone.utc).timestamp() + self._default_flow_duration
141
140
  )
142
141
  self._flow_state.tag = _FlowStateTag.COMPLETE
143
142
 
@@ -183,20 +182,8 @@ class _OAuthFlow:
183
182
  Notes:
184
183
  The flow state is reset if a token is not obtained from cache.
185
184
  """
186
- token_response = await self.get_user_token()
187
- if token_response:
188
- return _FlowResponse(
189
- flow_state=self._flow_state, token_response=token_response
190
- )
191
185
 
192
186
  logger.debug("Starting new OAuth flow")
193
- self._flow_state.tag = _FlowStateTag.BEGIN
194
- self._flow_state.expiration = (
195
- datetime.now().timestamp() + self._default_flow_duration
196
- )
197
-
198
- self._flow_state.attempts_remaining = self._max_attempts
199
- self._flow_state.continuation_activity = activity.model_copy()
200
187
 
201
188
  token_exchange_state = TokenExchangeState(
202
189
  connection_name=self._abs_oauth_connection_name,
@@ -205,16 +192,33 @@ class _OAuthFlow:
205
192
  ms_app_id=self._ms_app_id,
206
193
  )
207
194
 
208
- sign_in_resource = (
209
- await self._user_token_client.agent_sign_in.get_sign_in_resource(
210
- state=token_exchange_state.get_encoded_state()
195
+ res = await self._user_token_client.user_token._get_token_or_sign_in_resource(
196
+ activity.from_property.id,
197
+ self._abs_oauth_connection_name,
198
+ activity.channel_id,
199
+ token_exchange_state.get_encoded_state(),
200
+ )
201
+
202
+ if res.token_response:
203
+ logger.info("Skipping flow, user token obtained.")
204
+ self._flow_state.tag = _FlowStateTag.COMPLETE
205
+ self._flow_state.expiration = (
206
+ datetime.now(timezone.utc).timestamp() + self._default_flow_duration
207
+ )
208
+ return _FlowResponse(
209
+ flow_state=self._flow_state, token_response=res.token_response
211
210
  )
211
+
212
+ self._flow_state.tag = _FlowStateTag.BEGIN
213
+ self._flow_state.expiration = (
214
+ datetime.now(timezone.utc).timestamp() + self._default_flow_duration
212
215
  )
216
+ self._flow_state.attempts_remaining = self._max_attempts
213
217
 
214
- logger.debug("Sign-in resource obtained successfully: %s", sign_in_resource)
218
+ logger.debug("Sign-in resource obtained successfully: %s", res.sign_in_resource)
215
219
 
216
220
  return _FlowResponse(
217
- flow_state=self._flow_state, sign_in_resource=sign_in_resource
221
+ flow_state=self._flow_state, sign_in_resource=res.sign_in_resource
218
222
  )
219
223
 
220
224
  async def _continue_from_message(
@@ -299,7 +303,7 @@ class _OAuthFlow:
299
303
  else:
300
304
  self._flow_state.tag = _FlowStateTag.COMPLETE
301
305
  self._flow_state.expiration = (
302
- datetime.now().timestamp() + self._default_flow_duration
306
+ datetime.now(timezone.utc).timestamp() + self._default_flow_duration
303
307
  )
304
308
  logger.debug(
305
309
  "OAuth flow completed successfully, got TokenResponse: %s",
@@ -310,7 +314,6 @@ class _OAuthFlow:
310
314
  flow_state=self._flow_state.model_copy(),
311
315
  flow_error_tag=flow_error_tag,
312
316
  token_response=token_response,
313
- continuation_activity=self._flow_state.continuation_activity,
314
317
  )
315
318
 
316
319
  async def begin_or_continue_flow(self, activity: Activity) -> _FlowResponse:
@@ -38,7 +38,7 @@ class ActivityHandler(Agent):
38
38
  in order to process an inbound :class:`microsoft_agents.activity.Activity`.
39
39
 
40
40
  :param turn_context: The context object for this turn
41
- :type turn_context: :class:`microsoft_agents.builder.TurnContext`
41
+ :type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
42
42
 
43
43
  :returns: A task that represents the work queued to execute
44
44
 
@@ -143,7 +143,7 @@ class ActivityHandler(Agent):
143
143
  :meth:`on_turn()` is used.
144
144
 
145
145
  :param turn_context: The context object for this turn
146
- :type turn_context: :class:`microsoft_agents.builder.TurnContext`
146
+ :type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
147
147
  :returns: A task that represents the work queued to execute
148
148
 
149
149
  .. remarks::
@@ -176,7 +176,7 @@ class ActivityHandler(Agent):
176
176
 
177
177
  :param members_added: A list of all the members added to the conversation, as described by the
178
178
  conversation update activity
179
- :type members_added: list[ChannelAccount]
179
+ :type members_added: list[:class:`microsoft_agents.activity.ChannelAccount`]
180
180
  :param turn_context: The context object for this turn
181
181
  :type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
182
182
  :returns: A task that represents the work queued to execute
@@ -195,9 +195,9 @@ class ActivityHandler(Agent):
195
195
  Override this method in a derived class to provide logic for when members other than the agent leave
196
196
  the conversation. You can add your agent's good-bye logic.
197
197
 
198
- :param members_added: A list of all the members removed from the conversation, as described by the
198
+ :param members_removed: A list of all the members removed from the conversation, as described by the
199
199
  conversation update activity
200
- :type members_added: list[ChannelAccount]
200
+ :type members_removed: list[:class:`microsoft_agents.activity.ChannelAccount`]
201
201
  :param turn_context: The context object for this turn
202
202
  :type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
203
203
  :returns: A task that represents the work queued to execute
@@ -216,7 +216,7 @@ class ActivityHandler(Agent):
216
216
  :meth:`on_turn()` is used.
217
217
 
218
218
  :param turn_context: The context object for this turn
219
- :type turn_context: :class:`microsoft_agents.builder.TurnContext`
219
+ :type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
220
220
 
221
221
  :returns: A task that represents the work queued to execute
222
222
 
@@ -260,7 +260,7 @@ class ActivityHandler(Agent):
260
260
  are added to the conversation.
261
261
 
262
262
  :param message_reactions: The list of reactions added
263
- :type message_reactions: list[MessageReaction]
263
+ :type message_reactions: list[:class:`microsoft_agents.activity.MessageReaction`]
264
264
  :param turn_context: The context object for this turn
265
265
  :type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
266
266
  :returns: A task that represents the work queued to execute
@@ -285,7 +285,7 @@ class ActivityHandler(Agent):
285
285
  are removed from the conversation.
286
286
 
287
287
  :param message_reactions: The list of reactions removed
288
- :type message_reactions: list[MessageReaction]
288
+ :type message_reactions: list[:class:`microsoft_agents.activity.MessageReaction`]
289
289
  :param turn_context: The context object for this turn
290
290
  :type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
291
291
 
@@ -382,7 +382,7 @@ class ActivityHandler(Agent):
382
382
  ActivityTypes.typing activities, such as the conversational logic.
383
383
 
384
384
  :param turn_context: The context object for this turn
385
- :type turn_context: :class:`microsoft_agents.builder.TurnContext`
385
+ :type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
386
386
  :returns: A task that represents the work queued to execute
387
387
  """
388
388
  return
@@ -395,7 +395,7 @@ class ActivityHandler(Agent):
395
395
  ActivityTypes.InstallationUpdate activities.
396
396
 
397
397
  :param turn_context: The context object for this turn
398
- :type turn_context: :class:`microsoft_agents.builder.TurnContext`
398
+ :type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
399
399
  :returns: A task that represents the work queued to execute
400
400
  """
401
401
  if turn_context.activity.action in ("add", "add-upgrade"):
@@ -412,7 +412,7 @@ class ActivityHandler(Agent):
412
412
  ActivityTypes.InstallationUpdate activities with 'action' set to 'add'.
413
413
 
414
414
  :param turn_context: The context object for this turn
415
- :type turn_context: :class:`microsoft_agents.builder.TurnContext`
415
+ :type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
416
416
  :returns: A task that represents the work queued to execute
417
417
  """
418
418
  return
@@ -425,7 +425,7 @@ class ActivityHandler(Agent):
425
425
  ActivityTypes.InstallationUpdate activities with 'action' set to 'remove'.
426
426
 
427
427
  :param turn_context: The context object for this turn
428
- :type turn_context: :class:`microsoft_agents.builder.TurnContext`
428
+ :type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
429
429
  :returns: A task that represents the work queued to execute
430
430
  """
431
431
  return
@@ -439,7 +439,7 @@ class ActivityHandler(Agent):
439
439
  If overridden, this method could potentially respond to any of the other activity types.
440
440
 
441
441
  :param turn_context: The context object for this turn
442
- :type turn_context: :class:`microsoft_agents.builder.TurnContext`
442
+ :type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
443
443
 
444
444
  :returns: A task that represents the work queued to execute
445
445
 
@@ -456,9 +456,10 @@ class ActivityHandler(Agent):
456
456
  Registers an activity event handler for the _invoke_ event, emitted for every incoming event activity.
457
457
 
458
458
  :param turn_context: The context object for this turn
459
- :type turn_context: :class:`microsoft_agents.builder.TurnContext`
459
+ :type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
460
460
 
461
461
  :returns: A task that represents the work queued to execute
462
+ :rtype: Optional[:class:`microsoft_agents.activity.InvokeResponse`]
462
463
  """
463
464
  try:
464
465
  if (
@@ -492,7 +493,7 @@ class ActivityHandler(Agent):
492
493
  By default, this method does nothing.
493
494
 
494
495
  :param turn_context: The context object for this turn
495
- :type turn_context: :class:`microsoft_agents.builder.TurnContext`
496
+ :type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
496
497
 
497
498
  :returns: A task that represents the work queued to execute
498
499
  """
@@ -508,10 +509,11 @@ class ActivityHandler(Agent):
508
509
  calls this method.
509
510
 
510
511
  :param turn_context: A context object for this turn.
511
- :type turn_context: :class:`microsoft_agents.builder.TurnContext`
512
+ :type turn_context: :class:`microsoft_agents.activity.TurnContextProtocol`
512
513
  :param invoke_value: A string-typed object from the incoming activity's value.
513
- :type invoke_value: :class:`microsoft_agents.activity.adaptive_card_invoke_value.AdaptiveCardInvokeValue`
514
+ :type invoke_value: :class:`microsoft_agents.activity.AdaptiveCardInvokeValue`
514
515
  :return: The HealthCheckResponse object
516
+ :rtype: :class:`microsoft_agents.activity.AdaptiveCardInvokeResponse`
515
517
  """
516
518
  raise _InvokeResponseException(HTTPStatus.NOT_IMPLEMENTED)
517
519
 
@@ -83,6 +83,15 @@ class AgentApplication(Agent, Generic[StateT]):
83
83
  ) -> None:
84
84
  """
85
85
  Creates a new AgentApplication instance.
86
+
87
+ :param options: Configuration options for the application.
88
+ :type options: Optional[:class:`microsoft_agents.hosting.core.app.app_options.ApplicationOptions`]
89
+ :param connection_manager: OAuth connection manager.
90
+ :type connection_manager: Optional[:class:`microsoft_agents.hosting.core.authorization.Connections`]
91
+ :param authorization: Authorization manager for handling authentication flows.
92
+ :type authorization: Optional[:class:`microsoft_agents.hosting.core.app.oauth.Authorization`]
93
+ :param kwargs: Additional configuration parameters.
94
+ :type kwargs: Any
86
95
  """
87
96
  self.typing = TypingIndicator()
88
97
  self._route_list = _RouteList[StateT]()
@@ -161,6 +170,10 @@ class AgentApplication(Agent, Generic[StateT]):
161
170
  def adapter(self) -> ChannelServiceAdapter:
162
171
  """
163
172
  The bot's adapter.
173
+
174
+ :return: The channel service adapter for the bot.
175
+ :rtype: :class:`microsoft_agents.hosting.core.channel_service_adapter.ChannelServiceAdapter`
176
+ :raises ApplicationError: If the adapter is not configured.
164
177
  """
165
178
 
166
179
  if not self._adapter:
@@ -181,6 +194,10 @@ class AgentApplication(Agent, Generic[StateT]):
181
194
  def auth(self) -> Authorization:
182
195
  """
183
196
  The application's authentication manager
197
+
198
+ :return: The authentication manager for handling OAuth flows.
199
+ :rtype: :class:`microsoft_agents.hosting.core.app.oauth.Authorization`
200
+ :raises ApplicationError: If authentication is not configured.
184
201
  """
185
202
  if not self._auth:
186
203
  logger.error(
@@ -200,6 +217,9 @@ class AgentApplication(Agent, Generic[StateT]):
200
217
  def options(self) -> ApplicationOptions:
201
218
  """
202
219
  The application's configured options.
220
+
221
+ :return: The configuration options for the application.
222
+ :rtype: :class:`microsoft_agents.hosting.core.app.app_options.ApplicationOptions`
203
223
  """
204
224
  return self._options
205
225
 
@@ -217,18 +237,18 @@ class AgentApplication(Agent, Generic[StateT]):
217
237
  Routes are ordered by: is_agentic, is_invoke, rank (lower is higher priority), in that order.
218
238
 
219
239
  :param selector: A function that takes a TurnContext and returns a boolean indicating whether the route should be selected.
220
- :type selector: RouteSelector
240
+ :type selector: :class:`microsoft_agents.hosting.core.app._type_defs.RouteSelector`
221
241
  :param handler: A function that takes a TurnContext and a TurnState and returns an Awaitable.
222
- :type handler: RouteHandler[StateT]
242
+ :type handler: :class:`microsoft_agents.hosting.core.app._type_defs.RouteHandler`[StateT]
223
243
  :param is_invoke: Whether the route is for an invoke activity, defaults to False
224
- :type is_invoke: bool, optional
244
+ :type is_invoke: bool, Optional
225
245
  :param is_agentic: Whether the route is for an agentic request, defaults to False. For agentic requests
226
246
  the selector will include a new check for `context.activity.is_agentic_request()`.
227
- :type is_agentic: bool, optional
247
+ :type is_agentic: bool, Optional
228
248
  :param rank: The rank of the route, defaults to RouteRank.DEFAULT
229
- :type rank: RouteRank, optional
249
+ :type rank: :class:`microsoft_agents.hosting.core.app._routes.RouteRank`, Optional
230
250
  :param auth_handlers: A list of authentication handler IDs to use for this route, defaults to None
231
- :type auth_handlers: Optional[list[str]], optional
251
+ :type auth_handlers: Optional[list[str]], Optional
232
252
  :raises ApplicationError: If the selector or handler are not valid.
233
253
  """
234
254
  if not selector or not handler:
@@ -706,6 +726,11 @@ class AgentApplication(Agent, Generic[StateT]):
706
726
  def parse_env_vars_configuration(vars: dict[str, Any]) -> dict:
707
727
  """
708
728
  Parses environment variables and returns a dictionary with the relevant configuration.
729
+
730
+ :param vars: Dictionary of environment variable names and values.
731
+ :type vars: dict[str, Any]
732
+ :return: Parsed configuration dictionary with nested structure.
733
+ :rtype: dict
709
734
  """
710
735
  result = {}
711
736
  for key, value in vars.items():
@@ -16,10 +16,12 @@ from microsoft_agents.hosting.core import TurnContext
16
16
  class InputFile:
17
17
  """A file sent by the user to the bot.
18
18
 
19
- Attributes:
20
- content (bytes): The downloaded content of the file.
21
- content_type (str): The content type of the file.
22
- content_url (Optional[str]): Optional. URL to the content of the file.
19
+ :param content: The downloaded content of the file.
20
+ :type content: bytes
21
+ :param content_type: The content type of the file.
22
+ :type content_type: str
23
+ :param content_url: Optional. URL to the content of the file.
24
+ :type content_url: Optional[str]
23
25
  """
24
26
 
25
27
  content: bytes
@@ -29,17 +31,19 @@ class InputFile:
29
31
 
30
32
  class InputFileDownloader(ABC):
31
33
  """
32
- A plugin responsible for downloading files relative to the current user's input.
34
+ Abstract base class for a plugin responsible for downloading files provided by the user.
35
+
36
+ Implementations should download any files referenced by the incoming activity and return a
37
+ list of :class:`InputFile` instances representing the downloaded content.
33
38
  """
34
39
 
35
40
  @abstractmethod
36
41
  async def download_files(self, context: TurnContext) -> List[InputFile]:
37
42
  """
38
- Download any files relative to the current user's input.
39
-
40
- Args:
41
- context (TurnContext): Context for the current turn of conversation.
43
+ Download any files referenced by the incoming activity for the current turn.
42
44
 
43
- Returns:
44
- List[InputFile]: A list of input files.
45
+ :param context: The turn context for the current request.
46
+ :type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
47
+ :return: A list of downloaded :class:`InputFile` objects.
48
+ :rtype: list[:class:`microsoft_agents.hosting.core.app.input_file.InputFile`]
45
49
  """
@@ -43,7 +43,7 @@ class _AuthorizationHandler(ABC):
43
43
  :param connection_manager: The connection manager for OAuth providers.
44
44
  :type connection_manager: Connections
45
45
  :param auth_handlers: Configuration for OAuth providers.
46
- :type auth_handlers: dict[str, AuthHandler], optional
46
+ :type auth_handlers: dict[str, AuthHandler], Optional
47
47
  :raises ValueError: When storage is None or no auth handlers provided.
48
48
  """
49
49
  if not storage:
@@ -75,7 +75,7 @@ class _AuthorizationHandler(ABC):
75
75
  :param context: The turn context for the current turn of conversation.
76
76
  :type context: TurnContext
77
77
  :param scopes: Optional list of scopes to request during sign-in. If None, default scopes will be used.
78
- :type scopes: Optional[list[str]], optional
78
+ :type scopes: Optional[list[str]], Optional
79
79
  :return: A SignInResponse indicating the result of the sign-in attempt.
80
80
  :rtype: SignInResponse
81
81
  """
@@ -92,9 +92,9 @@ class _AuthorizationHandler(ABC):
92
92
  :param context: The turn context for the current turn of conversation.
93
93
  :type context: TurnContext
94
94
  :param exchange_connection: Optional name of the connection to use for token exchange. If None, default connection will be used.
95
- :type exchange_connection: Optional[str], optional
95
+ :type exchange_connection: Optional[str], Optional
96
96
  :param exchange_scopes: Optional list of scopes to request during token exchange. If None, default scopes will be used.
97
- :type exchange_scopes: Optional[list[str]], optional
97
+ :type exchange_scopes: Optional[list[str]], Optional
98
98
  """
99
99
  raise NotImplementedError()
100
100
 
@@ -249,9 +249,9 @@ class _UserAuthorization(_AuthorizationHandler):
249
249
  :param context: The turn context for the current turn of conversation.
250
250
  :type context: TurnContext
251
251
  :param exchange_connection: Optional name of the connection to use for token exchange. If None, default connection will be used.
252
- :type exchange_connection: Optional[str], optional
252
+ :type exchange_connection: Optional[str], Optional
253
253
  :param exchange_scopes: Optional list of scopes to request during token exchange. If None, default scopes will be used.
254
- :type exchange_scopes: Optional[list[str]], optional
254
+ :type exchange_scopes: Optional[list[str]], Optional
255
255
  """
256
256
  flow, _ = await self._load_flow(context)
257
257
  input_token_response = await flow.get_user_token()
@@ -41,7 +41,7 @@ class AgenticUserAuthorization(_AuthorizationHandler):
41
41
  :param connection_manager: The connection manager for OAuth providers.
42
42
  :type connection_manager: Connections
43
43
  :param auth_handlers: Configuration for OAuth providers.
44
- :type auth_handlers: dict[str, AuthHandler], optional
44
+ :type auth_handlers: dict[str, AuthHandler], Optional
45
45
  :raises ValueError: When storage is None or no auth handlers provided.
46
46
  """
47
47
  super().__init__(
@@ -172,9 +172,9 @@ class AgenticUserAuthorization(_AuthorizationHandler):
172
172
  :param context: The turn context for the current turn of conversation.
173
173
  :type context: TurnContext
174
174
  :param exchange_connection: Optional name of the connection to use for token exchange. If None, default connection will be used.
175
- :type exchange_connection: Optional[str], optional
175
+ :type exchange_connection: Optional[str], Optional
176
176
  :param exchange_scopes: Optional list of scopes to request during token exchange. If None, default scopes will be used.
177
- :type exchange_scopes: Optional[list[str]], optional
177
+ :type exchange_scopes: Optional[list[str]], Optional
178
178
  """
179
179
  if not exchange_scopes:
180
180
  exchange_scopes = self._handler.scopes or []
@@ -55,11 +55,11 @@ class Authorization:
55
55
  only if auth_handlers is empty or None.
56
56
 
57
57
  :param storage: The storage system to use for state management.
58
- :type storage: Storage
58
+ :type storage: :class:`microsoft_agents.hosting.core.storage.Storage`
59
59
  :param connection_manager: The connection manager for OAuth providers.
60
- :type connection_manager: Connections
60
+ :type connection_manager: :class:`microsoft_agents.hosting.core.authorization.Connections`
61
61
  :param auth_handlers: Configuration for OAuth providers.
62
- :type auth_handlers: dict[str, AuthHandler], optional
62
+ :type auth_handlers: dict[str, :class:`microsoft_agents.hosting.core.app.oauth.auth_handler.AuthHandler`], Optional
63
63
  :raises ValueError: When storage is None or no auth handlers provided.
64
64
  """
65
65
  if not storage:
@@ -105,7 +105,7 @@ class Authorization:
105
105
  it initializes an instance of each variant that is referenced.
106
106
 
107
107
  :param auth_handlers: A dictionary of auth handler configurations.
108
- :type auth_handlers: dict[str, AuthHandler]
108
+ :type auth_handlers: dict[str, :class:`microsoft_agents.hosting.core.app.oauth.auth_handler.AuthHandler`]
109
109
  """
110
110
  for name, auth_handler in self._handler_settings.items():
111
111
  auth_type = auth_handler.auth_type
@@ -126,26 +126,42 @@ class Authorization:
126
126
  can be used to inspect or manipulate the state directly if needed.
127
127
 
128
128
  :param context: The turn context for the current turn of conversation.
129
- :type context: TurnContext
129
+ :type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
130
130
  :return: A unique (across other values of channel_id and user_id) key for the sign-in state.
131
131
  :rtype: str
132
132
  """
133
133
  return f"auth:_SignInState:{context.activity.channel_id}:{context.activity.from_property.id}"
134
134
 
135
135
  async def _load_sign_in_state(self, context: TurnContext) -> Optional[_SignInState]:
136
- """Load the sign-in state from storage for the given context."""
136
+ """Load the sign-in state from storage for the given context.
137
+
138
+ :param context: The turn context for the current turn of conversation.
139
+ :type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
140
+ :return: The sign-in state if found, None otherwise.
141
+ :rtype: Optional[:class:`microsoft_agents.hosting.core.app.oauth._sign_in_state._SignInState`]
142
+ """
137
143
  key = self._sign_in_state_key(context)
138
144
  return (await self._storage.read([key], target_cls=_SignInState)).get(key)
139
145
 
140
146
  async def _save_sign_in_state(
141
147
  self, context: TurnContext, state: _SignInState
142
148
  ) -> None:
143
- """Save the sign-in state to storage for the given context."""
149
+ """Save the sign-in state to storage for the given context.
150
+
151
+ :param context: The turn context for the current turn of conversation.
152
+ :type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
153
+ :param state: The sign-in state to save.
154
+ :type state: :class:`microsoft_agents.hosting.core.app.oauth._sign_in_state._SignInState`
155
+ """
144
156
  key = self._sign_in_state_key(context)
145
157
  await self._storage.write({key: state})
146
158
 
147
159
  async def _delete_sign_in_state(self, context: TurnContext) -> None:
148
- """Delete the sign-in state from storage for the given context."""
160
+ """Delete the sign-in state from storage for the given context.
161
+
162
+ :param context: The turn context for the current turn of conversation.
163
+ :type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
164
+ """
149
165
  key = self._sign_in_state_key(context)
150
166
  await self._storage.delete([key])
151
167
 
@@ -179,7 +195,7 @@ class Authorization:
179
195
  :param handler_id: The ID of the auth handler to resolve.
180
196
  :type handler_id: str
181
197
  :return: The corresponding AuthorizationHandler instance.
182
- :rtype: AuthorizationHandler
198
+ :rtype: :class:`microsoft_agents.hosting.core.app.oauth._handlers._AuthorizationHandler`
183
199
  :raises ValueError: If the handler ID is not recognized or not configured.
184
200
  """
185
201
  if handler_id not in self._handlers:
@@ -200,13 +216,13 @@ class Authorization:
200
216
  Storage is updated as needed with _SignInState data for caching purposes.
201
217
 
202
218
  :param context: The turn context for the current turn of conversation.
203
- :type context: TurnContext
219
+ :type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
204
220
  :param state: The turn state for the current turn of conversation.
205
- :type state: TurnState
221
+ :type state: :class:`microsoft_agents.hosting.core.app.state.turn_state.TurnState`
206
222
  :param auth_handler_id: The ID of the auth handler to use for sign-in. If None, the first handler will be used.
207
223
  :type auth_handler_id: str
208
224
  :return: A _SignInResponse indicating the result of the sign-in attempt.
209
- :rtype: _SignInResponse
225
+ :rtype: :class:`microsoft_agents.hosting.core.app.oauth._sign_in_response._SignInResponse`
210
226
  """
211
227
 
212
228
  auth_handler_id = auth_handler_id or self._default_handler_id
@@ -250,7 +266,7 @@ class Authorization:
250
266
  """Attempts to sign out the user from a specified auth handler or the default handler.
251
267
 
252
268
  :param context: The turn context for the current turn of conversation.
253
- :type context: TurnContext
269
+ :type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
254
270
  :param auth_handler_id: The ID of the auth handler to sign out from. If None, sign out from all handlers.
255
271
  :type auth_handler_id: Optional[str]
256
272
  :return: None
@@ -272,11 +288,11 @@ class Authorization:
272
288
  from the cached _SignInState.
273
289
 
274
290
  :param context: The context object for the current turn.
275
- :type context: TurnContext
291
+ :type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
276
292
  :param state: The turn state for the current turn.
277
- :type state: TurnState
293
+ :type state: :class:`microsoft_agents.hosting.core.app.state.turn_state.TurnState`
278
294
  :return: A tuple indicating whether the turn should be skipped and the continuation activity if applicable.
279
- :rtype: tuple[bool, Optional[Activity]]
295
+ :rtype: tuple[bool, Optional[:class:`microsoft_agents.activity.Activity`]]
280
296
  """
281
297
  sign_in_state = await self._load_sign_in_state(context)
282
298
 
@@ -306,11 +322,11 @@ class Authorization:
306
322
  The token is taken from cache, so this does not initiate nor continue a sign-in flow.
307
323
 
308
324
  :param context: The context object for the current turn.
309
- :type context: TurnContext
325
+ :type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
310
326
  :param auth_handler_id: The ID of the auth handler to get the token for.
311
327
  :type auth_handler_id: str
312
328
  :return: The token response from the OAuth provider.
313
- :rtype: TokenResponse
329
+ :rtype: :class:`microsoft_agents.activity.TokenResponse`
314
330
  """
315
331
  return await self.exchange_token(context, auth_handler_id=auth_handler_id)
316
332
 
@@ -324,7 +340,7 @@ class Authorization:
324
340
  """Exchanges or refreshes the token for a specific auth handler or the default handler.
325
341
 
326
342
  :param context: The context object for the current turn.
327
- :type context: TurnContext
343
+ :type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
328
344
  :param scopes: The scopes to request during the token exchange or refresh. Defaults
329
345
  to the list given in the AuthHandler configuration if None.
330
346
  :type scopes: Optional[list[str]]
@@ -335,7 +351,7 @@ class Authorization:
335
351
  the connection defined in the AuthHandler configuration will be used.
336
352
  :type exchange_connection: Optional[str]
337
353
  :return: The token response from the OAuth provider.
338
- :rtype: TokenResponse
354
+ :rtype: :class:`microsoft_agents.activity.TokenResponse`
339
355
  :raises ValueError: If the specified auth handler ID is not recognized or not configured.
340
356
  """
341
357
 
@@ -376,6 +392,7 @@ class Authorization:
376
392
  Sets a handler to be called when sign-in is successfully completed.
377
393
 
378
394
  :param handler: The handler function to call on successful sign-in.
395
+ :type handler: Callable[[:class:`microsoft_agents.hosting.core.turn_context.TurnContext`, :class:`microsoft_agents.hosting.core.app.state.turn_state.TurnState`, Optional[str]], Awaitable[None]]
379
396
  """
380
397
  self._sign_in_success_handler = handler
381
398
 
@@ -387,5 +404,6 @@ class Authorization:
387
404
  Sets a handler to be called when sign-in fails.
388
405
 
389
406
  :param handler: The handler function to call on sign-in failure.
407
+ :type handler: Callable[[:class:`microsoft_agents.hosting.core.turn_context.TurnContext`, :class:`microsoft_agents.hosting.core.app.state.turn_state.TurnState`, Optional[str]], Awaitable[None]]
390
408
  """
391
409
  self._sign_in_failure_handler = handler