1

我尝试添加 Azure AD 身份验证。我已经有一个默认的身份验证AccountController

当我尝试调用 https://localhost:44304/signin-oidc 时出现错误

我尝试像这样连接:

services.AddMicrosoftIdentityWebAppAuthentication(Configuration);

或者

services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
 .AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"));

AzureAd 在 appsettings 中实现,对于测试项目它可以工作。

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });
4

1 回答 1

1

When I try call https://localhost:44304/signin-oidc I get error

When you call above url by broswer directly, it should be Http GET request. This is the reason you are experiencing the phenomenon.

Step 1

Open F12 to monitor the Http request in the Network.

enter image description here

1. Under normal operation steps, the captured Http Request is of the post method.

enter image description here

  1. call https://localhost:44304/signin-oidc by browser.

enter image description here

Related issue

Microsoft Account Authentication not working #1012

CallbackPath is used for the middleware to receive the results of the remote auth. You do not need a route/controller/action for this path. Once it has processed the results and generated the sign-in identity/cookie, then it will redirect back to your app code, either to where it started or where you told it to return to in the initial challenge.

Recommendation: keep the default CallbackPath value /signin-microsoft and register https://localhost:50001/signin-microsoft in the MSA portal.

于 2021-07-28T06:30:13.083 回答