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));
}
}
}

最新文章

  1. flask+sqlite3+echarts2+ajax数据可视化报错:UnicodeDecodeError: &#39;utf8&#39; codec can&#39;t decode byte解决方法
  2. 实现滑动可固定header以及页面刷新
  3. 利用IIS管理器模拟CDN
  4. testng xml中按顺序执行java类
  5. Android WebView加载本地html并实现Java与JS交互
  6. 使用MulticastSocket实现多点广播
  7. 树莓派3 安装ubuntu-mate
  8. isIsomorphic
  9. [iOS基础控件 - 6.11.1] - 控制器 &amp; 控制器view
  10. xenserver 备份backup和还原restore命令
  11. laravel5的坑
  12. QTableView表格滚动条样式(QSS真是细致到家了)
  13. #翻译#原文来自Database.System.Concepts(6th.Edition.2010)2.6Relational Operations,原文作者Abraham Silberschaz , Henry F. Korth , S. Sudarshan
  14. Elastic 之倒排索引(二)
  15. boostrap 日期插件(带中文显示)
  16. 排序算法&lt;No.4&gt;【基数排序】
  17. [BZOJ2834]回家的路
  18. supervisor安装与问题
  19. 使用AngularJS 添加行修改、删除表格数据
  20. Java并发多线程 - 并发工具类JUC

热门文章

  1. 在Linux系统中运行并简单的测试RabbitMq容器
  2. C#中使用WCF创建面向网络的服务程序
  3. WPF 基础总结(学习建议)
  4. React用脚手架实际开发项目!
  5. 实验6:Mapreduce实例——WordCount
  6. Laravel 创建指定表 migrate
  7. Vue 拖拽组件 vuedraggable 和 vue-dragging
  8. 深入java8的集合:ArrayList的实现原理
  9. Android源码分析(一)-----如何快速掌握Android编译文件
  10. 爬虫---Beautiful Soup 反反爬虫事例