|
3 | 3 |
|
4 | 4 | from datetime import datetime, timedelta |
5 | 5 | from urllib.parse import urlparse |
6 | | -from msrest.authentication import BasicTokenAuthentication, Authentication |
7 | 6 | import requests |
| 7 | + |
| 8 | +from msrest.authentication import Authentication |
8 | 9 | from .constants import Constants |
9 | 10 |
|
10 | 11 | # TODO: Decide to move this to Constants or viceversa (when porting OAuth) |
@@ -82,20 +83,25 @@ def __init__(self, app_id: str, password: str, channel_auth_tenant: str = None): |
82 | 83 | self.oauth_scope = AUTH_SETTINGS["refreshScope"] |
83 | 84 | self.token_cache_key = app_id + "-cache" |
84 | 85 |
|
85 | | - def signed_session(self) -> requests.Session: # pylint: disable=arguments-differ |
| 86 | + # pylint: disable=arguments-differ |
| 87 | + def signed_session(self, session: requests.Session = None) -> requests.Session: |
86 | 88 | """ |
87 | 89 | Gets the signed session. |
88 | 90 | :returns: Signed requests.Session object |
89 | 91 | """ |
90 | | - auth_token = self.get_access_token() |
91 | | - |
92 | | - basic_authentication = BasicTokenAuthentication({"access_token": auth_token}) |
93 | | - session = basic_authentication.signed_session() |
| 92 | + if not session: |
| 93 | + session = requests.Session() |
94 | 94 |
|
95 | 95 | # If there is no microsoft_app_id and no self.microsoft_app_password, then there shouldn't |
96 | 96 | # be an "Authorization" header on the outgoing activity. |
97 | 97 | if not self.microsoft_app_id and not self.microsoft_app_password: |
98 | | - del session.headers["Authorization"] |
| 98 | + session.headers.pop("Authorization", None) |
| 99 | + |
| 100 | + elif not session.headers.get("Authorization"): |
| 101 | + auth_token = self.get_access_token() |
| 102 | + header = "{} {}".format("Bearer", auth_token) |
| 103 | + session.headers["Authorization"] = header |
| 104 | + |
99 | 105 | return session |
100 | 106 |
|
101 | 107 | def get_access_token(self, force_refresh: bool = False) -> str: |
|
0 commit comments