Azure oauth v2.0 interaction_required 可信 IP 和 MFA 错误

Azure oauth v2.0 interaction_required error with trusted ip and MFA

我已经在我的 Web 服务器上设置了这个 Azure AD 身份验证工作流:

1 - 用户登录 url :

https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/authorize?
    client_id={client_id}
    &redirect_uri=https://example.com/callback
    &scope=openid%20https%3A%2F%2Fgraph.windows.net%2Fuser.read
    &response_mode=query
    &response_type=code

2 - (MFA) 用户提交了一个表单,其中包含在 phone

上收到的代码

3 - 用户被重定向到 https://example.com/callback?code={azure_given_code}

4 - 我通过以下 POST 请求 服务器端 {azure_given_code} 交换为令牌:

POST https://login.microsoftonline.com/{tenant_id}/oauth2/token

{
    "client_id": "{client_id}",
    "client_secret": "{client_secret}",
    "code": "{azure_given_code}",
    "grant_type": "authorization_code",
    "redirect_uri": "https://example.com/callback"
}

5 - 我收到一个访问令牌并且可以从此 url 再次检索登录用户,服务器端

https://graph.windows.net/me?api-version=1.6

我将我们办公室的 ip 地址添加到受信任的 ip 列表中,以便用户在从我们的网络连接时可以绕过 MFA。

一切正常如果我在办公室网络之外执行此工作流(来自触发 MFA 的不受信任的 ip)。 但是使用我的办公室 ip,第 2 步被绕过(如预期的那样),在第 3 步我得到以下错误:

{
    "error": "interaction_required",
    "error_description": "AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access …",     "error_codes": [50076],
    "timestamp": "2020-03-13 12:54:58Z",
    "trace_id": '...'
}

在这两种情况下(来自受信任和不受信任的 ip)我都缺少什么让这个工作流工作?

我真的被这个问题困住了,非常感谢你的帮助。

这是我解决问题的方法。

当用户被重定向到登录时url https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/authorize?... h是IP被用来判断他是否可以绕过MFA根据受信任的 ip 规则。

然后当检索到 azure_given_code 时,使用 服务器 IP 服务器端 请求令牌这是错误的原因(服务器 IP 不是受信任的 IP)。

执行 POST https://login.microsoftonline.com/{tenant_id}/oauth2/token 客户端确实解决了问题,因为用于请求的 IP 是可信的。