microsoft-agents-hosting-core 0.3.0.dev0__py3-none-any.whl → 0.4.0.dev3__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 (88) hide show
  1. {microsoft/agents → microsoft_agents}/hosting/core/__init__.py +18 -5
  2. {microsoft/agents → microsoft_agents}/hosting/core/activity_handler.py +26 -26
  3. {microsoft/agents → microsoft_agents}/hosting/core/app/__init__.py +4 -6
  4. {microsoft/agents → microsoft_agents}/hosting/core/app/agent_application.py +135 -38
  5. {microsoft/agents → microsoft_agents}/hosting/core/app/app_options.py +3 -3
  6. {microsoft/agents → microsoft_agents}/hosting/core/app/input_file.py +1 -1
  7. microsoft_agents/hosting/core/app/oauth/__init__.py +8 -0
  8. microsoft_agents/hosting/core/app/oauth/auth_handler.py +48 -0
  9. microsoft_agents/hosting/core/app/oauth/authorization.py +398 -0
  10. {microsoft/agents → microsoft_agents}/hosting/core/app/route.py +1 -1
  11. {microsoft/agents → microsoft_agents}/hosting/core/app/state/conversation_state.py +6 -3
  12. {microsoft/agents → microsoft_agents}/hosting/core/app/state/state.py +3 -3
  13. {microsoft/agents → microsoft_agents}/hosting/core/app/state/temp_state.py +9 -5
  14. {microsoft/agents → microsoft_agents}/hosting/core/app/state/turn_state.py +15 -10
  15. {microsoft/agents → microsoft_agents}/hosting/core/app/typing_indicator.py +2 -2
  16. {microsoft/agents → microsoft_agents}/hosting/core/authorization/agent_auth_configuration.py +1 -1
  17. {microsoft/agents → microsoft_agents}/hosting/core/card_factory.py +1 -1
  18. {microsoft/agents → microsoft_agents}/hosting/core/channel_adapter.py +13 -13
  19. {microsoft/agents → microsoft_agents}/hosting/core/channel_api_handler_protocol.py +2 -2
  20. {microsoft/agents → microsoft_agents}/hosting/core/channel_service_adapter.py +4 -4
  21. {microsoft/agents → microsoft_agents}/hosting/core/channel_service_client_factory_base.py +2 -2
  22. {microsoft/agents → microsoft_agents}/hosting/core/client/agent_conversation_reference.py +1 -1
  23. {microsoft/agents → microsoft_agents}/hosting/core/client/channel_factory_protocol.py +1 -1
  24. {microsoft/agents → microsoft_agents}/hosting/core/client/channel_protocol.py +1 -1
  25. {microsoft/agents → microsoft_agents}/hosting/core/client/configuration_channel_host.py +1 -1
  26. {microsoft/agents → microsoft_agents}/hosting/core/client/conversation_id_factory.py +2 -2
  27. {microsoft/agents → microsoft_agents}/hosting/core/client/conversation_id_factory_options.py +1 -1
  28. {microsoft/agents → microsoft_agents}/hosting/core/client/http_agent_channel.py +2 -2
  29. {microsoft/agents → microsoft_agents}/hosting/core/client/http_agent_channel_factory.py +1 -1
  30. {microsoft/agents → microsoft_agents}/hosting/core/connector/agent_sign_in_base.py +1 -1
  31. {microsoft/agents → microsoft_agents}/hosting/core/connector/attachments_base.py +1 -1
  32. {microsoft/agents → microsoft_agents}/hosting/core/connector/client/connector_client.py +2 -2
  33. {microsoft/agents → microsoft_agents}/hosting/core/connector/client/user_token_client.py +2 -2
  34. {microsoft/agents → microsoft_agents}/hosting/core/connector/conversations_base.py +1 -1
  35. {microsoft/agents → microsoft_agents}/hosting/core/connector/teams/teams_connector_client.py +5 -5
  36. {microsoft/agents → microsoft_agents}/hosting/core/connector/user_token_base.py +1 -1
  37. {microsoft/agents → microsoft_agents}/hosting/core/message_factory.py +1 -1
  38. microsoft_agents/hosting/core/oauth/__init__.py +12 -0
  39. microsoft_agents/hosting/core/oauth/flow_state.py +81 -0
  40. microsoft_agents/hosting/core/oauth/flow_storage_client.py +93 -0
  41. microsoft_agents/hosting/core/oauth/oauth_flow.py +341 -0
  42. {microsoft/agents → microsoft_agents}/hosting/core/rest_channel_service_client_factory.py +5 -5
  43. {microsoft/agents → microsoft_agents}/hosting/core/state/agent_state.py +2 -2
  44. {microsoft/agents → microsoft_agents}/hosting/core/state/state_property_accessor.py +1 -1
  45. {microsoft/agents → microsoft_agents}/hosting/core/state/user_state.py +1 -1
  46. microsoft/agents/hosting/core/storage/storage_test_utils.py → microsoft_agents/hosting/core/storage/_storage_test_utils.py +2 -0
  47. {microsoft/agents → microsoft_agents}/hosting/core/turn_context.py +3 -3
  48. {microsoft_agents_hosting_core-0.3.0.dev0.dist-info → microsoft_agents_hosting_core-0.4.0.dev3.dist-info}/METADATA +2 -2
  49. microsoft_agents_hosting_core-0.4.0.dev3.dist-info/RECORD +83 -0
  50. microsoft_agents_hosting_core-0.4.0.dev3.dist-info/top_level.txt +1 -0
  51. microsoft/agents/hosting/core/app/oauth/__init__.py +0 -8
  52. microsoft/agents/hosting/core/app/oauth/authorization.py +0 -431
  53. microsoft/agents/hosting/core/oauth_flow.py +0 -397
  54. microsoft_agents_hosting_core-0.3.0.dev0.dist-info/RECORD +0 -79
  55. microsoft_agents_hosting_core-0.3.0.dev0.dist-info/top_level.txt +0 -1
  56. {microsoft/agents → microsoft_agents}/hosting/core/agent.py +0 -0
  57. {microsoft/agents → microsoft_agents}/hosting/core/app/app_error.py +0 -0
  58. {microsoft/agents → microsoft_agents}/hosting/core/app/query.py +0 -0
  59. {microsoft/agents → microsoft_agents}/hosting/core/app/state/__init__.py +0 -0
  60. {microsoft/agents → microsoft_agents}/hosting/core/authorization/__init__.py +0 -0
  61. {microsoft/agents → microsoft_agents}/hosting/core/authorization/access_token_provider_base.py +0 -0
  62. {microsoft/agents → microsoft_agents}/hosting/core/authorization/anonymous_token_provider.py +0 -0
  63. {microsoft/agents → microsoft_agents}/hosting/core/authorization/auth_types.py +0 -0
  64. {microsoft/agents → microsoft_agents}/hosting/core/authorization/authentication_constants.py +0 -0
  65. {microsoft/agents → microsoft_agents}/hosting/core/authorization/claims_identity.py +0 -0
  66. {microsoft/agents → microsoft_agents}/hosting/core/authorization/connections.py +0 -0
  67. {microsoft/agents → microsoft_agents}/hosting/core/authorization/jwt_token_validator.py +0 -0
  68. {microsoft/agents → microsoft_agents}/hosting/core/client/__init__.py +0 -0
  69. {microsoft/agents → microsoft_agents}/hosting/core/client/channel_host_protocol.py +0 -0
  70. {microsoft/agents → microsoft_agents}/hosting/core/client/channel_info_protocol.py +0 -0
  71. {microsoft/agents → microsoft_agents}/hosting/core/client/channels_configuration.py +0 -0
  72. {microsoft/agents → microsoft_agents}/hosting/core/client/conversation_constants.py +0 -0
  73. {microsoft/agents → microsoft_agents}/hosting/core/client/conversation_id_factory_protocol.py +0 -0
  74. {microsoft/agents → microsoft_agents}/hosting/core/connector/__init__.py +0 -0
  75. {microsoft/agents → microsoft_agents}/hosting/core/connector/client/__init__.py +0 -0
  76. {microsoft/agents → microsoft_agents}/hosting/core/connector/connector_client_base.py +0 -0
  77. {microsoft/agents → microsoft_agents}/hosting/core/connector/get_product_info.py +0 -0
  78. {microsoft/agents → microsoft_agents}/hosting/core/connector/teams/__init__.py +0 -0
  79. {microsoft/agents → microsoft_agents}/hosting/core/connector/user_token_client_base.py +0 -0
  80. {microsoft/agents → microsoft_agents}/hosting/core/middleware_set.py +0 -0
  81. {microsoft/agents → microsoft_agents}/hosting/core/state/__init__.py +0 -0
  82. {microsoft/agents → microsoft_agents}/hosting/core/storage/__init__.py +0 -0
  83. {microsoft/agents → microsoft_agents}/hosting/core/storage/_type_aliases.py +0 -0
  84. {microsoft/agents → microsoft_agents}/hosting/core/storage/error_handling.py +0 -0
  85. {microsoft/agents → microsoft_agents}/hosting/core/storage/memory_storage.py +0 -0
  86. {microsoft/agents → microsoft_agents}/hosting/core/storage/storage.py +0 -0
  87. {microsoft/agents → microsoft_agents}/hosting/core/storage/store_item.py +0 -0
  88. {microsoft_agents_hosting_core-0.3.0.dev0.dist-info → microsoft_agents_hosting_core-0.4.0.dev3.dist-info}/WHEEL +0 -0
@@ -1,6 +1,5 @@
1
1
  from .activity_handler import ActivityHandler
2
2
  from .agent import Agent
3
- from .oauth_flow import OAuthFlow
4
3
  from .card_factory import CardFactory
5
4
  from .channel_adapter import ChannelAdapter
6
5
  from .channel_api_handler_protocol import ChannelApiHandlerProtocol
@@ -20,12 +19,11 @@ from .app.query import Query
20
19
  from .app.route import Route, RouteHandler
21
20
  from .app.typing_indicator import TypingIndicator
22
21
 
23
- # OAuth
24
- from .app.oauth.authorization import (
22
+ # App Auth
23
+ from .app.oauth import (
25
24
  Authorization,
26
25
  AuthorizationHandlers,
27
26
  AuthHandler,
28
- SignInState,
29
27
  )
30
28
 
31
29
  # App State
@@ -44,6 +42,16 @@ from .authorization.claims_identity import ClaimsIdentity
44
42
  from .authorization.jwt_token_validator import JwtTokenValidator
45
43
  from .authorization.auth_types import AuthTypes
46
44
 
45
+ # OAuth
46
+ from .oauth import (
47
+ FlowState,
48
+ FlowStateTag,
49
+ FlowErrorTag,
50
+ FlowResponse,
51
+ FlowStorageClient,
52
+ OAuthFlow,
53
+ )
54
+
47
55
  # Client API
48
56
  from .client.agent_conversation_reference import AgentConversationReference
49
57
  from .client.channel_factory_protocol import ChannelFactoryProtocol
@@ -88,7 +96,6 @@ from .storage.memory_storage import MemoryStorage
88
96
  __all__ = [
89
97
  "ActivityHandler",
90
98
  "Agent",
91
- "OAuthFlow",
92
99
  "CardFactory",
93
100
  "ChannelAdapter",
94
101
  "ChannelApiHandlerProtocol",
@@ -155,4 +162,10 @@ __all__ = [
155
162
  "StoreItem",
156
163
  "Storage",
157
164
  "MemoryStorage",
165
+ "FlowState",
166
+ "FlowStateTag",
167
+ "FlowErrorTag",
168
+ "FlowResponse",
169
+ "FlowStorageClient",
170
+ "OAuthFlow",
158
171
  ]
@@ -4,8 +4,8 @@ from __future__ import annotations
4
4
  from http import HTTPStatus
5
5
  from pydantic import BaseModel
6
6
 
7
- from microsoft.agents.activity import TurnContextProtocol
8
- from microsoft.agents.activity import (
7
+ from microsoft_agents.activity import TurnContextProtocol
8
+ from microsoft_agents.activity import (
9
9
  Activity,
10
10
  ActivityTypes,
11
11
  AdaptiveCardInvokeResponse,
@@ -34,10 +34,10 @@ class ActivityHandler(Agent):
34
34
  ): # pylint: disable=arguments-differ
35
35
  """
36
36
  Called by the adapter (for example, :class:`ChannelAdapter`) at runtime
37
- in order to process an inbound :class:`hosting.schema.Activity`.
37
+ in order to process an inbound :class:`microsoft_agents.activity.Activity`.
38
38
 
39
39
  :param turn_context: The context object for this turn
40
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
40
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
41
41
 
42
42
  :returns: A task that represents the work queued to execute
43
43
 
@@ -105,7 +105,7 @@ class ActivityHandler(Agent):
105
105
  such as the conversational logic.
106
106
 
107
107
  :param turn_context: The context object for this turn
108
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
108
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
109
109
 
110
110
  :returns: A task that represents the work queued to execute
111
111
  """
@@ -119,7 +119,7 @@ class ActivityHandler(Agent):
119
119
  such as the conversational logic.
120
120
 
121
121
  :param turn_context: The context object for this turn
122
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
122
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
123
123
 
124
124
  :returns: A task that represents the work queued to execute
125
125
  """
@@ -133,7 +133,7 @@ class ActivityHandler(Agent):
133
133
  such as the conversational logic.
134
134
 
135
135
  :param turn_context: The context object for this turn
136
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
136
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
137
137
 
138
138
  :returns: A task that represents the work queued to execute
139
139
  """
@@ -145,7 +145,7 @@ class ActivityHandler(Agent):
145
145
  :meth:`on_turn()` is used.
146
146
 
147
147
  :param turn_context: The context object for this turn
148
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
148
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
149
149
 
150
150
  :returns: A task that represents the work queued to execute
151
151
 
@@ -181,7 +181,7 @@ class ActivityHandler(Agent):
181
181
  conversation update activity
182
182
  :type members_added: :class:`typing.List`
183
183
  :param turn_context: The context object for this turn
184
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
184
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
185
185
 
186
186
  :returns: A task that represents the work queued to execute
187
187
 
@@ -203,7 +203,7 @@ class ActivityHandler(Agent):
203
203
  conversation update activity
204
204
  :type members_added: :class:`typing.List`
205
205
  :param turn_context: The context object for this turn
206
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
206
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
207
207
 
208
208
  :returns: A task that represents the work queued to execute
209
209
 
@@ -221,7 +221,7 @@ class ActivityHandler(Agent):
221
221
  :meth:`on_turn()` is used.
222
222
 
223
223
  :param turn_context: The context object for this turn
224
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
224
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
225
225
 
226
226
  :returns: A task that represents the work queued to execute
227
227
 
@@ -267,7 +267,7 @@ class ActivityHandler(Agent):
267
267
  :param message_reactions: The list of reactions added
268
268
  :type message_reactions: :class:`typing.List`
269
269
  :param turn_context: The context object for this turn
270
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
270
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
271
271
 
272
272
  :returns: A task that represents the work queued to execute
273
273
 
@@ -293,7 +293,7 @@ class ActivityHandler(Agent):
293
293
  :param message_reactions: The list of reactions removed
294
294
  :type message_reactions: :class:`typing.List`
295
295
  :param turn_context: The context object for this turn
296
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
296
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
297
297
 
298
298
  :returns: A task that represents the work queued to execute
299
299
 
@@ -312,7 +312,7 @@ class ActivityHandler(Agent):
312
312
  :meth:`on_turn()` is used.
313
313
 
314
314
  :param turn_context: The context object for this turn
315
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
315
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
316
316
 
317
317
  :returns: A task that represents the work queued to execute
318
318
 
@@ -343,7 +343,7 @@ class ActivityHandler(Agent):
343
343
  If using an `oauth_prompt`, override this method to forward this activity to the current dialog.
344
344
 
345
345
  :param turn_context: The context object for this turn
346
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
346
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
347
347
 
348
348
  :returns: A task that represents the work queued to execute
349
349
 
@@ -363,7 +363,7 @@ class ActivityHandler(Agent):
363
363
 
364
364
 
365
365
  :param turn_context: The context object for this turn
366
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
366
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
367
367
 
368
368
  :returns: A task that represents the work queued to execute
369
369
 
@@ -381,7 +381,7 @@ class ActivityHandler(Agent):
381
381
  Invoked when a conversation end activity is received from the channel.
382
382
 
383
383
  :param turn_context: The context object for this turn
384
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
384
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
385
385
  :returns: A task that represents the work queued to execute
386
386
  """
387
387
  return
@@ -394,7 +394,7 @@ class ActivityHandler(Agent):
394
394
  ActivityTypes.typing activities, such as the conversational logic.
395
395
 
396
396
  :param turn_context: The context object for this turn
397
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
397
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
398
398
  :returns: A task that represents the work queued to execute
399
399
  """
400
400
  return
@@ -407,7 +407,7 @@ class ActivityHandler(Agent):
407
407
  ActivityTypes.InstallationUpdate activities.
408
408
 
409
409
  :param turn_context: The context object for this turn
410
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
410
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
411
411
  :returns: A task that represents the work queued to execute
412
412
  """
413
413
  if turn_context.activity.action in ("add", "add-upgrade"):
@@ -424,7 +424,7 @@ class ActivityHandler(Agent):
424
424
  ActivityTypes.InstallationUpdate activities with 'action' set to 'add'.
425
425
 
426
426
  :param turn_context: The context object for this turn
427
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
427
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
428
428
  :returns: A task that represents the work queued to execute
429
429
  """
430
430
  return
@@ -437,7 +437,7 @@ class ActivityHandler(Agent):
437
437
  ActivityTypes.InstallationUpdate activities with 'action' set to 'remove'.
438
438
 
439
439
  :param turn_context: The context object for this turn
440
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
440
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
441
441
  :returns: A task that represents the work queued to execute
442
442
  """
443
443
  return
@@ -451,7 +451,7 @@ class ActivityHandler(Agent):
451
451
  If overridden, this method could potentially respond to any of the other activity types.
452
452
 
453
453
  :param turn_context: The context object for this turn
454
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
454
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
455
455
 
456
456
  :returns: A task that represents the work queued to execute
457
457
 
@@ -468,7 +468,7 @@ class ActivityHandler(Agent):
468
468
  Registers an activity event handler for the _invoke_ event, emitted for every incoming event activity.
469
469
 
470
470
  :param turn_context: The context object for this turn
471
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
471
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
472
472
 
473
473
  :returns: A task that represents the work queued to execute
474
474
  """
@@ -504,7 +504,7 @@ class ActivityHandler(Agent):
504
504
  By default, this method does nothing.
505
505
 
506
506
  :param turn_context: The context object for this turn
507
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
507
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
508
508
 
509
509
  :returns: A task that represents the work queued to execute
510
510
  """
@@ -520,9 +520,9 @@ class ActivityHandler(Agent):
520
520
  calls this method.
521
521
 
522
522
  :param turn_context: A context object for this turn.
523
- :type turn_context: :class:`microsoft.agents.builder.TurnContext`
523
+ :type turn_context: :class:`microsoft_agents.builder.TurnContext`
524
524
  :param invoke_value: A string-typed object from the incoming activity's value.
525
- :type invoke_value: :class:`microsoft.agents.activity.models.AdaptiveCardInvokeValue`
525
+ :type invoke_value: :class:`microsoft_agents.activity.models.AdaptiveCardInvokeValue`
526
526
  :return: The HealthCheckResponse object
527
527
  """
528
528
  raise _InvokeResponseException(HTTPStatus.NOT_IMPLEMENTED)
@@ -13,12 +13,11 @@ from .query import Query
13
13
  from .route import Route, RouteHandler
14
14
  from .typing_indicator import TypingIndicator
15
15
 
16
- # OAuth
17
- from .oauth.authorization import (
16
+ # Auth
17
+ from .oauth import (
18
18
  Authorization,
19
- AuthorizationHandlers,
20
19
  AuthHandler,
21
- SignInState,
20
+ AuthorizationHandlers,
22
21
  )
23
22
 
24
23
  # App State
@@ -49,7 +48,6 @@ __all__ = [
49
48
  "TurnState",
50
49
  "TempState",
51
50
  "Authorization",
52
- "AuthorizationHandlers",
53
51
  "AuthHandler",
54
- "SignInState",
52
+ "AuthorizationHandlers",
55
53
  ]
@@ -23,18 +23,24 @@ from typing import (
23
23
  cast,
24
24
  )
25
25
 
26
- from microsoft.agents.hosting.core.authorization import Connections
26
+ from microsoft_agents.hosting.core.authorization import Connections
27
27
 
28
- from microsoft.agents.hosting.core import Agent, TurnContext
29
- from microsoft.agents.activity import (
28
+ from microsoft_agents.hosting.core import Agent, TurnContext
29
+ from microsoft_agents.activity import (
30
30
  Activity,
31
31
  ActivityTypes,
32
+ ActionTypes,
32
33
  ConversationUpdateTypes,
33
34
  MessageReactionTypes,
34
35
  MessageUpdateTypes,
35
36
  InvokeResponse,
37
+ TokenResponse,
38
+ OAuthCard,
39
+ Attachment,
40
+ CardAction,
36
41
  )
37
42
 
43
+ from .. import CardFactory, MessageFactory
38
44
  from .app_error import ApplicationError
39
45
  from .app_options import ApplicationOptions
40
46
 
@@ -42,7 +48,12 @@ from .app_options import ApplicationOptions
42
48
  from .route import Route, RouteHandler
43
49
  from .state import TurnState
44
50
  from ..channel_service_adapter import ChannelServiceAdapter
45
- from .oauth import Authorization, SignInState
51
+ from ..oauth import (
52
+ FlowResponse,
53
+ FlowState,
54
+ FlowStateTag,
55
+ )
56
+ from .oauth import Authorization
46
57
  from .typing_indicator import TypingIndicator
47
58
 
48
59
  logger = logging.getLogger(__name__)
@@ -592,6 +603,103 @@ class AgentApplication(Agent, Generic[StateT]):
592
603
  self._turn_state_factory = func
593
604
  return func
594
605
 
606
+ async def _handle_flow_response(
607
+ self, context: TurnContext, flow_response: FlowResponse
608
+ ) -> None:
609
+ """Handles CONTINUE and FAILURE flow responses, sending activities back."""
610
+ flow_state: FlowState = flow_response.flow_state
611
+
612
+ if flow_state.tag == FlowStateTag.BEGIN:
613
+ # Create the OAuth card
614
+ sign_in_resource = flow_response.sign_in_resource
615
+ o_card: Attachment = CardFactory.oauth_card(
616
+ OAuthCard(
617
+ text="Sign in",
618
+ connection_name=flow_state.connection,
619
+ buttons=[
620
+ CardAction(
621
+ title="Sign in",
622
+ type=ActionTypes.signin,
623
+ value=sign_in_resource.sign_in_link,
624
+ channel_data=None,
625
+ )
626
+ ],
627
+ token_exchange_resource=sign_in_resource.token_exchange_resource,
628
+ token_post_resource=sign_in_resource.token_post_resource,
629
+ )
630
+ )
631
+ # Send the card to the user
632
+ await context.send_activity(MessageFactory.attachment(o_card))
633
+ elif flow_state.tag == FlowStateTag.FAILURE:
634
+ if flow_state.reached_max_attempts():
635
+ await context.send_activity(
636
+ MessageFactory.text(
637
+ "Sign-in failed. Max retries reached. Please try again later."
638
+ )
639
+ )
640
+ elif flow_state.is_expired():
641
+ await context.send_activity(
642
+ MessageFactory.text("Sign-in session expired. Please try again.")
643
+ )
644
+ else:
645
+ logger.warning("Sign-in flow failed for unknown reasons.")
646
+ await context.send_activity("Sign-in failed. Please try again.")
647
+
648
+ async def _on_turn_auth_intercept(
649
+ self, context: TurnContext, turn_state: TurnState
650
+ ) -> bool:
651
+ """Intercepts the turn to check for active authentication flows."""
652
+ logger.debug(
653
+ "Checking for active sign-in flow for context: %s with activity type %s",
654
+ context.activity.id,
655
+ context.activity.type,
656
+ )
657
+ prev_flow_state = await self._auth.get_active_flow_state(context)
658
+ if prev_flow_state:
659
+ logger.debug(
660
+ "Previous flow state: %s",
661
+ {
662
+ "user_id": prev_flow_state.user_id,
663
+ "connection": prev_flow_state.connection,
664
+ "channel_id": prev_flow_state.channel_id,
665
+ "auth_handler_id": prev_flow_state.auth_handler_id,
666
+ "tag": prev_flow_state.tag,
667
+ "expiration": prev_flow_state.expiration,
668
+ },
669
+ )
670
+ # proceed if there is an existing flow to continue
671
+ # new flows should be initiated in _on_activity
672
+ # this can be reorganized later... but it works for now
673
+ if (
674
+ prev_flow_state
675
+ and (
676
+ prev_flow_state.tag == FlowStateTag.NOT_STARTED
677
+ or prev_flow_state.is_active()
678
+ )
679
+ and context.activity.type in [ActivityTypes.message, ActivityTypes.invoke]
680
+ ):
681
+
682
+ logger.debug("Sign-in flow is active for context: %s", context.activity.id)
683
+
684
+ flow_response: FlowResponse = await self._auth.begin_or_continue_flow(
685
+ context, turn_state, prev_flow_state.auth_handler_id
686
+ )
687
+
688
+ await self._handle_flow_response(context, flow_response)
689
+
690
+ new_flow_state: FlowState = flow_response.flow_state
691
+ token_response: TokenResponse = flow_response.token_response
692
+ saved_activity: Activity = new_flow_state.continuation_activity.model_copy()
693
+
694
+ if token_response:
695
+ new_context = copy(context)
696
+ new_context.activity = saved_activity
697
+ logger.info("Resending continuation activity %s", saved_activity.text)
698
+ await self.on_turn(new_context)
699
+ await turn_state.save(context)
700
+ return True # early return from _on_turn
701
+ return False # continue _on_turn
702
+
595
703
  async def on_turn(self, context: TurnContext):
596
704
  logger.debug(
597
705
  f"AgentApplication.on_turn(): Processing turn for context: {context.activity.id}"
@@ -599,6 +707,7 @@ class AgentApplication(Agent, Generic[StateT]):
599
707
  await self._start_long_running_call(context, self._on_turn)
600
708
 
601
709
  async def _on_turn(self, context: TurnContext):
710
+ # robrandao: TODO
602
711
  try:
603
712
  await self._start_typing(context)
604
713
 
@@ -607,32 +716,8 @@ class AgentApplication(Agent, Generic[StateT]):
607
716
  logger.debug("Initializing turn state")
608
717
  turn_state = await self._initialize_state(context)
609
718
 
610
- sign_in_state = turn_state.get_value(
611
- Authorization.SIGN_IN_STATE_KEY, target_cls=SignInState
612
- )
613
- logger.debug(
614
- f"Sign-in state: {sign_in_state} for context: {context.activity.id}"
615
- )
616
-
617
- if self._auth and sign_in_state and not sign_in_state.completed:
618
- flow_state = self._auth.get_flow_state(sign_in_state.handler_id)
619
- logger.debug("Flow state: %s", flow_state)
620
- if flow_state.flow_started:
621
- logger.debug("Continuing sign-in flow")
622
- token_response = await self._auth.begin_or_continue_flow(
623
- context, turn_state, sign_in_state.handler_id
624
- )
625
- saved_activity = sign_in_state.continuation_activity.model_copy()
626
- if token_response and token_response.token:
627
- new_context = copy(context)
628
- new_context.activity = saved_activity
629
- logger.info(
630
- "Resending continuation activity %s", saved_activity.text
631
- )
632
- await self.on_turn(new_context)
633
- turn_state.delete_value(Authorization.SIGN_IN_STATE_KEY)
634
- await turn_state.save(context)
635
- return
719
+ if self._auth and await self._on_turn_auth_intercept(context, turn_state):
720
+ return
636
721
 
637
722
  logger.debug("Running before turn middleware")
638
723
  if not await self._run_before_turn_middleware(context, turn_state):
@@ -645,7 +730,7 @@ class AgentApplication(Agent, Generic[StateT]):
645
730
  await self._on_activity(context, turn_state)
646
731
 
647
732
  logger.debug("Running after turn middleware")
648
- if not await self._run_after_turn_middleware(context, turn_state):
733
+ if await self._run_after_turn_middleware(context, turn_state):
649
734
  await turn_state.save(context)
650
735
  return
651
736
  except ApplicationError as err:
@@ -655,12 +740,10 @@ class AgentApplication(Agent, Generic[StateT]):
655
740
  )
656
741
  await self._on_error(context, err)
657
742
  finally:
658
- logger.debug("Stopping typing indicator")
659
743
  self.typing.stop()
660
744
 
661
745
  async def _start_typing(self, context: TurnContext):
662
746
  if self._options.start_typing_timer:
663
- logger.debug("Starting typing indicator for context")
664
747
  await self.typing.start(context)
665
748
 
666
749
  def _remove_mentions(self, context: TurnContext):
@@ -715,7 +798,7 @@ class AgentApplication(Agent, Generic[StateT]):
715
798
  for before_turn in self._internal_before_turn:
716
799
  is_ok = await before_turn(context, state)
717
800
  if not is_ok:
718
- await state.save(context, self._options.storage)
801
+ await state.save(context)
719
802
  return False
720
803
  return True
721
804
 
@@ -741,7 +824,7 @@ class AgentApplication(Agent, Generic[StateT]):
741
824
  for after_turn in self._internal_after_turn:
742
825
  is_ok = await after_turn(context, state)
743
826
  if not is_ok:
744
- await state.save(context, self._options.storage)
827
+ await state.save(context)
745
828
  return False
746
829
  return True
747
830
 
@@ -753,12 +836,26 @@ class AgentApplication(Agent, Generic[StateT]):
753
836
  else:
754
837
  sign_in_complete = False
755
838
  for auth_handler_id in route.auth_handlers:
756
- token_response = await self._auth.begin_or_continue_flow(
757
- context, state, auth_handler_id
839
+ logger.debug(
840
+ "Beginning or continuing flow for auth handler %s",
841
+ auth_handler_id,
842
+ )
843
+ flow_response: FlowResponse = (
844
+ await self._auth.begin_or_continue_flow(
845
+ context, state, auth_handler_id
846
+ )
847
+ )
848
+ await self._handle_flow_response(context, flow_response)
849
+ logger.debug(
850
+ "Flow response flow_state.tag: %s",
851
+ flow_response.flow_state.tag,
852
+ )
853
+ sign_in_complete = (
854
+ flow_response.flow_state.tag == FlowStateTag.COMPLETE
758
855
  )
759
- sign_in_complete = token_response and token_response.token
760
856
  if not sign_in_complete:
761
857
  break
858
+
762
859
  if sign_in_complete:
763
860
  await route.handler(context, state)
764
861
  return
@@ -9,8 +9,8 @@ from dataclasses import dataclass, field
9
9
  from logging import Logger
10
10
  from typing import Callable, List, Optional
11
11
 
12
- from microsoft.agents.hosting.core.app.oauth.authorization import AuthorizationHandlers
13
- from microsoft.agents.hosting.core.storage import Storage
12
+ from microsoft_agents.hosting.core.app.oauth import AuthHandler
13
+ from microsoft_agents.hosting.core.storage import Storage
14
14
 
15
15
  # from .auth import AuthOptions
16
16
  from .input_file import InputFileDownloader
@@ -84,7 +84,7 @@ class ApplicationOptions:
84
84
  If not provided, the default `TurnState` will be used.
85
85
  """
86
86
 
87
- authorization_handlers: Optional[AuthorizationHandlers] = None
87
+ authorization_handlers: Optional[dict[str, AuthHandler]] = None
88
88
  """
89
89
  Optional. Authorization handler for OAuth flows.
90
90
  If not provided, no OAuth flows will be supported.
@@ -9,7 +9,7 @@ from abc import ABC, abstractmethod
9
9
  from dataclasses import dataclass
10
10
  from typing import List, Optional
11
11
 
12
- from microsoft.agents.hosting.core import TurnContext
12
+ from microsoft_agents.hosting.core import TurnContext
13
13
 
14
14
 
15
15
  @dataclass
@@ -0,0 +1,8 @@
1
+ from .authorization import Authorization
2
+ from .auth_handler import AuthHandler, AuthorizationHandlers
3
+
4
+ __all__ = [
5
+ "Authorization",
6
+ "AuthHandler",
7
+ "AuthorizationHandlers",
8
+ ]
@@ -0,0 +1,48 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
4
+ import logging
5
+ from typing import Dict
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+
10
+ class AuthHandler:
11
+ """
12
+ Interface defining an authorization handler for OAuth flows.
13
+ """
14
+
15
+ def __init__(
16
+ self,
17
+ name: str = None,
18
+ title: str = None,
19
+ text: str = None,
20
+ abs_oauth_connection_name: str = None,
21
+ obo_connection_name: str = None,
22
+ **kwargs,
23
+ ):
24
+ """
25
+ Initializes a new instance of AuthHandler.
26
+
27
+ Args:
28
+ name: The name of the OAuth connection.
29
+ auto: Whether to automatically start the OAuth flow.
30
+ title: Title for the OAuth card.
31
+ text: Text for the OAuth button.
32
+ """
33
+ self.name = name or kwargs.get("NAME")
34
+ self.title = title or kwargs.get("TITLE")
35
+ self.text = text or kwargs.get("TEXT")
36
+ self.abs_oauth_connection_name = abs_oauth_connection_name or kwargs.get(
37
+ "AZUREBOTOAUTHCONNECTIONNAME"
38
+ )
39
+ self.obo_connection_name = obo_connection_name or kwargs.get(
40
+ "OBOCONNECTIONNAME"
41
+ )
42
+ logger.debug(
43
+ f"AuthHandler initialized: name={self.name}, title={self.title}, text={self.text} abs_connection_name={self.abs_oauth_connection_name} obo_connection_name={self.obo_connection_name}"
44
+ )
45
+
46
+
47
+ # # Type alias for authorization handlers dictionary
48
+ AuthorizationHandlers = Dict[str, AuthHandler]