I’m setting up a single-tenant authentication on Azure AD, but after I click on the login button, I’m sent to an empty page saying "Sorry, there’s nothing at this address".
If I try a multi-tenant application, I can login correctly, but I want this to be available only to users in the company
I’m using a test tenant, and here goes the code related:
appsettings.json:
"Microsoft": {
"AppId": "30582132-28cc-#################",
"AppSecret": "Pbl8Q~mSnfXx.####################",
"TenantId": "5d01008c-86dc-####################"
}
Program.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>
LoginController:
[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("/");
}
}
The error message comes from 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>
2
Answers
Change the path in the portal to:
Your problem is this line
That needs to be a url for single tenant.