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.
- {microsoft/agents → microsoft_agents}/hosting/core/__init__.py +18 -5
- {microsoft/agents → microsoft_agents}/hosting/core/activity_handler.py +26 -26
- {microsoft/agents → microsoft_agents}/hosting/core/app/__init__.py +4 -6
- {microsoft/agents → microsoft_agents}/hosting/core/app/agent_application.py +135 -38
- {microsoft/agents → microsoft_agents}/hosting/core/app/app_options.py +3 -3
- {microsoft/agents → microsoft_agents}/hosting/core/app/input_file.py +1 -1
- microsoft_agents/hosting/core/app/oauth/__init__.py +8 -0
- microsoft_agents/hosting/core/app/oauth/auth_handler.py +48 -0
- microsoft_agents/hosting/core/app/oauth/authorization.py +398 -0
- {microsoft/agents → microsoft_agents}/hosting/core/app/route.py +1 -1
- {microsoft/agents → microsoft_agents}/hosting/core/app/state/conversation_state.py +6 -3
- {microsoft/agents → microsoft_agents}/hosting/core/app/state/state.py +3 -3
- {microsoft/agents → microsoft_agents}/hosting/core/app/state/temp_state.py +9 -5
- {microsoft/agents → microsoft_agents}/hosting/core/app/state/turn_state.py +15 -10
- {microsoft/agents → microsoft_agents}/hosting/core/app/typing_indicator.py +2 -2
- {microsoft/agents → microsoft_agents}/hosting/core/authorization/agent_auth_configuration.py +1 -1
- {microsoft/agents → microsoft_agents}/hosting/core/card_factory.py +1 -1
- {microsoft/agents → microsoft_agents}/hosting/core/channel_adapter.py +13 -13
- {microsoft/agents → microsoft_agents}/hosting/core/channel_api_handler_protocol.py +2 -2
- {microsoft/agents → microsoft_agents}/hosting/core/channel_service_adapter.py +4 -4
- {microsoft/agents → microsoft_agents}/hosting/core/channel_service_client_factory_base.py +2 -2
- {microsoft/agents → microsoft_agents}/hosting/core/client/agent_conversation_reference.py +1 -1
- {microsoft/agents → microsoft_agents}/hosting/core/client/channel_factory_protocol.py +1 -1
- {microsoft/agents → microsoft_agents}/hosting/core/client/channel_protocol.py +1 -1
- {microsoft/agents → microsoft_agents}/hosting/core/client/configuration_channel_host.py +1 -1
- {microsoft/agents → microsoft_agents}/hosting/core/client/conversation_id_factory.py +2 -2
- {microsoft/agents → microsoft_agents}/hosting/core/client/conversation_id_factory_options.py +1 -1
- {microsoft/agents → microsoft_agents}/hosting/core/client/http_agent_channel.py +2 -2
- {microsoft/agents → microsoft_agents}/hosting/core/client/http_agent_channel_factory.py +1 -1
- {microsoft/agents → microsoft_agents}/hosting/core/connector/agent_sign_in_base.py +1 -1
- {microsoft/agents → microsoft_agents}/hosting/core/connector/attachments_base.py +1 -1
- {microsoft/agents → microsoft_agents}/hosting/core/connector/client/connector_client.py +2 -2
- {microsoft/agents → microsoft_agents}/hosting/core/connector/client/user_token_client.py +2 -2
- {microsoft/agents → microsoft_agents}/hosting/core/connector/conversations_base.py +1 -1
- {microsoft/agents → microsoft_agents}/hosting/core/connector/teams/teams_connector_client.py +5 -5
- {microsoft/agents → microsoft_agents}/hosting/core/connector/user_token_base.py +1 -1
- {microsoft/agents → microsoft_agents}/hosting/core/message_factory.py +1 -1
- microsoft_agents/hosting/core/oauth/__init__.py +12 -0
- microsoft_agents/hosting/core/oauth/flow_state.py +81 -0
- microsoft_agents/hosting/core/oauth/flow_storage_client.py +93 -0
- microsoft_agents/hosting/core/oauth/oauth_flow.py +341 -0
- {microsoft/agents → microsoft_agents}/hosting/core/rest_channel_service_client_factory.py +5 -5
- {microsoft/agents → microsoft_agents}/hosting/core/state/agent_state.py +2 -2
- {microsoft/agents → microsoft_agents}/hosting/core/state/state_property_accessor.py +1 -1
- {microsoft/agents → microsoft_agents}/hosting/core/state/user_state.py +1 -1
- microsoft/agents/hosting/core/storage/storage_test_utils.py → microsoft_agents/hosting/core/storage/_storage_test_utils.py +2 -0
- {microsoft/agents → microsoft_agents}/hosting/core/turn_context.py +3 -3
- {microsoft_agents_hosting_core-0.3.0.dev0.dist-info → microsoft_agents_hosting_core-0.4.0.dev3.dist-info}/METADATA +2 -2
- microsoft_agents_hosting_core-0.4.0.dev3.dist-info/RECORD +83 -0
- microsoft_agents_hosting_core-0.4.0.dev3.dist-info/top_level.txt +1 -0
- microsoft/agents/hosting/core/app/oauth/__init__.py +0 -8
- microsoft/agents/hosting/core/app/oauth/authorization.py +0 -431
- microsoft/agents/hosting/core/oauth_flow.py +0 -397
- microsoft_agents_hosting_core-0.3.0.dev0.dist-info/RECORD +0 -79
- microsoft_agents_hosting_core-0.3.0.dev0.dist-info/top_level.txt +0 -1
- {microsoft/agents → microsoft_agents}/hosting/core/agent.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/app/app_error.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/app/query.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/app/state/__init__.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/authorization/__init__.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/authorization/access_token_provider_base.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/authorization/anonymous_token_provider.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/authorization/auth_types.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/authorization/authentication_constants.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/authorization/claims_identity.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/authorization/connections.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/authorization/jwt_token_validator.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/client/__init__.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/client/channel_host_protocol.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/client/channel_info_protocol.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/client/channels_configuration.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/client/conversation_constants.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/client/conversation_id_factory_protocol.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/connector/__init__.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/connector/client/__init__.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/connector/connector_client_base.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/connector/get_product_info.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/connector/teams/__init__.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/connector/user_token_client_base.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/middleware_set.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/state/__init__.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/storage/__init__.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/storage/_type_aliases.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/storage/error_handling.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/storage/memory_storage.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/storage/storage.py +0 -0
- {microsoft/agents → microsoft_agents}/hosting/core/storage/store_item.py +0 -0
- {microsoft_agents_hosting_core-0.3.0.dev0.dist-info → microsoft_agents_hosting_core-0.4.0.dev3.dist-info}/WHEEL +0 -0
|
@@ -1,397 +0,0 @@
|
|
|
1
|
-
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
# Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
from __future__ import annotations
|
|
5
|
-
|
|
6
|
-
from datetime import datetime
|
|
7
|
-
from typing import Dict, Optional
|
|
8
|
-
|
|
9
|
-
from microsoft.agents.hosting.core.connector.client import UserTokenClient
|
|
10
|
-
from microsoft.agents.activity import (
|
|
11
|
-
ActionTypes,
|
|
12
|
-
ActivityTypes,
|
|
13
|
-
CardAction,
|
|
14
|
-
Attachment,
|
|
15
|
-
OAuthCard,
|
|
16
|
-
TokenExchangeState,
|
|
17
|
-
TokenResponse,
|
|
18
|
-
Activity,
|
|
19
|
-
)
|
|
20
|
-
from microsoft.agents.activity import (
|
|
21
|
-
TurnContextProtocol as TurnContext,
|
|
22
|
-
)
|
|
23
|
-
from microsoft.agents.hosting.core.storage import StoreItem, Storage
|
|
24
|
-
from pydantic import BaseModel
|
|
25
|
-
|
|
26
|
-
from .message_factory import MessageFactory
|
|
27
|
-
from .card_factory import CardFactory
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class FlowState(StoreItem, BaseModel):
|
|
31
|
-
flow_started: bool = False
|
|
32
|
-
user_token: str = ""
|
|
33
|
-
flow_expires: float = 0
|
|
34
|
-
abs_oauth_connection_name: Optional[str] = None
|
|
35
|
-
continuation_activity: Optional[Activity] = None
|
|
36
|
-
|
|
37
|
-
def store_item_to_json(self) -> dict:
|
|
38
|
-
return self.model_dump()
|
|
39
|
-
|
|
40
|
-
@staticmethod
|
|
41
|
-
def from_json_to_store_item(json_data: dict) -> "StoreItem":
|
|
42
|
-
return FlowState.model_validate(json_data)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
class OAuthFlow:
|
|
46
|
-
"""
|
|
47
|
-
Manages the OAuth flow.
|
|
48
|
-
"""
|
|
49
|
-
|
|
50
|
-
def __init__(
|
|
51
|
-
self,
|
|
52
|
-
storage: Storage,
|
|
53
|
-
abs_oauth_connection_name: str,
|
|
54
|
-
user_token_client: Optional[UserTokenClient] = None,
|
|
55
|
-
messages_configuration: dict[str, str] = None,
|
|
56
|
-
**kwargs,
|
|
57
|
-
):
|
|
58
|
-
"""
|
|
59
|
-
Creates a new instance of OAuthFlow.
|
|
60
|
-
|
|
61
|
-
Args:
|
|
62
|
-
user_state: The user state.
|
|
63
|
-
abs_oauth_connection_name: The OAuth connection name.
|
|
64
|
-
user_token_client: Optional user token client.
|
|
65
|
-
messages_configuration: Optional messages configuration for backward compatibility.
|
|
66
|
-
"""
|
|
67
|
-
if not abs_oauth_connection_name:
|
|
68
|
-
raise ValueError(
|
|
69
|
-
"OAuthFlow.__init__: connectionName expected but not found"
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
# Handle backward compatibility with messages_configuration
|
|
73
|
-
self.messages_configuration = messages_configuration or {}
|
|
74
|
-
|
|
75
|
-
# Initialize properties
|
|
76
|
-
self.abs_oauth_connection_name = abs_oauth_connection_name
|
|
77
|
-
self.user_token_client = user_token_client
|
|
78
|
-
self.token_exchange_id: Optional[str] = None
|
|
79
|
-
|
|
80
|
-
# Initialize state and flow state
|
|
81
|
-
self._storage = storage
|
|
82
|
-
self.flow_state = None
|
|
83
|
-
|
|
84
|
-
async def get_user_token(self, context: TurnContext) -> TokenResponse:
|
|
85
|
-
"""
|
|
86
|
-
Retrieves the user token from the user token service.
|
|
87
|
-
|
|
88
|
-
Args:
|
|
89
|
-
context: The turn context containing the activity information.
|
|
90
|
-
|
|
91
|
-
Returns:
|
|
92
|
-
The user token response.
|
|
93
|
-
|
|
94
|
-
Raises:
|
|
95
|
-
ValueError: If the channelId or from properties are not set in the activity.
|
|
96
|
-
"""
|
|
97
|
-
await self._initialize_token_client(context)
|
|
98
|
-
|
|
99
|
-
if not context.activity.from_property:
|
|
100
|
-
raise ValueError("User ID is not set in the activity.")
|
|
101
|
-
|
|
102
|
-
if not context.activity.channel_id:
|
|
103
|
-
raise ValueError("Channel ID is not set in the activity.")
|
|
104
|
-
|
|
105
|
-
return await self.user_token_client.user_token.get_token(
|
|
106
|
-
user_id=context.activity.from_property.id,
|
|
107
|
-
connection_name=self.abs_oauth_connection_name,
|
|
108
|
-
channel_id=context.activity.channel_id,
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
async def begin_flow(self, context: TurnContext) -> TokenResponse:
|
|
112
|
-
"""
|
|
113
|
-
Begins the OAuth flow.
|
|
114
|
-
|
|
115
|
-
Args:
|
|
116
|
-
context: The turn context.
|
|
117
|
-
|
|
118
|
-
Returns:
|
|
119
|
-
A TokenResponse object.
|
|
120
|
-
"""
|
|
121
|
-
self.flow_state = FlowState()
|
|
122
|
-
|
|
123
|
-
if not self.abs_oauth_connection_name:
|
|
124
|
-
raise ValueError("connectionName is not set")
|
|
125
|
-
|
|
126
|
-
await self._initialize_token_client(context)
|
|
127
|
-
|
|
128
|
-
activity = context.activity
|
|
129
|
-
|
|
130
|
-
# Try to get existing token first
|
|
131
|
-
user_token = await self.user_token_client.user_token.get_token(
|
|
132
|
-
user_id=activity.from_property.id,
|
|
133
|
-
connection_name=self.abs_oauth_connection_name,
|
|
134
|
-
channel_id=activity.channel_id,
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
if user_token and user_token.token:
|
|
138
|
-
# Already have token, return it
|
|
139
|
-
self.flow_state.flow_started = False
|
|
140
|
-
self.flow_state.flow_expires = 0
|
|
141
|
-
self.flow_state.abs_oauth_connection_name = self.abs_oauth_connection_name
|
|
142
|
-
await self._save_flow_state(context)
|
|
143
|
-
return user_token
|
|
144
|
-
|
|
145
|
-
# No token, need to start sign-in flow
|
|
146
|
-
token_exchange_state = TokenExchangeState(
|
|
147
|
-
connection_name=self.abs_oauth_connection_name,
|
|
148
|
-
conversation=activity.get_conversation_reference(),
|
|
149
|
-
relates_to=activity.relates_to,
|
|
150
|
-
ms_app_id=context.turn_state.get(context.adapter.AGENT_IDENTITY_KEY).claims[
|
|
151
|
-
"aud"
|
|
152
|
-
],
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
sign_in_resource = (
|
|
156
|
-
await self.user_token_client.agent_sign_in.get_sign_in_resource(
|
|
157
|
-
state=token_exchange_state.get_encoded_state(),
|
|
158
|
-
)
|
|
159
|
-
)
|
|
160
|
-
|
|
161
|
-
# Create the OAuth card
|
|
162
|
-
o_card: Attachment = CardFactory.oauth_card(
|
|
163
|
-
OAuthCard(
|
|
164
|
-
text=self.messages_configuration.get("card_title", "Sign in"),
|
|
165
|
-
connection_name=self.abs_oauth_connection_name,
|
|
166
|
-
buttons=[
|
|
167
|
-
CardAction(
|
|
168
|
-
title=self.messages_configuration.get("button_text", "Sign in"),
|
|
169
|
-
type=ActionTypes.signin,
|
|
170
|
-
value=sign_in_resource.sign_in_link,
|
|
171
|
-
channel_data=None,
|
|
172
|
-
)
|
|
173
|
-
],
|
|
174
|
-
token_exchange_resource=sign_in_resource.token_exchange_resource,
|
|
175
|
-
token_post_resource=sign_in_resource.token_post_resource,
|
|
176
|
-
)
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
# Send the card to the user
|
|
180
|
-
await context.send_activity(MessageFactory.attachment(o_card))
|
|
181
|
-
|
|
182
|
-
# Update flow state
|
|
183
|
-
self.flow_state.flow_started = True
|
|
184
|
-
self.flow_state.flow_expires = datetime.now().timestamp() + 30000
|
|
185
|
-
self.flow_state.abs_oauth_connection_name = self.abs_oauth_connection_name
|
|
186
|
-
await self._save_flow_state(context)
|
|
187
|
-
|
|
188
|
-
# Return in-progress response
|
|
189
|
-
return TokenResponse()
|
|
190
|
-
|
|
191
|
-
async def continue_flow(self, context: TurnContext) -> TokenResponse:
|
|
192
|
-
"""
|
|
193
|
-
Continues the OAuth flow.
|
|
194
|
-
|
|
195
|
-
Args:
|
|
196
|
-
context: The turn context.
|
|
197
|
-
|
|
198
|
-
Returns:
|
|
199
|
-
A TokenResponse object.
|
|
200
|
-
"""
|
|
201
|
-
await self._initialize_token_client(context)
|
|
202
|
-
|
|
203
|
-
if (
|
|
204
|
-
self.flow_state
|
|
205
|
-
and self.flow_state.flow_expires != 0
|
|
206
|
-
and datetime.now().timestamp() > self.flow_state.flow_expires
|
|
207
|
-
):
|
|
208
|
-
await context.send_activity(
|
|
209
|
-
MessageFactory.text(
|
|
210
|
-
self.messages_configuration.get(
|
|
211
|
-
"session_expired_messages",
|
|
212
|
-
"Sign-in session expired. Please try again.",
|
|
213
|
-
)
|
|
214
|
-
)
|
|
215
|
-
)
|
|
216
|
-
return TokenResponse()
|
|
217
|
-
|
|
218
|
-
cont_flow_activity = context.activity
|
|
219
|
-
|
|
220
|
-
# Handle message type activities (typically when the user enters a code)
|
|
221
|
-
if cont_flow_activity.type == ActivityTypes.message:
|
|
222
|
-
magic_code = cont_flow_activity.text
|
|
223
|
-
|
|
224
|
-
# Validate magic code format (6 digits)
|
|
225
|
-
if magic_code and magic_code.isdigit() and len(magic_code) == 6:
|
|
226
|
-
result = await self.user_token_client.user_token.get_token(
|
|
227
|
-
user_id=cont_flow_activity.from_property.id,
|
|
228
|
-
connection_name=self.abs_oauth_connection_name,
|
|
229
|
-
channel_id=cont_flow_activity.channel_id,
|
|
230
|
-
code=magic_code,
|
|
231
|
-
)
|
|
232
|
-
|
|
233
|
-
if result and result.token:
|
|
234
|
-
self.flow_state.flow_started = False
|
|
235
|
-
self.flow_state.flow_expires = 0
|
|
236
|
-
self.flow_state.abs_oauth_connection_name = (
|
|
237
|
-
self.abs_oauth_connection_name
|
|
238
|
-
)
|
|
239
|
-
await self._save_flow_state(context)
|
|
240
|
-
return result
|
|
241
|
-
else:
|
|
242
|
-
await context.send_activity(
|
|
243
|
-
MessageFactory.text("Invalid code. Please try again.")
|
|
244
|
-
)
|
|
245
|
-
self.flow_state.flow_started = True
|
|
246
|
-
self.flow_state.flow_expires = datetime.now().timestamp() + 30000
|
|
247
|
-
await self._save_flow_state(context)
|
|
248
|
-
return TokenResponse()
|
|
249
|
-
else:
|
|
250
|
-
await context.send_activity(
|
|
251
|
-
MessageFactory.text(
|
|
252
|
-
"Invalid code format. Please enter a 6-digit code."
|
|
253
|
-
)
|
|
254
|
-
)
|
|
255
|
-
return TokenResponse()
|
|
256
|
-
|
|
257
|
-
# Handle verify state invoke activity
|
|
258
|
-
if (
|
|
259
|
-
cont_flow_activity.type == ActivityTypes.invoke
|
|
260
|
-
and cont_flow_activity.name == "signin/verifyState"
|
|
261
|
-
):
|
|
262
|
-
token_verify_state = cont_flow_activity.value
|
|
263
|
-
magic_code = token_verify_state.get("state")
|
|
264
|
-
|
|
265
|
-
result = await self.user_token_client.user_token.get_token(
|
|
266
|
-
user_id=cont_flow_activity.from_property.id,
|
|
267
|
-
connection_name=self.abs_oauth_connection_name,
|
|
268
|
-
channel_id=cont_flow_activity.channel_id,
|
|
269
|
-
code=magic_code,
|
|
270
|
-
)
|
|
271
|
-
|
|
272
|
-
if result and result.token:
|
|
273
|
-
self.flow_state.flow_started = False
|
|
274
|
-
self.flow_state.abs_oauth_connection_name = (
|
|
275
|
-
self.abs_oauth_connection_name
|
|
276
|
-
)
|
|
277
|
-
await self._save_flow_state(context)
|
|
278
|
-
return result
|
|
279
|
-
return TokenResponse()
|
|
280
|
-
|
|
281
|
-
# Handle token exchange invoke activity
|
|
282
|
-
if (
|
|
283
|
-
cont_flow_activity.type == ActivityTypes.invoke
|
|
284
|
-
and cont_flow_activity.name == "signin/tokenExchange"
|
|
285
|
-
):
|
|
286
|
-
token_exchange_request = cont_flow_activity.value
|
|
287
|
-
|
|
288
|
-
# Dedupe checks to prevent duplicate processing
|
|
289
|
-
token_exchange_id = token_exchange_request.get("id")
|
|
290
|
-
if self.token_exchange_id == token_exchange_id:
|
|
291
|
-
# Already processed this request
|
|
292
|
-
return TokenResponse()
|
|
293
|
-
|
|
294
|
-
# Store this request ID
|
|
295
|
-
self.token_exchange_id = token_exchange_id
|
|
296
|
-
|
|
297
|
-
# Exchange the token
|
|
298
|
-
user_token_resp = await self.user_token_client.user_token.exchange_token(
|
|
299
|
-
user_id=cont_flow_activity.from_property.id,
|
|
300
|
-
connection_name=self.abs_oauth_connection_name,
|
|
301
|
-
channel_id=cont_flow_activity.channel_id,
|
|
302
|
-
body=token_exchange_request,
|
|
303
|
-
)
|
|
304
|
-
|
|
305
|
-
if user_token_resp and user_token_resp.token:
|
|
306
|
-
self.flow_state.flow_started = False
|
|
307
|
-
await self._save_flow_state(context)
|
|
308
|
-
return user_token_resp
|
|
309
|
-
else:
|
|
310
|
-
self.flow_state.flow_started = True
|
|
311
|
-
return TokenResponse()
|
|
312
|
-
|
|
313
|
-
return TokenResponse()
|
|
314
|
-
|
|
315
|
-
async def sign_out(self, context: TurnContext) -> None:
|
|
316
|
-
"""
|
|
317
|
-
Signs the user out.
|
|
318
|
-
|
|
319
|
-
Args:
|
|
320
|
-
context: The turn context.
|
|
321
|
-
"""
|
|
322
|
-
await self._initialize_token_client(context)
|
|
323
|
-
|
|
324
|
-
await self.user_token_client.user_token.sign_out(
|
|
325
|
-
user_id=context.activity.from_property.id,
|
|
326
|
-
connection_name=self.abs_oauth_connection_name,
|
|
327
|
-
channel_id=context.activity.channel_id,
|
|
328
|
-
)
|
|
329
|
-
|
|
330
|
-
if self.flow_state:
|
|
331
|
-
self.flow_state.flow_expires = 0
|
|
332
|
-
await self._save_flow_state(context)
|
|
333
|
-
|
|
334
|
-
async def _get_flow_state(self, context: TurnContext) -> FlowState:
|
|
335
|
-
"""
|
|
336
|
-
Gets the user state.
|
|
337
|
-
|
|
338
|
-
Args:
|
|
339
|
-
context: The turn context.
|
|
340
|
-
|
|
341
|
-
Returns:
|
|
342
|
-
The user state.
|
|
343
|
-
"""
|
|
344
|
-
storage_key = self._get_storage_key(context)
|
|
345
|
-
|
|
346
|
-
storage_result: Dict[str, FlowState] | None = await self._storage.read(
|
|
347
|
-
[storage_key], target_cls=FlowState
|
|
348
|
-
)
|
|
349
|
-
if not storage_result or storage_key not in storage_result:
|
|
350
|
-
return FlowState()
|
|
351
|
-
return storage_result[storage_key]
|
|
352
|
-
|
|
353
|
-
async def _save_flow_state(self, context: TurnContext) -> None:
|
|
354
|
-
"""
|
|
355
|
-
Saves the flow state to the user state.
|
|
356
|
-
Args:
|
|
357
|
-
context: The turn context.
|
|
358
|
-
"""
|
|
359
|
-
await self._storage.write({self._get_storage_key(context): self.flow_state})
|
|
360
|
-
|
|
361
|
-
async def _initialize_token_client(self, context: TurnContext) -> None:
|
|
362
|
-
"""
|
|
363
|
-
Initializes the user token client if not already set.
|
|
364
|
-
|
|
365
|
-
Args:
|
|
366
|
-
context: The turn context.
|
|
367
|
-
"""
|
|
368
|
-
|
|
369
|
-
# TODO: Change this to caching when the story is implemented, for now we're getting it from TurnContext (new with every request)
|
|
370
|
-
self.user_token_client = context.turn_state.get(
|
|
371
|
-
context.adapter.USER_TOKEN_CLIENT_KEY
|
|
372
|
-
)
|
|
373
|
-
|
|
374
|
-
def _get_storage_key(self, context: TurnContext) -> str:
|
|
375
|
-
"""
|
|
376
|
-
Gets the storage key for the flow state.
|
|
377
|
-
|
|
378
|
-
Args:
|
|
379
|
-
context: The turn context.
|
|
380
|
-
|
|
381
|
-
Returns:
|
|
382
|
-
The storage key.
|
|
383
|
-
"""
|
|
384
|
-
channel_id = context.activity.channel_id
|
|
385
|
-
if not channel_id:
|
|
386
|
-
raise ValueError("Channel ID is not set in the activity.")
|
|
387
|
-
user_id = (
|
|
388
|
-
context.activity.from_property.id
|
|
389
|
-
if context.activity.from_property
|
|
390
|
-
else None
|
|
391
|
-
)
|
|
392
|
-
if not user_id:
|
|
393
|
-
raise ValueError("User ID is not set in the activity.")
|
|
394
|
-
|
|
395
|
-
return (
|
|
396
|
-
f"oauth/{self.abs_oauth_connection_name}/{channel_id}/{user_id}/flowState"
|
|
397
|
-
)
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
microsoft/agents/hosting/core/__init__.py,sha256=VxZ0E6RzP1n1oM6t1osTPOJ3DrxZT0xdrcuVdTTpbIM,4976
|
|
2
|
-
microsoft/agents/hosting/core/activity_handler.py,sha256=ighDOQW6YoXnCqDP-5tCbZknkzjhltem64TRC6goWQE,26592
|
|
3
|
-
microsoft/agents/hosting/core/agent.py,sha256=K8v84y8ULP7rbcMKg8LxaM3haAq7f1oHFCLy3AAphQE,574
|
|
4
|
-
microsoft/agents/hosting/core/card_factory.py,sha256=fZWb__zOIyKs46bwpbfHyLVTC9mLBJS1SbikuKESyU0,6926
|
|
5
|
-
microsoft/agents/hosting/core/channel_adapter.py,sha256=rqFz71DykiFV_756EGF1gj6P5DJsSu0QSb-onJwOHo4,10063
|
|
6
|
-
microsoft/agents/hosting/core/channel_api_handler_protocol.py,sha256=LXBWJh1T-ESX6JyMFwAMrLy8WfIv2oH8zA5ZsUgBaNg,4411
|
|
7
|
-
microsoft/agents/hosting/core/channel_service_adapter.py,sha256=9AR658i7XP_IuFfEXjujpFUFL2Be-ibPVvUGHd_UuPc,17373
|
|
8
|
-
microsoft/agents/hosting/core/channel_service_client_factory_base.py,sha256=bVz6_qQyMLUjFmFOeuNUVynlJoIaACfE0Wvj9puvavI,1465
|
|
9
|
-
microsoft/agents/hosting/core/message_factory.py,sha256=yras68M7OdR10_6Jm_2gaZ6Cq3uyUwojZOBMg5kR-GY,7822
|
|
10
|
-
microsoft/agents/hosting/core/middleware_set.py,sha256=TBsBs4KwAfKyHlQTlG4bl1y5UjkBzeMDs5w7LNB-Bi4,2585
|
|
11
|
-
microsoft/agents/hosting/core/oauth_flow.py,sha256=DXx-V0bACxP6XY4s5ysAN6Xga0CrskI1WzL1VRFEVws,13760
|
|
12
|
-
microsoft/agents/hosting/core/rest_channel_service_client_factory.py,sha256=r4kybbqIXpWywTJ0lmaO2U1VNpJStAM1oyOuuw9ZU6Q,2854
|
|
13
|
-
microsoft/agents/hosting/core/turn_context.py,sha256=Hhd75-BFwiWQxXtFRrlKGBoVbPAzRvgRjG1FYr0Iyis,14415
|
|
14
|
-
microsoft/agents/hosting/core/app/__init__.py,sha256=Gmu4Upo8gRBzjbWchsg0qDSnVNROUXNgIAhPVvtslEQ,1303
|
|
15
|
-
microsoft/agents/hosting/core/app/agent_application.py,sha256=xZLcaqKGpTRDM924fsQkbcPAMPuzCKHHgohh881BSOY,28800
|
|
16
|
-
microsoft/agents/hosting/core/app/app_error.py,sha256=JgYBgv2EKe9Q2TFi5FeG_RneulBEa5SyBpWSF-duBzE,301
|
|
17
|
-
microsoft/agents/hosting/core/app/app_options.py,sha256=AhdOEQnGm0VYOx-HrEcX6QkEzpSbyn3OIrwxN2UMMzM,2815
|
|
18
|
-
microsoft/agents/hosting/core/app/input_file.py,sha256=4iKXWaKbE8RqO3dy74EVmsI7rcffAi4pt87tz81BYg4,1151
|
|
19
|
-
microsoft/agents/hosting/core/app/query.py,sha256=lToDWFG7exUyPC5zxvna89013fDPKrUGOI8jyWFoUYk,328
|
|
20
|
-
microsoft/agents/hosting/core/app/route.py,sha256=ZSyVVJ4qwY37_XFD6XfWFnoGoS28kukk09OHJ1PFoG4,871
|
|
21
|
-
microsoft/agents/hosting/core/app/typing_indicator.py,sha256=t4ergQjB9MNexqc7c3Tra9pvmcvpEkq7c9og5GWWNJI,1558
|
|
22
|
-
microsoft/agents/hosting/core/app/oauth/__init__.py,sha256=xNbUpO0O48RUhT59kZcQlYJSYIwCVwb3xI6uI0FKNwY,195
|
|
23
|
-
microsoft/agents/hosting/core/app/oauth/authorization.py,sha256=l17Ffzdn2vo8Jvt6wuq_1vx_XCw8S-TqTIvldoiHwbc,15617
|
|
24
|
-
microsoft/agents/hosting/core/app/state/__init__.py,sha256=aL_8GB7_de8LUSEOgTJQFRx1kvgvJHHJVv7nWAoRPmU,331
|
|
25
|
-
microsoft/agents/hosting/core/app/state/conversation_state.py,sha256=sSk3UUUr5wcM-buRr53k7kPWl-c8mELtsBZqTFQO4mE,1514
|
|
26
|
-
microsoft/agents/hosting/core/app/state/state.py,sha256=yarInT3dzCkqpLzNuIHPbxlv-T0cdNJHhW8BKBDflCc,5353
|
|
27
|
-
microsoft/agents/hosting/core/app/state/temp_state.py,sha256=E0g8xolZC3THEiTH9rEzjRRnDmNCZd1XvI8gvVRKToE,3362
|
|
28
|
-
microsoft/agents/hosting/core/app/state/turn_state.py,sha256=iWwyZ-_ju7k_zR_die1xfzDP95x5hTMVG-6SjQ64pvo,9640
|
|
29
|
-
microsoft/agents/hosting/core/authorization/__init__.py,sha256=pOTmTJFS5CMPEcHRadBTgrbWUP5lOIxsPMgTreFq7mw,634
|
|
30
|
-
microsoft/agents/hosting/core/authorization/access_token_provider_base.py,sha256=f3GiPKYAVEWQ8ZDmedjL8o4QrGeQWRJ4Y2bbb-tOwRQ,1066
|
|
31
|
-
microsoft/agents/hosting/core/authorization/agent_auth_configuration.py,sha256=vGrxvDaq5YUCe01LS5G3sogf78UJWFv4pw94DWiFiIA,1914
|
|
32
|
-
microsoft/agents/hosting/core/authorization/anonymous_token_provider.py,sha256=wgVYhRYhqEeOPDEYG88Zmbj6iNtQrUEog5Ut7mZzj90,400
|
|
33
|
-
microsoft/agents/hosting/core/authorization/auth_types.py,sha256=N2YkXc_9G3e1kVuv74pdxhMzXzPvtLwqujcpv5xCxsU,279
|
|
34
|
-
microsoft/agents/hosting/core/authorization/authentication_constants.py,sha256=VH8XsG0p9KtAQtAu9FtuqGUi2pRaRusZQhYhAPLqZfk,4126
|
|
35
|
-
microsoft/agents/hosting/core/authorization/claims_identity.py,sha256=GkSDYjnR0fOAGMtIB97NFFg3CXpEM4sjGyS8DmgJebs,2491
|
|
36
|
-
microsoft/agents/hosting/core/authorization/connections.py,sha256=kG_iSP0Z9-tE_bTL-MxojY8oN5bRMVJzMdMxDNzKtiE,1152
|
|
37
|
-
microsoft/agents/hosting/core/authorization/jwt_token_validator.py,sha256=7Oerq5hBZMQ3M2Gs_-0pfcFns55GL5biiKTHY8DuCtg,1872
|
|
38
|
-
microsoft/agents/hosting/core/client/__init__.py,sha256=HMWtSUXu1akaX6qtDx412Lr8vLi5SEslc-DYrvZAPWs,1299
|
|
39
|
-
microsoft/agents/hosting/core/client/agent_conversation_reference.py,sha256=OwI_6E0yb01GwLAzMJUj3hsfDvuHvSQ5cPU_VbI8WcM,193
|
|
40
|
-
microsoft/agents/hosting/core/client/channel_factory_protocol.py,sha256=mn5Bg27lgYmNqwvJUW6-1jTA5vogmASaZ8SfIdMpHn8,299
|
|
41
|
-
microsoft/agents/hosting/core/client/channel_host_protocol.py,sha256=2HSBNudC7TgqicaIMJFE0QBz3F1cFtGVzA0k6FOMdaU,681
|
|
42
|
-
microsoft/agents/hosting/core/client/channel_info_protocol.py,sha256=blCKoD2OHj4Hy8XxXuHMEbOdh7lu30ESatKu7wUlUAk,184
|
|
43
|
-
microsoft/agents/hosting/core/client/channel_protocol.py,sha256=JhoCo5Qfy5vs1G34oyoTAXMNAKAFn138N1GKNZ1IfC4,492
|
|
44
|
-
microsoft/agents/hosting/core/client/channels_configuration.py,sha256=Es3qq8wb31cuITwAbKI0cN1nK-vwy8W_mpqcj4tRRgk,989
|
|
45
|
-
microsoft/agents/hosting/core/client/configuration_channel_host.py,sha256=-CQxX272Gqyth3yGW4jLBggWmsU9oe1-msdnA74-SAY,2415
|
|
46
|
-
microsoft/agents/hosting/core/client/conversation_constants.py,sha256=HVTgiaApSp3OkntL89JETq_QcMMHsquwrp4fqDmK3zQ,118
|
|
47
|
-
microsoft/agents/hosting/core/client/conversation_id_factory.py,sha256=MUJ_3IDXWnJpJRbFRq7inpGu17Fla4F9ohsOuZX3dK4,2497
|
|
48
|
-
microsoft/agents/hosting/core/client/conversation_id_factory_options.py,sha256=P5Xwbnw0cwXb8Coq5bprkcTtkuX_WJQBE0hR08EjEb8,538
|
|
49
|
-
microsoft/agents/hosting/core/client/conversation_id_factory_protocol.py,sha256=ZvWuZ8DUGyFYR3VL-rpP02rP2jL50YyX6cswC-_S07g,1228
|
|
50
|
-
microsoft/agents/hosting/core/client/http_agent_channel.py,sha256=rzypoNp_va9mGk55WDfU-BQf1zgZM8FW1xZOEWPeZI4,3539
|
|
51
|
-
microsoft/agents/hosting/core/client/http_agent_channel_factory.py,sha256=BPA-mNi9QFUGXeoWr0nkAm6otd2nFoUT_FZOesnNlpo,428
|
|
52
|
-
microsoft/agents/hosting/core/connector/__init__.py,sha256=Dkc1GAviMYXw5BFvP6xgVhrb1UJUuLiHbfEkjminnOc,522
|
|
53
|
-
microsoft/agents/hosting/core/connector/agent_sign_in_base.py,sha256=PcJeCreCUyOiZctMqaO1ZwTq8669XS_GPjb1qav12M4,647
|
|
54
|
-
microsoft/agents/hosting/core/connector/attachments_base.py,sha256=nNFci1zZf_6gY7v7achM-UFDCzkabTQYfwlu8dzHZ9Q,507
|
|
55
|
-
microsoft/agents/hosting/core/connector/connector_client_base.py,sha256=DKog6C1Z8V9r_Lp-IvXUiAbJN_iJMFary5FvejjHlaw,583
|
|
56
|
-
microsoft/agents/hosting/core/connector/conversations_base.py,sha256=5rnqI9sKOc4mJUXFASC67cKaSI2oLs-YUpFvhBDfydQ,3754
|
|
57
|
-
microsoft/agents/hosting/core/connector/get_product_info.py,sha256=SDxPqBCzzQLEUsaZ4S9lB95ibo9LMGd1-K5Uf7vcAwo,962
|
|
58
|
-
microsoft/agents/hosting/core/connector/user_token_base.py,sha256=kFO2_YQhw-IqVN9zhK_2ezhHh_DkVZYfSbGFp5pSgK8,1195
|
|
59
|
-
microsoft/agents/hosting/core/connector/user_token_client_base.py,sha256=JTkbG70YXEnAQA_2yJn9dUGQ-hSCwNgU0C-V8y7kGEI,376
|
|
60
|
-
microsoft/agents/hosting/core/connector/client/__init__.py,sha256=6JdKhmm7btmo0omxMBd8PJbtGFk0cnMwVUoStyW7Ft0,143
|
|
61
|
-
microsoft/agents/hosting/core/connector/client/connector_client.py,sha256=H3RHAS7-p4HB1yOCeukRvaJQ-wLZ3fdKB2CxqIAj7fE,22337
|
|
62
|
-
microsoft/agents/hosting/core/connector/client/user_token_client.py,sha256=ULZe2AN5D4nNSnNj5k-aDdI8l63IjyV3D8S87pdkLYQ,10896
|
|
63
|
-
microsoft/agents/hosting/core/connector/teams/__init__.py,sha256=3ZMPGYyZ15EwvfQzfJJQy1J58oIt4InSxibl3BN6R54,100
|
|
64
|
-
microsoft/agents/hosting/core/connector/teams/teams_connector_client.py,sha256=N1132_KCah-fCS-seDlHobmyn1y01GdSeWmYkAIPDV4,12676
|
|
65
|
-
microsoft/agents/hosting/core/state/__init__.py,sha256=yckKi1wg_86ng-DL9Q3R49QiWKvNjPkVNk6HClWgVrY,208
|
|
66
|
-
microsoft/agents/hosting/core/state/agent_state.py,sha256=1ltzbTE-_XEBOrAbqJOVbu7UYAT9aS41uJQmsqNeLJw,12879
|
|
67
|
-
microsoft/agents/hosting/core/state/state_property_accessor.py,sha256=mTbg1-2MjdDUSM55nWiPCUn6eaSPuLBazSoSFbdrzEQ,1392
|
|
68
|
-
microsoft/agents/hosting/core/state/user_state.py,sha256=KAmypGk_nvyixFO-w9SQsgGPqPVKeZYrCcXQ0koQfjg,1484
|
|
69
|
-
microsoft/agents/hosting/core/storage/__init__.py,sha256=wq8zlkoPG6I8PfMvdGPN-tNCdP905W7jylFrmJ-GF6o,196
|
|
70
|
-
microsoft/agents/hosting/core/storage/_type_aliases.py,sha256=VCKtjiCBrhEsGSm3zVVSSccdoiY02GYhABvrLjhAcz8,72
|
|
71
|
-
microsoft/agents/hosting/core/storage/error_handling.py,sha256=zH34d7s4pJG_uajpBWhrtTpH2eMy88kSKaqvOqtbgzY,1265
|
|
72
|
-
microsoft/agents/hosting/core/storage/memory_storage.py,sha256=NADem1wQE1MOG1qMriYw4NjILHEBDbIG5HT6wvHfG2M,2353
|
|
73
|
-
microsoft/agents/hosting/core/storage/storage.py,sha256=vft_Kw4pkzo8NnBEyDx7gAn1Ndg2I9ePaxnuxbKVHzs,3227
|
|
74
|
-
microsoft/agents/hosting/core/storage/storage_test_utils.py,sha256=ALTEz04PZfpqCYaZa4ibbP-iXOfJLJVPaBQGR0lWpFY,18253
|
|
75
|
-
microsoft/agents/hosting/core/storage/store_item.py,sha256=4LSkuI0H0lgWig88YoHFn6BP8Bx44YbyuvqBvaBNdEM,276
|
|
76
|
-
microsoft_agents_hosting_core-0.3.0.dev0.dist-info/METADATA,sha256=gFqUUHt76yyEvj-1LkrFaYrklPw1fV7NZfXCFCnaDqE,584
|
|
77
|
-
microsoft_agents_hosting_core-0.3.0.dev0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
78
|
-
microsoft_agents_hosting_core-0.3.0.dev0.dist-info/top_level.txt,sha256=egwWDmpnNBTGerc55Oa6VVW9hTKdtxFjHWHywqmVMpM,10
|
|
79
|
-
microsoft_agents_hosting_core-0.3.0.dev0.dist-info/RECORD,,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
microsoft
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{microsoft/agents → microsoft_agents}/hosting/core/authorization/access_token_provider_base.py
RENAMED
|
File without changes
|
{microsoft/agents → microsoft_agents}/hosting/core/authorization/anonymous_token_provider.py
RENAMED
|
File without changes
|
|
File without changes
|
{microsoft/agents → microsoft_agents}/hosting/core/authorization/authentication_constants.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{microsoft/agents → microsoft_agents}/hosting/core/client/conversation_id_factory_protocol.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|