8000 Axsuarez/cherrypick 4.5 (#270) · sherlock666/botbuilder-python@a25be28 · GitHub
[go: up one dir, main page]

Skip to content

Commit a25be28

Browse files
authored
Axsuarez/cherrypick 4.5 (microsoft#270)
* Changes for token validation fix * breaking lines due to pylint
1 parent de81087 commit a25be28

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

libraries/botbuilder-core/botbuilder/core/bot_framework_adapter.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import asyncio
55
import base64
6+
import json
67
from typing import List, Callable, Awaitable, Union, Dict
78
from msrest.serialization import Model
89
from botbuilder.schema import (
@@ -90,7 +91,9 @@ def __init__(self, settings: BotFrameworkAdapterSettings):
9091
)
9192
self._is_emulating_oauth_cards = False
9293

93-
async def continue_conversation(self, bot_id: str, reference: ConversationReference, callback: Callable):
94+
async def continue_conversation(
95+
self, bot_id: str, reference: ConversationReference, callback: Callable
96+
):
9497
"""
9598
Continues a conversation with a user. This is often referred to as the bots "Proactive Messaging"
9699
flow as its lets the bot proactively send messages to a conversation or user that its already
@@ -290,8 +293,7 @@ async def delete_activity(
290293
try:
291294
client = self.create_connector_client(reference.service_url)
292295
await client.conversations.delete_activity(
293-
reference.conversation.id,
294-
reference.activity_id,
296+
reference.conversation.id, reference.activity_id
295297
)
296298
except Exception as error:
297299
raise error
@@ -488,15 +490,13 @@ async def get_oauth_sign_in_link(
488490
state = TokenExchangeState(
489491
connection_name=connection_name,
490492
conversation=conversation,
491-
ms_app_id=client.config.credentials.app_id,
493+
ms_app_id=client.config.credentials.microsoft_app_id,
492494
)
493495

494-
# TODO check proper encoding error handling
495496
final_state = base64.b64encode(
496-
state.serialize().encode(encoding="UTF-8", errors="strict")
497+
json.dumps(state.serialize()).encode(encoding="UTF-8", errors="strict")
497498
).decode()
498499

499-
# TODO check form of response
500500
return client.bot_sign_in.get_sign_in_url(final_state)
501501

502502
async def get_token_status(

libraries/botbuilder-core/botbuilder/core/bot_telemetry_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ def track_metric(
9393
:param value: The value of the metric that was captured.
9494
:param tel_type: The type of the metric. (defaults to: TelemetryDataPointType.aggregation`)
9595
:param count: the number of metrics that were aggregated into this data point. (defaults to: None)
96-
:param min_val: the minimum of all metrics collected that were aggregated into this data point. (defaults to: None)
97-
:param max_val: the maximum of all metrics collected that were aggregated into this data point. (defaults to: None)
96+
:param min_val: the minimum of all metrics collected that were aggregated into this data point.
97+
(defaults to: None)
98+
:param max_val: the maximum of all metrics collected that were aggregated into this data point.
99+
(defaults to: None)
98100
:param std_dev: the standard deviation of all metrics collected that were aggregated into this data point. \
99101
:param properties: the set of custom properties the client wants attached to this data item. (defaults to: None)
100102
"""

libraries/botbuilder-core/botbuilder/core/null_telemetry_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ def track_metric(
8080
:param value: The value of the metric that was captured.
8181
:param tel_type: The type of the metric. (defaults to: TelemetryDataPointType.aggregation`)
8282
:param count: the number of metrics that were aggregated into this data point. (defaults to: None
83-
:param min_val: the minimum of all metrics collected that were aggregated into this data point. (defaults to: None)
84-
:param max_val: the maximum of all metrics collected that were aggregated into this data point. (defaults to: None)
83+
:param min_val: the minimum of all metrics collected that were aggregated into this data point.
84+
(defaults to: None)
85+
:param max_val: the maximum of all metrics collected that were aggregated into this data point.
86+
(defaults to: None)
8587
:param std_dev: the standard deviation of all metrics collected that were aggregated into this data point. \
8688
(defaults to: None)
8789
:param properties: the set of custom properties the client wants attached to this data item. (defaults to: None)

libraries/botframework-connector/botframework/connector/auth/channel_validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ async def authenticate_channel_token(
8080
"""
8181
metadata_endpoint = (
8282
ChannelValidation.open_id_metadata_endpoint
83-
if ChannelValidation
84-
else Constants.TO_BOT_FROM_EMULATOR_OPEN_ID_METADATA_URL
83+
if ChannelValidation.open_id_metadata_endpoint
84+
else Constants.TO_BOT_FROM_CHANNEL_OPEN_ID_METADATA_URL
8585
)
8686

8787
token_extractor = JwtTokenExtractor(

libraries/botframework-connector/botframework/connector/auth/jwt_token_extractor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ async def get_identity(
5353

5454
try:
5555
return await self._validate_token(parameter, channel_id)
56-
except:
57-
raise
56+
except Exception as error:
57+
raise error
5858

5959
def _has_allowed_issuer(self, jwt_token: str) -> bool:
6060
decoded = jwt.decode(jwt_token, verify=False)

libraries/botframework-connector/botframework/connector/auth/jwt_token_validation.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,15 @@ async def validate_auth_header(
7070
auth_header, credentials, channel_service, channel_id
7171
)
7272

73-
if not channel_service:
74-
if service_url.strip():
75-
return
73+
# Right now public Azure is the only supported scenario (Gov and Enterprise pending)
74+
if service_url:
75+
return await ChannelValidation.authenticate_channel_token_with_service_url(
76+
auth_header, credentials, service_url, channel_id
77+
)
7678

77-
else:
78-
if service_url:
79-
return await ChannelValidation.authenticate_channel_token_with_service_url(
80-
auth_header, credentials, service_url, channel_id
81-
)
82-
else:
83-
return await ChannelValidation.authenticate_channel_token(
84-
auth_header, credentials, channel_id
85-
)
79+
return await ChannelValidation.authenticate_channel_token(
80+
auth_header, credentials, channel_id
81+
)
8682

8783
@staticmethod
8884
def is_government(channel_service: str) -> bool:

libraries/botframework-connector/botframework/connector/token_api/operations/_bot_sign_in_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def get_sign_in_url(
105105

106106
deserialized = None
107107
if response.status_code == 200:
108-
deserialized = self._deserialize("str", response)
108+
deserialized = response.content.decode("utf-8")
109109

110110
if raw:
111111
client_raw_response = ClientRawResponse(deserialized, response)

0 commit comments

Comments
 (0)
0