Python ADALacquire_token_with_client_ 刷新令牌?

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 应用执行我需要的操作,但是使用刷新令牌而不是每次运行都获取新令牌不是最佳实践吗?


慕妹3242003
浏览 287回答 1
1回答

largeQ

是的,我同意使用刷新令牌而不是每次都获取新的新令牌是最佳做法。使用客户端凭据授予发布刷新令牌没有任何好处。这就是为什么RFC6749 第 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--客户秘密-https://adal-python.readthedocs.io/en/latest/
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python