SASTokenAuth Class

CBS authentication using SAS tokens.

Inheritance
SASTokenAuth
SASTokenAuth

Constructor

SASTokenAuth(audience, uri, token, expires_in=None, expires_at=None, username=None, password=None, port=None, timeout=10, retry_policy=<uamqp.authentication.cbs_auth.TokenRetryPolicy object>, verify=None, token_type=b'servicebus.windows.net:sastoken', http_proxy=None, transport_type=<TransportType.Amqp: 1>, encoding='UTF-8', **kwargs)

Parameters

audience
str or bytes
Required

The token audience field. For SAS tokens this is usually the URI.

uri
str
Required

The AMQP endpoint URI. This must be provided as a decoded string.

token
str or <xref:bytes.>
Required

The SAS token.

expires_in
timedelta
default value: None

The total remaining seconds until the token expires.

expires_at
float
default value: None

The timestamp at which the SAS token will expire formatted as seconds since epoch.

username
str
default value: None

The SAS token username, also referred to as the key name or policy name. This can optionally be encoded into the URI.

password
str
default value: None

The SAS token password, also referred to as the key. This can optionally be encoded into the URI.

port
int
default value: None

The TLS port - default for AMQP is 5671.

timeout
float
default value: 10

The timeout in seconds in which to negotiate the token. The default value is 10 seconds.

retry_policy
TokenRetryPolicy
Required

The retry policy for the PUT token request. The default retry policy has 3 retries.

verify
str
default value: None

The path to a user-defined certificate.

token_type
bytes
default value: b'servicebus.windows.net:sastoken'

The type field of the token request. Default value is b"servicebus.windows.net:sastoken".

http_proxy
dict
default value: None

HTTP proxy configuration. This should be a dictionary with the following keys present: 'proxy_hostname' and 'proxy_port'. Additional optional keys are 'username' and 'password'.

transport_type
<xref:uamqp.TransportType>
default value: TransportType.Amqp

The transport protocol type - default is ~uamqp.TransportType.Amqp. ~uamqp.TransportType.AmqpOverWebsocket is applied when http_proxy is set or the transport type is explicitly requested.

encoding
str
default value: UTF-8

The encoding to use if hostname is provided as a str. Default is 'UTF-8'.

refresh_window
int

The time in seconds before the token expiration time to start the process of token refresh. Default value is 10% of the remaining seconds until the token expires.

Methods

from_shared_access_key

Attempt to create a CBS token session using a Shared Access Key such as is used to connect to Azure services.

time to start the process of token refresh. Default value is 10% of the remaining seconds until the token expires.

update_token

If a username and password are present - attempt to use them to request a fresh SAS token.

from_shared_access_key

Attempt to create a CBS token session using a Shared Access Key such as is used to connect to Azure services.

time to start the process of token refresh. Default value is 10% of the remaining seconds until the token expires.

from_shared_access_key(uri, key_name, shared_access_key, expiry=None, port=None, timeout=10, retry_policy=<uamqp.authentication.cbs_auth.TokenRetryPolicy object>, verify=None, http_proxy=None, transport_type=<TransportType.Amqp: 1>, encoding='UTF-8', **kwargs)

Parameters

uri
str
Required

The AMQP endpoint URI. This must be provided as a decoded string.

key_name
str
Required

The SAS token username, also referred to as the key name or policy name.

shared_access_key
str
Required

The SAS token password, also referred to as the key.

expiry
int
Required

The lifetime in seconds for the generated token. Default is 1 hour.

port
int
default value: None

The TLS port - default for AMQP is 5671.

timeout
float
default value: None

The timeout in seconds in which to negotiate the token. The default value is 10 seconds.

retry_policy
TokenRetryPolicy
default value: 10

The retry policy for the PUT token request. The default retry policy has 3 retries.

verify
str
Required

The path to a user-defined certificate.

http_proxy
dict
default value: None

HTTP proxy configuration. This should be a dictionary with the following keys present: 'proxy_hostname' and 'proxy_port'. Additional optional keys are 'username' and 'password'.

transport_type
<xref:uamqp.TransportType>
default value: None

The transport protocol type - default is ~uamqp.TransportType.Amqp. ~uamqp.TransportType.AmqpOverWebsocket is applied when http_proxy is set or the transport type is explicitly requested.

encoding
str
default value: TransportType.Amqp

The encoding to use if hostname is provided as a str. Default is 'UTF-8'.

refresh_window
int
default value: UTF-8

The time in seconds before the token expiration

update_token

If a username and password are present - attempt to use them to request a fresh SAS token.

update_token()