|
26 | 26 | StoreItem,
|
27 | 27 | TurnContext,
|
28 | 28 | )
|
| 29 | +from botframework.connector.auth.user_token_client import UserTokenClient |
29 | 30 |
|
30 | 31 |
|
31 | 32 | class _TokenStoreItem(StoreItem):
|
@@ -147,17 +148,29 @@ async def _exchanged_token(self, turn_context: TurnContext) -> bool:
|
147 | 148 | token_exchange_response: TokenResponse = None
|
148 | 149 | aux_dict = {}
|
149 | 150 | if turn_context.activity.value:
|
150 |
| - for prop in ["id", "connection_name", "token", "properties"]: |
| 151 | + for prop in ["id", "connectionName", "token", "properties"]: |
151 | 152 | aux_dict[prop] = turn_context.activity.value.get(prop)
|
152 | 153 | token_exchange_request = TokenExchangeInvokeRequest(
|
153 | 154 | id=aux_dict["id"],
|
154 |
| - connection_name=aux_dict["connection_name"], |
| 155 | + connection_name=aux_dict["connectionName"], |
155 | 156 | token=aux_dict["token"],
|
156 | 157 | properties=aux_dict["properties"],
|
157 | 158 | )
|
158 | 159 | try:
|
159 | 160 | adapter = turn_context.adapter
|
160 |
| - if isinstance(turn_context.adapter, ExtendedUserTokenProvider): |
| 161 | + |
| 162 | + user_token_client: UserTokenClient = turn_context.turn_state.get( |
| 163 | + UserTokenClient.__name__, None |
| 164 | + ) |
| 165 | + if user_token_client: |
| 166 | + # If the adapter has UserTokenClient, use it to exchange the token. |
| 167 | + token_exchange_response = await user_token_client.exchange_token( |
| 168 | + turn_context.activity.from_property.id, |
| 169 | + token_exchange_request.connection_name, |
| 170 | + turn_context.activity.channel_id, |
| 171 | + TokenExchangeRequest(token=token_exchange_request.token), |
| 172 | + ) |
| 173 | + elif isinstance(turn_context.adapter, ExtendedUserTokenProvider): |
161 | 174 | token_exchange_response = await adapter.exchange_token(
|
162 | 175 | turn_context,
|
163 | 176 | self._oauth_connection_name,
|
|
0 commit comments