azure - Blazor + Azure AD 身份验证 : Single Tenant login giving "Sorry, there' s nothing at this address"

标签 azure authentication azure-active-directory blazor

我正在 Azure AD 上设置单租户身份验证,但在单击登录按钮后,我被发送到一个空页面,显示“抱歉,此地址没有任何内容”。

如果我尝试 Multi-Tenancy 应用程序,我可以正确登录,但我希望该应用程序仅对公司中的用户可用

我正在使用测试租户,以下是相关代码:

appsettings.json:

  "Microsoft": {
    "AppId": "30582132-28cc-#################", 
    "AppSecret": "Pbl8Q~mSnfXx.####################",
    "TenantId": "5d01008c-86dc-####################" 
  }

程序.cs:

builder.Services.AddAuthentication("Cookies")
    .AddCookie(opt =>
    {
        opt.Cookie.Name = "AuthCookie";
    })
    .AddMicrosoftAccount(opt =>
    {
        opt.SignInScheme = "Cookies";
        opt.ClientId = builder.Configuration["Microsoft:AppId"];
        opt.ClientSecret = builder.Configuration["Microsoft:AppSecret"];
        opt.AuthorizationEndpoint = builder.Configuration["Microsoft:TenantId"];
    });

MainLayout.razor:

@layout TelerikLayout
@inherits LayoutComponentBase
@using System.Security.Claims

<PageTitle>Marker.Web</PageTitle>

<div class="page">
    <main>
        <AuthorizeView>
            <Authorized>
                @context.User.FindFirst(ClaimTypes.Name).Value
                <a class="btn btn-danger" href="login/logout">Logout</a>
            </Authorized>
            <NotAuthorized>
                <a class="btn btn-success" href="login/microsoft?RedirectUri=/">Login</a>
            </NotAuthorized>
        </AuthorizeView>
        <article>
            @Body
        </article>
    </main>
</div>

登录 Controller :

    [Route("/[controller]")]
    [ApiController]
    public class LoginController : ControllerBase
    {
        [HttpGet("microsoft")]
        public async Task<ActionResult> Login(string RedirectUri)
        {
            var props = new AuthenticationProperties
            {
                RedirectUri = RedirectUri
            };
            return Challenge(props, MicrosoftAccountDefaults.AuthenticationScheme);
        }

        [HttpGet("logout")]
        public async Task<ActionResult> Logout()
        {
            await HttpContext.SignOutAsync();
            return Redirect("/");
        }
    }

错误消息来自App.razor:

<CascadingAuthenticationState>
    <Router AppAssembly="@typeof(Program).Assembly">
        <Found Context="routeData">
            <AuthorizeRouteView RouteData="@routeData" 
                DefaultLayout="@typeof(MainLayout)" />
        </Found>
        <NotFound>
            <LayoutView Layout="@typeof(MainLayout)">
                <p>Sorry, there's nothing at this address.</p>
            </LayoutView>
        </NotFound>
    </Router>
</CascadingAuthenticationState>

On Azure this is the RedirectUri

Single-tenant setting

最佳答案

将门户中的路径更改为:

https://localhost:7011/authentication/login-callback

关于azure - Blazor + Azure AD 身份验证 : Single Tenant login giving "Sorry, there' s nothing at this address",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72521570/

相关文章:

javascript - Next.js:如何访问localStorage?

angularjs - 从 WAAD 获取用户组的最简单方法是什么?

azure-sql-database - 用户 'NT AUTHORITY\ANONYMOUS LOGIN' 登录失败错误 18456 Azure Sql

azure - 我们可以将用户的照片从 AzureAD 同步到 AD DS 吗?

html - 需要帮助将字体从 Azure 加载到网页中

azure - 如何在 Azure 应用程序见解中执行明确的声明?

AppFabric 缓存的 Java 客户端?

asp.net-mvc - Controller Action 多次击中-在Azure模拟器中运行的ASP.NET MVC 4应用

java - Android NTLM 获取 HTTP/1.1 401 未经授权

REST API 通过 SSL 的 HTTP 基本身份验证