Python ADAL库的身份验证方法acquire_token_with_client_credentials是否有理由不返回刷新令牌?我认为守护进程应用程序每次运行时都不需要使用刷新令牌,但我觉得其他身份验证方法确实返回了一个。
代码示例:
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应用程序执行我需要的操作,但是不是最佳做法是使用刷新令牌而不是每次运行时获取新的令牌?
是的,我同意使用刷新令牌而不是每次都获取新的令牌是最佳做法。
使用客户端凭据授予发布刷新令牌没有任何好处。这就是为什么RFC6749 section 4.4.3表示不应该包括刷新令牌的原因。
根据文档,“acquire_token_with_client_credentials”仅返回访问令牌。
因此,要使用刷新令牌,python adal库支持其他身份验证方法,例如:“acquire_token”,“acquire_token_with_refresh_token”等。您可以查看文档。
以下是文档链接: