AzureMLTokenAuthentication Class

Manages authentication and access tokens in the context of submitted runs.

The Azure Machine Learning token is generated when a run is submitted and is only available to the code that submitted the run. The AzureMLTokenAuthentication class can only be used in the context of the submitted run. The returned token cannot be used against any Azure Resource Manager (ARM) operations like provisioning compute. The Azure Machine Learning token is useful when executing a program remotely where it might be unsafe to use the private credentials of a user.

Authorize users by their Azure ML token.

The Azure ML token is generated when a run is submitted and is only available to the code submitted. The class can only be used in the context of the submitted run. The token cannot be used against any ARM operations like provisioning compute. The Azure ML token is useful when executing a program remotely where it might be unsafe to use the user's private credentials. The consumer of this class should call the class method create which creates a new object or returns a registered instance with the same run_scope (subscription_id, resource_group_name, workspace_name, experiment_name, run_id) provided.

Inheritance
AzureMLTokenAuthentication

Constructor

AzureMLTokenAuthentication(azureml_access_token, expiry_time=None, host=None, subscription_id=None, resource_group_name=None, workspace_name=None, experiment_name=None, run_id=None, user_email=None, experiment_id=None, cloud='AzureCloud')

Parameters

Name Description
azureml_access_token
Required
str

The Azure ML token is generated when a run is submitted and is only available to the code submitted.

expiry_time

The Azure ML token's expiration time.

default value: None
host
str
default value: None
subscription_id
str

The Azure subscription ID where the experiment is submitted.

default value: None
resource_group_name
str

The resource group name where the experiment is submitted.

default value: None
workspace_name
str

The workspace where the experiment is submitted.

default value: None
experiment_name
str

The experiment name.

default value: None
experiment_id
str

The experiment id. If provided experiment_name will be ignored

default value: None
run_id
str

The ID of the run.

default value: None
user_email
str

Optional user email.

default value: None
cloud
str

The name of the target cloud. Can be one of "AzureCloud", "AzureChinaCloud", or "AzureUSGovernment". If no cloud is specified, "AzureCloud" is used.

default value: AzureCloud
azureml_access_token
Required
str

The Azure ML token is generated when a run is submitted and is only available to the code submitted.

expiry_time
Required
<xref:datetime.Datetime>

The Azure ML token's expiration time.

host
Required
str
subscription_id
Required
str

The Azure subscription ID where the experiment is submitted.

resource_group_name
Required
str

The resource group name where the experiment is submitted.

workspace_name
Required
str

The workspace where the experiment is submitted.

experiment_name
Required
str

The experiment name.

experiment_id
Required
str

The experiment id. If provided experiment_name will be ignored

run_id
Required
str

The ID of the run.

user_email
Required
str

An optional user email.

cloud
Required
str

The name of the target cloud. Can be one of "AzureCloud", "AzureChinaCloud", or "AzureUSGovernment". If no cloud is specified, "AzureCloud" is used.

Remarks

Consumers of this class should call the class method create, which creates a new object or returns a registered instance with the same run_scope (subscription_id, resource_group_name, workspace_name, experiment_name, run_id) provided.

Methods

create

Create an AzureMLTokenAuthentication object or return a registered instance with the same run_scope.

get_authentication_header

Return the HTTP authorization header.

The authorization header contains the user access token for access authorization against the service.

set_token

Update Azure ML access token.

create

Create an AzureMLTokenAuthentication object or return a registered instance with the same run_scope.

create(azureml_access_token, expiry_time, host, subscription_id, resource_group_name, workspace_name, experiment_name, run_id, user_email=None, experiment_id=None)

Parameters

Name Description
cls
Required

Indicates class method.

azureml_access_token
Required
str

The Azure ML token is generated when a run is submitted and is only available to the code submitted.

expiry_time
Required

The Azure ML token's expiration time.

host
Required
str
subscription_id
Required
str

The Azure subscription ID where the experiment is submitted.

resource_group_name
Required
str

The resource group name where the experiment is submitted.

workspace_name
Required
str

The workspace where the experiment is submitted.

experiment_name
Required
str

The experiment name.

experiment_id
str

The experiment id. If provided experiment_name will be ignored

default value: None
run_id
Required
str

The ID of the run.

user_email
str

An optional user email.

default value: None

get_authentication_header

Return the HTTP authorization header.

The authorization header contains the user access token for access authorization against the service.

get_authentication_header()

Returns

Type Description

Returns the HTTP authorization header.

set_token

Update Azure ML access token.

set_token(token, expiry_time)

Parameters

Name Description
token
Required
str

The token to refresh.

expiry_time
Required

The new expiration time.

Attributes

expiry_time

Return the Azure ML token's expiration time.

Returns

Type Description

The expiration time.

token

Return the Azure ML token.

Returns

Type Description
str

The Azure ML access token.

EXPIRATION_THRESHOLD_IN_SECONDS

Seconds before expiration that refresh process starts.

EXPIRATION_THRESHOLD_IN_SECONDS = 95

REFRESH_INTERVAL_IN_SECONDS

Seconds before a retry times out.

REFRESH_INTERVAL_IN_SECONDS = 30