Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/illinker-test-assets.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'wasm/BlazingPizza.Client/ServerAuthenticationStateProvider.cs')
-rw-r--r--wasm/BlazingPizza.Client/ServerAuthenticationStateProvider.cs28
1 files changed, 28 insertions, 0 deletions
diff --git a/wasm/BlazingPizza.Client/ServerAuthenticationStateProvider.cs b/wasm/BlazingPizza.Client/ServerAuthenticationStateProvider.cs
new file mode 100644
index 0000000..9a94bc5
--- /dev/null
+++ b/wasm/BlazingPizza.Client/ServerAuthenticationStateProvider.cs
@@ -0,0 +1,28 @@
+using System.Net.Http;
+using System.Security.Claims;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Components;
+
+namespace BlazingPizza.Client
+{
+ public class ServerAuthenticationStateProvider : AuthenticationStateProvider
+ {
+ private readonly HttpClient _httpClient;
+
+ public ServerAuthenticationStateProvider(HttpClient httpClient)
+ {
+ _httpClient = httpClient;
+ }
+
+ public override async Task<AuthenticationState> GetAuthenticationStateAsync()
+ {
+ var userInfo = await _httpClient.GetJsonAsync<UserInfo>("user");
+
+ var identity = userInfo.IsAuthenticated
+ ? new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, userInfo.Name) }, "serverauth")
+ : new ClaimsIdentity();
+
+ return new AuthenticationState(new ClaimsPrincipal(identity));
+ }
+ }
+}