/
qwiklly
/
arc-server
Обзор
Документация
Войти
/
qwiklly
/
arc-server
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
src/AppRemoteConfig/Services/CustomAuthStateProvider.cs
48 строк
2 KB
CLTanuki
feat(#3, #7): scope, based on current user
10 янв 2024, 18:20
10 янв 2024, 18:20
0019562
Код
Авторство
О чём код?
// namespace AppRemoteConfig.Services // { // using System.Security.Claims; // using AppRemoteConfig.Models.Database; // using Microsoft.AspNetCore.Components.Authorization; // // public class CustomAuthStateProvider : AuthenticationStateProvider // { // private ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity()); // private readonly IHttpClientFactory _httpClientFactory; // private AppUser? _userProfileDto; // public CustomAuthStateProvider(IHttpClientFactory httpClientFactory) // { // _httpClientFactory = httpClientFactory; // } // // public override async Task<AuthenticationState> GetAuthenticationStateAsync() // { // if(_userProfileDto == null) // { // var client = _httpClientFactory.CreateClient // ("BlazorWasmAppCookieAuth.ServerAPI"); // var response = await client.GetAsync("/api/Auth/user-profile"); // if (response.IsSuccessStatusCode) // { // _userProfileDto = // await response.Content.ReadFromJsonAsync<UserProfileDto>(); // var identity = new ClaimsIdentity(new[]{ // new Claim(ClaimTypes.Email, _userProfileDto?.Email ?? ""), // new Claim(ClaimTypes.Name, _userProfileDto ?.Name ?? ""), // new Claim("UserId", _userProfileDto?.ToString() ?? "") // }, "AuthCookie"); // // claimsPrincipal = new ClaimsPrincipal(identity); // //NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); // } // } // return new AuthenticationState(claimsPrincipal); // } // // public void SignOut() // { // _userProfileDto = null; // claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity()); // NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); // } // } // }