Last active
May 27, 2020 11:38
-
-
Save mattruma/8de8614d008e1a4a4583e0c778c36d8a to your computer and use it in GitHub Desktop.
mattruma.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@page "/profile" | |
@using System.Security.Claims | |
@using Microsoft.AspNetCore.Components.Authorization | |
<section class="mb-4"> | |
<h1 class="mb-4">Authorize View Component</h1> | |
<AuthorizeView> | |
<Authorized> | |
<h2 class="mb-4">Hello, @context.User.Identity.Name!</h2> | |
<table class="table"> | |
<thead> | |
<tr> | |
<th>Key</th> | |
<th>Value</th> | |
</tr> | |
</thead> | |
<tbody> | |
@foreach (var claim in context.User.Claims) | |
{ | |
<tr> | |
<td>@claim.Type</td> | |
<td>@claim.Value</td> | |
</tr> | |
} | |
</tbody> | |
</table> | |
</Authorized> | |
</AuthorizeView> | |
</section> | |
<section class="mb-4"> | |
<h1 class="mb-4">Authentication State</h1> | |
<h2 class="mb-4">Hello, @this.AuthenticationStateUser.Identity.Name!</h2> | |
<table class="table"> | |
<thead> | |
<tr> | |
<th>Key</th> | |
<th>Value</th> | |
</tr> | |
</thead> | |
<tbody> | |
@foreach (var claim in this.AuthenticationStateUser.Claims) | |
{ | |
<tr> | |
<td>@claim.Type</td> | |
<td>@claim.Value</td> | |
</tr> | |
} | |
</tbody> | |
</table> | |
</section> | |
@inject AuthenticationStateProvider AuthenticationStateProvider | |
<section class="mb-4"> | |
<h1 class="mb-4">Authentication State Provider</h1> | |
<h2 class="mb-4">Hello, @this.AuthenticationStateProviderUser.Identity.Name!</h2> | |
<table class="table"> | |
<thead> | |
<tr> | |
<th>Key</th> | |
<th>Value</th> | |
</tr> | |
</thead> | |
<tbody> | |
@foreach (var claim in this.AuthenticationStateProviderUser.Claims) | |
{ | |
<tr> | |
<td>@claim.Type</td> | |
<td>@claim.Value</td> | |
</tr> | |
} | |
</tbody> | |
</table> | |
</section> | |
@code { | |
[CascadingParameter] | |
private Task<AuthenticationState> authenticationStateTask { get; set; } | |
private ClaimsPrincipal AuthenticationStateUser { get; set; } | |
private ClaimsPrincipal AuthenticationStateProviderUser { get; set; } | |
protected override async Task OnParametersSetAsync() | |
{ | |
AuthenticationState authenticationState; | |
authenticationState = await authenticationStateTask; | |
this.AuthenticationStateUser = authenticationState.User; | |
authenticationState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); | |
this.AuthenticationStateProviderUser = authenticationState.User; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment