Python ADAL acquisition_token_with_client_credentials刷新令牌?

时间:2019-03-08 17:15:57

标签: python adal

Python ADAL库的身份验证方法 acquire_token_with_client_credentials 是否没有返回刷新令牌的原因?我想Daemon应用程序不需要在每次运行时都使用刷新令牌,但是其他身份验证方法确实返回一个身份验证对我来说很奇怪。

代码示例:

class AzureActiveDirectory_Helper:
_config = Configuration()
_resource = _config.Resource
_graph_api_endpoint = _config.Graph_API_Endpoint
_authority = _config.Authority

def __init__(self):
    self.Context = adal.AuthenticationContext(self._authority)
    self.Token = self.Context.acquire_token_with_client_credentials(
        resource=self._resource,
        client_id=self._config.Client_ID,
        client_secret="thisIsASuperSecretKey!!"
    )

    self.Headers = {
        'Authorization' : f'Bearer {self.Token["accessToken"]}',
        'Accept' : 'application/json',
        'Content-Type' : 'application/json'
    }

self.Token中的值确实具有accessToken值,并且该令牌确实允许我针对Azure AD应用程序执行所需的操作,但是使用刷新令牌而不是获取刷新令牌不是最佳实践吗?每次运行都有新鲜的令牌吗?

1 个答案:

答案 0 :(得分:3)

是的,我同意,最佳做法是使用刷新令牌而不是每次都获取新的新鲜令牌。

使用客户凭证授予的刷新令牌的发行没有好处。这就是RFC6749 section 4.4.3指示不应包含刷新令牌的原因。

根据文档,“ acquire_token_with_client_credentials”仅返回访问令牌。

因此,要使用刷新令牌,python adal库支持其他身份验证方法,例如: “ acquire_token”,“ acquire_token_with_refresh_token”等。您可以检查文档。

下面是文档链接:

https://docs.microsoft.com/en-us/python/api/adal/adal.authentication_context.authenticationcontext?view=azure-python#acquire-token-with-client-credentials-resource--client-id--client-secret-

https://adal-python.readthedocs.io/en/latest/

相关问题