使用隐式授权流的 Azure B2C 身份验证

Azure B2C authentication with Implicit Grant Flow

我使用的是 Azure B2C 租户,它有一些用户。我创建了一个应用程序,并在身份验证中选择 web。我取消选择 隐式授权流程 因为我收到警告 This app has implicit grant settings enabled. If you are using any of these URIs in a SPA with MSAL.js 2.0, you should migrate URIs. 我只选择了 Local 而没有其他提供者。我还有一个 Sing In User 流程​​。使用这些设置,我什至无法从我的 C# ASP.NET 应用程序中看到登录页面。所以我选择了隐式流。那解决了问题,我可以看到登录页面并可以登录了。

我的问题是为什么我需要 隐式流 来进行 web 身份验证。

除非您使用旧版本的 MSAL,即 MSAL1.XXX 版本,否则您不需要隐式流。

The latest version of MSAL.js i.e., MSAL 2.XXX version only works with the authorization code flow with PKCE instead of implicit flow . So you need to implement PKCE flow instead of implicit Grand.

如果您使用的是最新版本的 MSAL,请不要使用将启用隐式流的 Access_tokenid_token 设置。

如果您正在使用 the Microsoft Identity Web authentication library or one of the Microsoft Identity Web project templates, then it passes response_type=code id_token in the authorization request, which represents the hybrid flow

这就是为什么您必须 select 应用程序注册的“ID 令牌”设置。