首页 > 解决方案 > 没有重定向 AAD RedirectUri 的 OWIN MVC5

问题描述

使用带有 AAD 模板的 OOTB MVC5,无需任何修改。

我想要做的是在 AAD 的身份验证后将其他自定义声明添加回我的应用程序。配置身份验证:

public void ConfigureAuth(IAppBuilder app)
    {
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        app.UseCookieAuthentication(new CookieAuthenticationOptions()
        {
            AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
        });

        app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                ClientId = clientId,
                Authority = authority,
                RedirectUri = "https://localhost:44336/Account/Signin",
                PostLogoutRedirectUri = postLogoutRedirectUri
            });
    }

在 Azure 门户中,应用程序的回复 URL 也按上述方式输入。应用程序的实际行为是,在 AAD 登录后,重定向只是回到应用程序的根 /,并且没有命中 Account 控制器上的 Signin 操作。

任何想法为什么?我错过了什么?

标签: asp.net-mvcasp.net-mvc-5azure-active-directoryowin

解决方案


  1. 您是否还有设置了回复 url/redirecturi 的 web.config 或 appsettings.json?如果是这样,请确保它也在那里匹配。
  2. 您是仅在本地工作还是这是一个已发布的应用程序?确保您在应用注册和配置中也包含已发布的应用 URL。还要确保这些都是 https 而不是 http(看起来很明显但很容易错过)。
  3. 确保正确列出您的主页 URL。
  4. 如果没有看到您的帐户控制器,很难诊断这一点。你能在这里提供这个吗?

如果您还没有,请查看此存储库。它详细描述了如何完成您想要实现的目标。

另请查看此Youtube 教程


推荐阅读