1

我正在尝试在 Blazor WASM(Asp.Net 托管解决方案)中获取 IdentityServer 6 以使用 Microsoft id,但遇到错误消息“AADSTS90023:公共客户端无法发送客户端密码”。我觉得我已经尝试了所有我能想到的配置,但希望我仍然错过了一些东西。

IdentityServer 配置使用我认为适合我的场景的“SPA”配置文件:

"IdentityServer": {
"Clients": {
  "Blazor.Client": {
    "ClientId": "Blazor.Client",
    "ClientName": "Blazor.Client",
    "Profile": "SPA",
    "RedirectUri": "https://localhost:15601",
    "LogoutUri": "https://localhost:15601"
  }
}

}

配置代码遵循最简单的示例:

.AddMicrosoftAccount(options =>
            {
                options.ClientId = <clientId>;
                options.ClientSecret = <secret>
            })

因为这些代码片段基本上是执行此操作的最简单方法,所以我假设我的 AzureAD 应用程序注册有问题,但我不知道是什么问题。我已经包含了清单:

{
"id": "<id>",
"acceptMappedClaims": null,
"accessTokenAcceptedVersion": 2,
"addIns": [],
"allowPublicClient": false,
"appId": "<apiId>",
"appRoles": [],
"oauth2AllowUrlPathMatching": false,
"createdDateTime": "2021-12-10T09:21:08Z",
"certification": null,
"disabledByMicrosoftStatus": null,
"groupMembershipClaims": null,
"identifierUris": [
    "api://<apiId>"
],
"informationalUrls": {
    "termsOfService": null,
    "support": null,
    "privacy": null,
    "marketing": null
},
"keyCredentials": [],
"knownClientApplications": [],
"logoUrl": null,
"logoutUrl": null,
"name": "<name>",
"oauth2AllowIdTokenImplicitFlow": false,
"oauth2AllowImplicitFlow": false,
"oauth2Permissions": [],
"oauth2RequirePostResponse": false,
"optionalClaims": null,
"orgRestrictions": [],
"parentalControlSettings": {
    "countriesBlockedForMinors": [],
    "legalAgeGroupRule": "Allow"
},
"passwordCredentials": [
    {
        "customKeyIdentifier": null,
        "endDate": "2023-12-10T09:21:45.315Z",
        "keyId": "<keyId>",
        "startDate": "2021-12-10T09:21:45.315Z",
        "value": null,
        "createdOn": "2021-12-10T09:21:57.2927675Z",
        "hint": "H1f",
        "displayName": "<displayName>"
    }
],
"preAuthorizedApplications": [],
"publisherDomain": "<publisherDomain>.onmicrosoft.com",
"replyUrlsWithType": [
    {
        "url": "https://localhost:15602/signin-microsoft",
        "type": "Spa"
    }
],
"requiredResourceAccess": [
    {
        "resourceAppId": "00000003-0000-0000-c000-000000000000",
        "resourceAccess": [
            {
                "id": "<someId>",
                "type": "Scope"
            }
        ]
    }
],
"samlMetadataUrl": null,
"signInUrl": null,
"signInAudience": "AzureADandPersonalMicrosoftAccount",
"tags": [],
"tokenEncryptionKeyId": null
}

不支持这种情况还是我做错了什么?

编辑:最终问题出在重定向 uri 平台上,该平台不应设置为“SPA”而是“Web”,因为它不是客户端进行身份验证,而是 IdentityServer Web 服务。相关部分是:

    "replyUrlsWithType": [
    {
        "url": "https://localhost:15602/signin-microsoft",
        "type": "Web"
    }
4

1 回答 1

1
  1. 客户秘密实际上必须保密,即;您不能将其放在网站中并从公共前端使用它。客户端凭据流程设计也是如此。
  2. Blazor webassembly 应用程序在 oAuth/openid 术语中称为“公共应用程序”。

注意:根据微软文档:

公共客户端(本机应用程序和单页应用程序)在兑换授权代码时不得使用机密或证书 - 始终确保您的重定向 URI 正确指示应用程序的类型

  • 因此,请尝试禁用 IdP 上对客户端密码的要求并刷新令牌,因为它们也无法以安全/安全的方式进行处理。

  • 建议您对公共客户端使用 code+PKCE,这在您将 response_type 设置为 code 时会自动发生。

参考微软身份平台和OAuth 2.0授权码流程-微软身份平台| 微软文档

于 2021-12-13T12:49:10.973 回答