本文整理汇总了Python中adal.AdalError方法的典型用法代码示例。如果您正苦于以下问题:Python adal.AdalError方法的具体用法?Python adal.AdalError怎么用?Python adal.AdalError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类adal
的用法示例。
在下文中一共展示了adal.AdalError方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: token
# 需要导入模块: import adal [as 别名]
# 或者: from adal import AdalError [as 别名]
def token(self) -> str:
"""
Return the access token.
Returns
-------
str
Access Token
"""
if self._expired_creds:
try:
self._refresh_creds()
except AdalError:
self._get_token()
return self.config_data["accessToken"]
示例2: refresh_session
# 需要导入模块: import adal [as 别名]
# 或者: from adal import AdalError [as 别名]
def refresh_session(self, session=None):
"""Return updated session if token has expired, attempts to
refresh using newly acquired token.
If a session object is provided, configure it directly. Otherwise,
create a new session and return it.
:param session: The session to configure for authentication
:type session: requests.Session
:rtype: requests.Session.
"""
if 'refresh_token' in self.token:
try:
token = self._context.acquire_token_with_refresh_token(
self.token['refresh_token'],
self.id,
self.resource,
self.secret # This is needed when using Confidential Client
)
self.token = self._convert_token(token)
except adal.AdalError as err:
raise_with_traceback(AuthenticationError, "", err)
return self.signed_session(session)
示例3: set_token
# 需要导入模块: import adal [as 别名]
# 或者: from adal import AdalError [as 别名]
def set_token(self):
"""Get token using Username/Password credentials.
:raises: AuthenticationError if credentials invalid, or call fails.
"""
super(UserPassCredentials, self).set_token()
try:
token = self._context.acquire_token_with_username_password(
self.resource,
self.username,
self.password,
self.id
)
self.token = self._convert_token(token)
except adal.AdalError as err:
raise_with_traceback(AuthenticationError, "", err)
示例4: acquire_authorization_header
# 需要导入模块: import adal [as 别名]
# 或者: from adal import AdalError [as 别名]
def acquire_authorization_header(self):
"""Acquire tokens from AAD."""
try:
return self._acquire_authorization_header()
except (AdalError, KustoClientError) as error:
if self.authentication_method is AuthenticationMethod.aad_username_password:
kwargs = {"username": self.username, "client_id": self.client_id}
elif self.authentication_method is AuthenticationMethod.aad_application_key:
kwargs = {"client_id": self.client_id}
elif self.authentication_method is AuthenticationMethod.aad_device_login:
kwargs = {"client_id": self.client_id}
elif self.authentication_method is AuthenticationMethod.aad_application_certificate:
kwargs = {"client_id": self.client_id, "thumbprint": self.thumbprint}
elif self.authentication_method is AuthenticationMethod.aad_msi:
kwargs = self.msi_params
elif self.authentication_method is AuthenticationMethod.token_provider:
kwargs = {}
else:
raise error
kwargs["resource"] = self.kusto_uri
if self.authentication_method is AuthenticationMethod.aad_msi:
kwargs["authority"] = AuthenticationMethod.aad_msi.value
elif self.authentication_method is AuthenticationMethod.token_provider:
kwargs["authority"] = AuthenticationMethod.token_provider.value
elif self.auth_context is not None:
kwargs["authority"] = self.auth_context.authority.url
raise KustoAuthenticationError(self.authentication_method.value, error, **kwargs)
示例5: signed_session
# 需要导入模块: import adal [as 别名]
# 或者: from adal import AdalError [as 别名]
def signed_session(self, session=None):
"""Create requests session with any required auth headers applied.
If a session object is provided, configure it directly. Otherwise,
create a new session and return it.
:param session: The session to configure for authentication
:type session: requests.Session
:rtype: requests.Session
"""
session = super(AdalAuthentication, self).signed_session(session)
try:
raw_token = self._adal_method(*self._args, **self._kwargs)
except adal.AdalError as err:
# pylint: disable=no-member
if 'AADSTS70008:' in ((getattr(err, 'error_response', None) or {}).get('error_description') or ''):
raise Expired("Credentials have expired due to inactivity.")
else:
raise AuthenticationError(err)
except ConnectionError as err:
raise AuthenticationError('Please ensure you have network connection. Error detail: ' + str(err))
scheme, token = raw_token['tokenType'], raw_token['accessToken']
header = "{} {}".format(scheme, token)
session.headers['Authorization'] = header
return session
示例6: test_adal_authentication
# 需要导入模块: import adal [as 别名]
# 或者: from adal import AdalError [as 别名]
def test_adal_authentication(self):
def success_auth():
return {
'tokenType': 'https',
'accessToken': 'cryptictoken'
}
credentials = AdalAuthentication(success_auth)
session = credentials.signed_session()
self.assertEqual(session.headers['Authorization'], 'https cryptictoken')
def error():
raise adal.AdalError("You hacker", {})
credentials = AdalAuthentication(error)
with self.assertRaises(AuthenticationError) as cm:
session = credentials.signed_session()
def expired():
raise adal.AdalError("Too late", {'error_description': "AADSTS70008: Expired"})
credentials = AdalAuthentication(expired)
with self.assertRaises(TokenExpiredError) as cm:
session = credentials.signed_session()
def connection_error():
raise ConnectionError("Plug the network")
credentials = AdalAuthentication(connection_error)
with self.assertRaises(AuthenticationError) as cm:
session = credentials.signed_session()