zoukankan      html  css  js  c++  java
  • asp.net core 3.0 身份认证 替换为自已的提供程序 AuthenticationStateProvider replace to SelfAuthenticationStateProvider

            public void ConfigureServices(IServiceCollection services)
            {
                // 添加身份验证服务
                services.AddAuthorizationCore();
                services.AddScoped<AuthenticationStateProvider, ServerAuthenticationStateProvider>();
            }
    using BlazorDemo.Shared;
    using Microsoft.AspNetCore.Components;
    using Microsoft.AspNetCore.Components.Authorization;
    using System.Net.Http;
    using System.Security.Claims;
    using System.Threading.Tasks;
    
    namespace BlazorDemo.Client
    {
        public class SelfAuthenticationStateProvider : AuthenticationStateProvider
        {
            private readonly HttpClient _httpClient;
    
            public SelfAuthenticationStateProvider(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) }, "selfauth")
                    : new ClaimsIdentity();
    
                return new AuthenticationState(new ClaimsPrincipal(identity));
            }
        }
    }
  • 相关阅读:
    flask之闪现
    对于Flask中蓝图的理解
    flask中的CBV和FBV
    Flask之基本使用与配置
    Flask
    Flask-信号(blinker)
    flask-migrate
    Flask WTForms的使用和源码分析 —— (7)
    mac下卸载jdk
    RabbitMQ五种消息队列学习(三)–Work模式
  • 原文地址:https://www.cnblogs.com/webenh/p/11644692.html
Copyright © 2011-2022 走看看