76 lines
No EOL
2.1 KiB
Text
76 lines
No EOL
2.1 KiB
Text
@using System.Security.Claims
|
|
@using Microsoft.AspNetCore.Components.Authorization
|
|
@inject AuthenticationStateProvider AuthenticationStateProvider
|
|
@inherits LayoutComponentBase
|
|
|
|
<PageTitle>Lieb</PageTitle>
|
|
|
|
<div class="page">
|
|
<div class="sidebar">
|
|
<NavMenu />
|
|
</div>
|
|
|
|
<main>
|
|
<div class="top-row px-4">
|
|
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
|
|
<AuthorizeView>
|
|
<Authorized>
|
|
<a href="#">Hello, @context.User.Identity.Name!</a>
|
|
<a href="Account/Logout">Log out</a>
|
|
</Authorized>
|
|
<NotAuthorized>
|
|
<a href="Account/Login">Log in</a>
|
|
</NotAuthorized>
|
|
</AuthorizeView>
|
|
</div>
|
|
<AuthorizeView>
|
|
<p>You can only see this if you are loged in</p>
|
|
</AuthorizeView>
|
|
<AuthorizeView Policy="Admin">
|
|
<p>You can only see this if you satisfy the "Admin" policy.</p>
|
|
</AuthorizeView>
|
|
|
|
|
|
<article class="content px-4">
|
|
@Body
|
|
</article>
|
|
<button @onclick="GetClaimsPrincipalData">Get ClaimsPrincipal Data</button>
|
|
</main>
|
|
</div>
|
|
<p>@_authMessage</p>
|
|
|
|
@if (_claims.Count() > 0)
|
|
{
|
|
<ul>
|
|
@foreach (var claim in _claims)
|
|
{
|
|
<li>@claim.Type: @claim.Value</li>
|
|
}
|
|
</ul>
|
|
}
|
|
|
|
<p>@_surnameMessage</p>
|
|
|
|
@code {
|
|
private string _authMessage;
|
|
private string _surnameMessage;
|
|
private IEnumerable<Claim> _claims = Enumerable.Empty<Claim>();
|
|
|
|
private async Task GetClaimsPrincipalData()
|
|
{
|
|
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
|
var user = authState.User;
|
|
|
|
if (user.Identity.IsAuthenticated)
|
|
{
|
|
_authMessage = $"{user.Identity.Name} is authenticated.";
|
|
_claims = user.Claims;
|
|
_surnameMessage =
|
|
$"Surname: {user.FindFirst(c => c.Type == ClaimTypes.Surname)?.Value}";
|
|
}
|
|
else
|
|
{
|
|
_authMessage = "The user is NOT authenticated.";
|
|
}
|
|
}
|
|
} |