def _create_auth(self, username=None, password=None): """ Create an ~uamqp.authentication.cbs_auth_async.SASTokenAuthAsync instance to authenticate the session. :param username: The name of the shared access policy. :type username: str :param password: The shared access key. :type password: str """ if self.sas_token: token = self.sas_token() if callable(self.sas_token) else self.sas_token try: expiry = int(parse_sas_token(token)['se']) except (KeyError, TypeError, IndexError): raise ValueError("Supplied SAS token has no valid expiry value.") return authentication.SASTokenAsync( self.auth_uri, self.auth_uri, token, expires_at=expiry, timeout=self.auth_timeout, http_proxy=self.http_proxy) username = username or self._auth_config['username'] password = password or self._auth_config['password'] if "@sas.root" in username: return authentication.SASLPlain( self.address.hostname, username, password, http_proxy=self.http_proxy) return authentication.SASTokenAsync.from_shared_access_key( self.auth_uri, username, password, timeout=self.auth_timeout, http_proxy=self.http_proxy)
async def test_event_hubs_custom_end_point(): sas_token = authentication.SASTokenAsync( "fake_audience", "fake_uri", "fake_token", expires_in=timedelta(10), custom_endpoint_hostname="123.45.67.89") assert sas_token.hostname == b"123.45.67.89" sas_token = authentication.SASTokenAsync.from_shared_access_key( "fake_uri", "fake_key_name", "fake_key", custom_endpoint_hostname="123.45.67.89") assert sas_token.hostname == b"123.45.67.89" async def fake_get_token(): return "fake get token" jwt_token = authentication.JWTTokenAsync( "fake_audience", "fake_uri", fake_get_token, custom_endpoint_hostname="123.45.67.89") assert jwt_token.hostname == b"123.45.67.89"
def _create_auth(self, username=None, password=None): """ Create an ~uamqp.authentication.cbs_auth_async.SASTokenAuthAsync instance to authenticate the session. :param username: The name of the shared access policy. :type username: str :param password: The shared access key. :type password: str """ http_proxy = self.config.http_proxy transport_type = self.config.transport_type auth_timeout = self.config.auth_timeout if isinstance(self.credential, EventHubSharedKeyCredential): username = username or self._auth_config['username'] password = password or self._auth_config['password'] if "@sas.root" in username: return authentication.SASLPlain(self.host, username, password, http_proxy=http_proxy, transport_type=transport_type) return authentication.SASTokenAsync.from_shared_access_key( self.auth_uri, username, password, timeout=auth_timeout, http_proxy=http_proxy, transport_type=transport_type) elif isinstance(self.credential, EventHubSASTokenCredential): token = self.credential.get_sas_token() try: expiry = int(parse_sas_token(token)['se']) except (KeyError, TypeError, IndexError): raise ValueError( "Supplied SAS token has no valid expiry value.") return authentication.SASTokenAsync(self.auth_uri, self.auth_uri, token, expires_at=expiry, timeout=auth_timeout, http_proxy=http_proxy, transport_type=transport_type) else: get_jwt_token = functools.partial( self.credential.get_token, 'https://eventhubs.azure.net//.default') return authentication.JWTTokenAsync(self.auth_uri, self.auth_uri, get_jwt_token, http_proxy=http_proxy, transport_type=transport_type)
def _create_auth(self): """ Create an ~uamqp.authentication.cbs_auth_async.SASTokenAuthAsync instance to authenticate the session. """ http_proxy = self._config.http_proxy transport_type = self._config.transport_type auth_timeout = self._config.auth_timeout if isinstance(self._credential, EventHubSharedKeyCredential): # pylint:disable=no-else-return username = self._credential.policy password = self._credential.key if "@sas.root" in username: return authentication.SASLPlain(self._address.hostname, username, password, http_proxy=http_proxy, transport_type=transport_type) return authentication.SASTokenAsync.from_shared_access_key( self._auth_uri, username, password, timeout=auth_timeout, http_proxy=http_proxy, transport_type=transport_type) elif isinstance(self._credential, EventHubSASTokenCredential): token = self._credential.get_sas_token() try: expiry = int(parse_sas_token(token)['se']) except (KeyError, TypeError, IndexError): raise ValueError( "Supplied SAS token has no valid expiry value.") return authentication.SASTokenAsync(self._auth_uri, self._auth_uri, token, expires_at=expiry, timeout=auth_timeout, http_proxy=http_proxy, transport_type=transport_type) else: get_jwt_token = functools.partial(self._credential.get_token, JWT_TOKEN_SCOPE) return authentication.JWTTokenAsync(self._auth_uri, self._auth_uri, get_jwt_token, http_proxy=http_proxy, transport_type=transport_type)