本文整理汇总了Python中msrestazure.azure_active_directory.AADTokenCredentials方法的典型用法代码示例。如果您正苦于以下问题:Python azure_active_directory.AADTokenCredentials方法的具体用法?Python azure_active_directory.AADTokenCredentials怎么用?Python azure_active_directory.AADTokenCredentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msrestazure.azure_active_directory
的用法示例。
在下文中一共展示了azure_active_directory.AADTokenCredentials方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: authenticate_device_code
# 需要导入模块: from msrestazure import azure_active_directory [as 别名]
# 或者: from msrestazure.azure_active_directory import AADTokenCredentials [as 别名]
def authenticate_device_code():
"""
Authenticate the end-user using device auth.
"""
authority_host_uri = 'https://login.microsoftonline.com'
tenant = '<TENANT_ID_OR_DOMAIN>'
authority_uri = authority_host_uri + '/' + tenant
resource_uri = 'https://management.core.windows.net/'
client_id = '04b07795-8ddb-461a-bbee-02f9e1bf7b46'
context = adal.AuthenticationContext(authority_uri, api_version=None)
code = context.acquire_user_code(resource_uri, client_id)
print(code['message'])
mgmt_token = context.acquire_token_with_device_code(resource_uri, code, client_id)
credentials = AADTokenCredentials(mgmt_token, client_id)
return credentials
示例2: authenticate_username_password
# 需要导入模块: from msrestazure import azure_active_directory [as 别名]
# 或者: from msrestazure.azure_active_directory import AADTokenCredentials [as 别名]
def authenticate_username_password():
"""
Authenticate using user w/ username + password.
This doesn't work for users or tenants that have multi-factor authentication required.
"""
authority_host_uri = 'https://login.microsoftonline.com'
tenant = '<TENANT>'
authority_uri = authority_host_uri + '/' + tenant
resource_uri = 'https://management.core.windows.net/'
username = '<USERNAME>'
password = '<PASSWORD>'
client_id = '<CLIENT_ID>'
context = adal.AuthenticationContext(authority_uri, api_version=None)
mgmt_token = context.acquire_token_with_username_password(resource_uri, username, password, client_id)
credentials = AADTokenCredentials(mgmt_token, client_id)
return credentials
示例3: authenticate_client_key
# 需要导入模块: from msrestazure import azure_active_directory [as 别名]
# 或者: from msrestazure.azure_active_directory import AADTokenCredentials [as 别名]
def authenticate_client_key():
"""
Authenticate using service principal w/ key.
"""
authority_host_uri = 'https://login.microsoftonline.com'
tenant = '<TENANT>'
authority_uri = authority_host_uri + '/' + tenant
resource_uri = 'https://management.core.windows.net/'
client_id = '<CLIENT_ID>'
client_secret = '<CLIENT_SECRET>'
context = adal.AuthenticationContext(authority_uri, api_version=None)
mgmt_token = context.acquire_token_with_client_credentials(resource_uri, client_id, client_secret)
credentials = AADTokenCredentials(mgmt_token, client_id)
return credentials
示例4: authenticate_client_cert
# 需要导入模块: from msrestazure import azure_active_directory [as 别名]
# 或者: from msrestazure.azure_active_directory import AADTokenCredentials [as 别名]
def authenticate_client_cert():
"""
Authenticate using service principal w/ cert.
"""
authority_host_uri = 'https://login.microsoftonline.com'
tenant = '<TENANT>'
authority_uri = authority_host_uri + '/' + tenant
resource_uri = 'https://management.core.windows.net/'
client_id = '<CLIENT_ID>'
client_cert = '<CLIENT_CERT>'
client_cert_thumbprint = '<CLIENT_CERT_THUMBPRINT>'
context = adal.AuthenticationContext(authority_uri, api_version=None)
mgmt_token = context.acquire_token_with_client_certificate(resource_uri, client_id, client_cert, client_cert_thumbprint)
credentials = AADTokenCredentials(mgmt_token, client_id)
return credentials
示例5: authenticate_device_code
# 需要导入模块: from msrestazure import azure_active_directory [as 别名]
# 或者: from msrestazure.azure_active_directory import AADTokenCredentials [as 别名]
def authenticate_device_code(self):
"""
Authenticate the end-user using device auth.
"""
context = self._get_authentication_context()
code = context.acquire_user_code(
resource=self.resource,
client_id=self.client_id)
print(code['message'])
mgmt_token = context.acquire_token_with_device_code(
resource=self.resource,
user_code_info=code,
client_id=self.client_id)
credentials = AADTokenCredentials(
token=mgmt_token,
client_id=self.client_id)
return credentials.token
示例6: refresh_credential
# 需要导入模块: from msrestazure import azure_active_directory [as 别名]
# 或者: from msrestazure.azure_active_directory import AADTokenCredentials [as 别名]
def refresh_credential(self, credentials):
"""
Refresh credentials
"""
print_debug('Refreshing credentials')
authority_uri = AUTHORITY_HOST_URI + '/' + self.get_tenant_id()
existing_cache = self.context.cache
context = adal.AuthenticationContext(authority_uri, cache=existing_cache)
new_token = context.acquire_token(credentials.token['resource'],
credentials.token['user_id'],
credentials.token['_client_id'])
new_credentials = AADTokenCredentials(new_token, credentials.token.get('_client_id'))
return new_credentials
示例7: acquire_token_with_username_password
# 需要导入模块: from msrestazure import azure_active_directory [as 别名]
# 或者: from msrestazure.azure_active_directory import AADTokenCredentials [as 别名]
def acquire_token_with_username_password(self, authority, resource, username, password, client_id, tenant):
authority_uri = authority
if tenant is not None:
authority_uri = authority + '/' + tenant
context = AuthenticationContext(authority_uri)
token_response = context.acquire_token_with_username_password(resource, username, password, client_id)
return AADTokenCredentials(token_response)