Oauth 2.0 Active Directory是否不支持PKCE的授权代码流?

Oauth 2.0 Active Directory是否不支持PKCE的授权代码流?,oauth-2.0,active-directory,azure-active-directory,pkce,Oauth 2.0,Active Directory,Azure Active Directory,Pkce,我尝试使用当前推荐的PKCE授权代码流从Active Directory收集访问令牌。客户将是一个公共SPA,这是选择流量的原因 收集openid配置表单AD以及用户的授权代码非常有效。 但我无法从以下端点请求访问令牌: https://login.microsoftonline.com/{tenantId}/oauth2/token. 我试图在《邮递员》中重新构建请求: POST /7e8c2868-7490-4dd7-82b7-f5ec29222d30/oauth2/token HTTP/

我尝试使用当前推荐的PKCE授权代码流从Active Directory收集访问令牌。客户将是一个公共SPA,这是选择流量的原因

收集openid配置表单AD以及用户的授权代码非常有效。 但我无法从以下端点请求访问令牌:

https://login.microsoftonline.com/{tenantId}/oauth2/token.
我试图在《邮递员》中重新构建请求:

POST /7e8c2868-7490-4dd7-82b7-f5ec29222d30/oauth2/token HTTP/1.1
Host: login.microsoftonline.com
Accept: application/json, text/plain, */*
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache

grant_type=authorization_code
code=...
code_verifier=...
client_id=...
redirect_uri=...
…并以以下消息结束:

{
  "error": "invalid_client",
  "error_description": "AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'.\r\nTrace ID: ed0413ad-89f1-4a2b-8d68-e23498701800\r\nCorrelation ID: deb53b0d-5398-4f72-a9a5-6c0863547b99\r\nTimestamp: 2020-03-06 09:30:36Z",
  "error_codes": [
    7000218
  ],
  "timestamp": "2020-03-06 09:30:36Z",
  "trace_id": "ed0413ad-89f1-4a2b-8d68-e23498701800",
  "correlation_id": "deb53b0d-5398-4f72-a9a5-6c0863547b99",
  "error_uri": "https://login.microsoftonline.com/error?code=7000218"
}
这似乎有些奇怪,因为PKCE的身份验证流的官方规范不需要client_secret或client_断言。这仅适用于默认身份验证流

广告执行是否有问题,或者我是否对其进行了错误配置

web客户端的清单如下所示:

{
  "id": "...",
  "acceptMappedClaims": null,
  "accessTokenAcceptedVersion": null, 
  "addIns": [],
  "allowPublicClient": true,
  "appId": "...",
  "appRoles": [],
  "oauth2AllowUrlPathMatching": false,
  "createdDateTime": "...",
  "groupMembershipClaims": null,
  "identifierUris": [],
  "informationalUrls": {
    "termsOfService": null,
    "support": null,
    "privacy": null,
    "marketing": null
  },
  "keyCredentials": [],
  "knownClientApplications": [],
  "logoUrl": null,
  "logoutUrl": null,
  "name": "...",
  "oauth2AllowIdTokenImplicitFlow": false,
  "oauth2AllowImplicitFlow": false,
  "oauth2Permissions": [],
  "oauth2RequirePostResponse": false,
  "optionalClaims": null,
  "orgRestrictions": [],
  "parentalControlSettings": {
    "countriesBlockedForMinors": [],
    "legalAgeGroupRule": "Allow"
  },
  "passwordCredentials": [],
  "preAuthorizedApplications": [],
  "publisherDomain": "...",
  "replyUrlsWithType": [
    {
        "url": "http://localhost:4200",
        "type": "Web"
    }
  ],
  "requiredResourceAccess": [
    {
        "resourceAppId": "00000003-0000-0000-c000-000000000000",
        "resourceAccess": [
            {
                "id": "...",
                "type": "Scope"
            }
        ]
    }
  ],
  "samlMetadataUrl": null,
  "signInUrl": null,
  "signInAudience": "AzureADMyOrg",
  "tags": [],
  "tokenEncryptionKeyId": null
}
GET /.../oauth2/authorize
  response_type=code
  &client_id=...
  &state=...
  &redirect_uri=http%3A%2F%2Flocalhost%3A4200
  &scope=openid%20user_impersonation%20offline_access
  &code_challenge=...
  &code_challenge_method=...
  &nonce=...

Host: login.microsoftonline.com
我的应用程序在广告中注册为公共应用程序

在此之前发送的身份验证请求如下所示:

{
  "id": "...",
  "acceptMappedClaims": null,
  "accessTokenAcceptedVersion": null, 
  "addIns": [],
  "allowPublicClient": true,
  "appId": "...",
  "appRoles": [],
  "oauth2AllowUrlPathMatching": false,
  "createdDateTime": "...",
  "groupMembershipClaims": null,
  "identifierUris": [],
  "informationalUrls": {
    "termsOfService": null,
    "support": null,
    "privacy": null,
    "marketing": null
  },
  "keyCredentials": [],
  "knownClientApplications": [],
  "logoUrl": null,
  "logoutUrl": null,
  "name": "...",
  "oauth2AllowIdTokenImplicitFlow": false,
  "oauth2AllowImplicitFlow": false,
  "oauth2Permissions": [],
  "oauth2RequirePostResponse": false,
  "optionalClaims": null,
  "orgRestrictions": [],
  "parentalControlSettings": {
    "countriesBlockedForMinors": [],
    "legalAgeGroupRule": "Allow"
  },
  "passwordCredentials": [],
  "preAuthorizedApplications": [],
  "publisherDomain": "...",
  "replyUrlsWithType": [
    {
        "url": "http://localhost:4200",
        "type": "Web"
    }
  ],
  "requiredResourceAccess": [
    {
        "resourceAppId": "00000003-0000-0000-c000-000000000000",
        "resourceAccess": [
            {
                "id": "...",
                "type": "Scope"
            }
        ]
    }
  ],
  "samlMetadataUrl": null,
  "signInUrl": null,
  "signInAudience": "AzureADMyOrg",
  "tags": [],
  "tokenEncryptionKeyId": null
}
GET /.../oauth2/authorize
  response_type=code
  &client_id=...
  &state=...
  &redirect_uri=http%3A%2F%2Flocalhost%3A4200
  &scope=openid%20user_impersonation%20offline_access
  &code_challenge=...
  &code_challenge_method=...
  &nonce=...

Host: login.microsoftonline.com
更新2021 Microsoft最终更新了他们的门户,因此我们现在有了一个UI,可以使用PKCE正确配置授权代码流

您只需打开已注册AAD应用程序的身份验证页面。在那里,您可以通过单击左侧的按钮添加新平台:

选择新的单页应用程序磁贴并输入重定向URL

先前的答复(清单) 我刚在包裹里找到答案。目前Azure广告似乎正在致力于支持此身份验证流。要激活它,您必须为重定向URL设置一个新的类型,它们最近刚刚添加

要将授权代码流与PKCE与Azure Active Directory一起使用,您需要:

  • 设置向azure ad应用程序添加web平台并添加重定向URL
  • 将这些重定向URL的类型从“Web”更改为“Spa”。这必须在清单中完成。更改它将使URL从身份验证页面中消失。但这没关系,因为它仍然存在于舱单中
  • 将web应用视为公共客户端(身份验证>高级设置>默认客户端类型-“是”)

  • 现在,令牌端点不再需要
    client\u secret
    client\u断言

    Chrsi,身份验证请求URL是什么样子的?您是否正确指定了
    code\u challenge
    code\u challenge\u方法
    参数?你能把这些信息添加到问题中吗?很好。更新了问题,看起来好像
    code\u挑战
    code\u挑战
    方法不存在。因此,它可能被adOh no.解释为正常的身份验证代码流。。。我捕捉到了错误的授权请求。再次编辑问题。它实际上包括了挑战。这种方法对我不起作用。此外,现在水疗设置一般可用。因此,不再需要黑客了。@kwoxer感谢您指出这一点。是的,他们最终更新了Azure门户,现在可以通过UI添加SPA平台。我相应地更新了答案。但要澄清的是,编辑清单不是“黑客”。在UI列表中添加SPA平台只是一种用户友好的方式来更新清单:)没错。也许你对我的问题有一个想法,这与这个问题非常相似,我认为这一定是一个bug,因为在我使用平台之前,它已经解决了: