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

asp.net core 3.0 身份认证 替换为自已的提供程序 AuthenticationStateProvider replace to SelfAuthenticationStateProvider的更多相关文章

  1. asp.net core 2.0的认证和授权

    在asp.net core中,微软提供了基于认证(Authentication)和授权(Authorization)的方式,来实现权限管理的,本篇博文,介绍基于固定角色的权限管理和自定义角色权限管理, ...

  2. 【转载】asp.net core 2.0的认证和授权

    在asp.net core中,微软提供了基于认证(Authentication)和授权(Authorization)的方式,来实现权限管理的,本篇博文,介绍基于固定角色的权限管理和自定义角色权限管理, ...

  3. ASP.NET Core 2.0身份和角色管理入门

    见  https://blog.csdn.net/mzl87/article/details/84892916 https://www.codeproject.com/Articles/1235077 ...

  4. ASP.NET Core 6.0 添加 JWT 认证和授权

    序言 本文将分别介绍 Authentication(认证) 和 Authorization(授权). 并以简单的例子在 ASP.NET Core 6.0 的 WebAPI 中分别实现这两个功能. 相关 ...

  5. ASP.NET Core 1.0 静态文件、路由、自定义中间件、身份验证简介

    概述 ASP.NET Core 1.0是ASP.NET的一个重要的重新设计. 例如,在ASP.NET Core中,使用Middleware编写请求管道. ASP.NET Core中间件对HttpCon ...

  6. Asp.Net Core 3.0的依赖注入改变

    Asp.Net Core 3.0出来很久了,预览版的时候就被我偶像Lemon大人,带着尝试摸索了一下这个 那么Asp.Net Core 3.0和Asp.Net Core 2.X到底有哪些区别呢? As ...

  7. 探索ASP.Net Core 3.0系列六:ASP.NET Core 3.0新特性启动信息中的结构化日志

    前言:在本文中,我将聊聊在ASP.NET Core 3.0中细小的变化——启动时记录消息的方式进行小的更改. 现在,ASP.NET Core不再将消息直接记录到控制台,而是正确使用了logging 基 ...

  8. ASP.NET Core 3.0 gRPC 身份认证和授权

    一.开头聊骚 本文算是对于 ASP.NET Core 3.0 gRPC 研究性学习的最后一篇了,以后在实际使用中,可能会发一些经验之文.本文主要讲 ASP.NET Core 本身的认证授权和gRPC接 ...

  9. Asp.Net Core 2.0 项目实战(10) 基于cookie登录授权认证并实现前台会员、后台管理员同时登录

    1.登录的实现 登录功能实现起来有哪些常用的方式,大家首先想到的肯定是cookie或session或cookie+session,当然还有其他模式,今天主要探讨一下在Asp.net core 2.0下 ...

随机推荐

  1. 基本认证(Basic Authorization)

    ---------------------------------- import arcpy from base64 import encodestring username = 'xxx' pas ...

  2. jakarta-oro-2.0.8.jar-----------JAVA FTP相关

    资源不好找,找到了就和大家分享一下! 链接:https://share.weiyun.com/51kBB0y 密码:2hcxcu

  3. Filco圣手二代双模蓝牙机械键盘连接方法

    转自:https://www.cnblogs.com/goldenSky/p/11437780.html 常规方法 确认键盘的电源接通. 同时按下「Ctrl」+「Alt」+「Fn」执行装置切换模式.配 ...

  4. memory一致性模型

    https://homes.cs.washington.edu/~bornholt/post/memory-models.html https://www.cs.cmu.edu/afs/cs/acad ...

  5. SqlServer数据库优化之添加主键和自增长

    今天需要给有500万条数据的表添加主键和自增长列,其中最大的难度在于如何UPDATE这500万多条数据,开始吧! 1.先给表添加一个字段叫ID,并允许空 2.查询表,我想到了使用其中的时间列排序来创建 ...

  6. Windows下硬盘存储情况可视化工具--WinDirStat

    WinDirStat是一款免费的用于Windows下硬盘空间可视化工具. 下载地址:https://windirstat.en.softonic.com/ 界面如图所示: 可以轻易看出硬盘空间使用情况 ...

  7. angular6 表单验证

    这里使用的是模型驱动的表单 1.app.module.ts import { ReactiveFormsModule } from '@angular/forms'; @NgModule({ ... ...

  8. Linux 初识Libevent网络库

    初识Libevent libevent是用c写的高并发网络io库,只要有文件描述符,就都可使用libevent. libevent使用回调函数(callback) . 有了libevent,网络编程我 ...

  9. Linux下经常使用的C/C++开源Socket库【转】

    转自:https://www.cnblogs.com/gccbuaa/p/7015599.html 1.      Linux Socket Programming In C++ : http://t ...

  10. Centos 7 修改网卡名称、静态IP

    修改内核选项 # vim /etc/sysconfig/grub GRUB_TIMEOUT= GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc ...