Azure AD不授予offline_access

时间:2019-09-20 11:09:28

标签: azure-active-directory

我正在尝试使用Azure AD将用户登录到我的应用程序中,但是我无法在服务器上获得offline_access权限(作用域)。

我的最初要求是:

https://login.microsoftonline.com/{tenant}/oauth2/authorize?client_id={client_id}&response_type=code&redirect_uri=https%3A%2F%2Fservice%2Emyserver%2Ecz&scope=user.read%20openid%20profile%20offline_access&response_mode=form_post&state=azure_login

如您所见,我要求输入user.readopenidprofileoffline_access。但是当我获得令牌时,响应为:

{
    "token_type": "Bearer",
    "scope": "profile openid email User.Read",
    "expires_in": 3599,
    "ext_expires_in": 3599,
    "access_token": "ey...",
    "id_token": "ey..."
}

首先,我没有要求发送电子邮件,其次没有refresh_tokenexpires_on

最有趣的是,如果我在计算机上本地运行应用程序(redirect_uri为http://localhost:8080),则会得到完全不同的响应:

{
    "token_type": "Bearer",
    "expires_in": "3599",
    "ext_expires_in": "3599",
    "expires_on": "1568980038",
    "access_token": "AQ...",
    "refresh_token": "AQ...",
    "id_token": "ey..."
}

我在本地有offline_access权限,另一方面,我没有任何其他权限。例如,我无法从http://localhost:8080访问https://graph.microsoft.com/v1.0/me

要在服务器上获得offline_access权限,我该怎么做?

1 个答案:

答案 0 :(得分:0)

好,我终于找到了。整个问题是由API的组合引起的。有以下链接:

https://login.microsoftonline.com/{tenant}/oauth2/authorize
https://login.microsoftonline.com/{tenant}/oauth2/token
https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize
https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token

我忽略了“ v2.0”并将其混合在一起。

相关问题