gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:00:08 26 4
gpt4 key购买 nike

我正在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com