我一直在使用 Microsoft.Identity 平台并试图让它与 aspnetcore 6.0 中的基本模板一起使用,但我陷入了无限登录循环。
我正在使用从 web 应用程序和 web api 模板创建的项目(使用这些命令"dotnet new webapi --force --auth IndividualB2C"
和"dotnet new webapp --force --auth IndividualB2C"
),然后更新两者中的 appsettings 以连接到我的 Azure B2C 租户。
网页应用
"AzureAdB2C": {
"CallbackPath": "/signin-oidc",
"ClientId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"ClientSecret": "xxxxx",
"Domain": "xxxx.onmicrosoft.com",
"EditProfilePolicyId": "B2C_1_EditProfile",
"Instance": "https://xxxx.b2clogin.com/",
"SignedOutCallbackPath": "/signout/B2C_1_susi",
"SignUpSignInPolicyId": "B2C_1_SUSI"
},
"DownstreamApi": {
"BaseUrl": "https://localhost:7208/",
"Scopes": "https://xxxx.onmicrosoft.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/user.impersonation"
}
网页接口
"AzureAdB2C": {
"ClientId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"Domain": "xxxx.onmicrosoft.com",
"Instance": "https://xxxx.b2clogin.com/",
"Scopes": "https://xxxx.onmicrosoft.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/user.impersonation"
"SignUpSignInPolicyId": "B2C_1_SUSI"
}
进行这些更改后,我可以运行应用程序,Web 应用程序将尝试通过我的社交帐户登录,然后进入登录服务器和应用程序重定向 URL 之间的无限循环重定向。
我确实收到一条引发 MicrosoftIdentityWebChallengeUserException 的日志消息(大概是因为我需要同意范围)。我的理解是[AuthorizeForScopes(ScopeKeySection = "DownstreamApi:Scopes")]
Razor 页面上的属性应该为我处理这个同意工作流,但它似乎没有这样做。
在配置这些示例应用程序或捕获 WebChallenge 异常的方法时,我需要做些什么额外的事情(如果是,我如何将质询发回给用户)?
我觉得我在这里遗漏了一些明显的东西来使它起作用,但我似乎找不到它。任何人都可以提供一些指导以使其正常工作吗?