Authentication and Authorisation

who you are   ===  》what you are allowed to do

https://andrewlock.net/introduction-to-authentication-with-asp-net-core/

The difference between Authentication and Authorisation

First of all, we should clarify the difference between these two dependent facets of security. The simple answer is that Authentication is the process of determining who you are, while Authorisation revolves around what you are allowed to do, i.e. permissions. Obviously before you can determine what a user is allowed to do, you need to know who they are, so when authorisation is required, you must also first authenticate the user in some way.

 

https://www.cnblogs.com/dudu/p/6367303.html

 

 驾照中的“身份证号码:xxx”是一个claim,“姓名:xxx”是另一个claim。

一组claims构成了一个identity,具有这些claims的identity就是 ClaimsIdentity ,驾照就是一种ClaimsIdentity,可以把ClaimsIdentity理解为“证件”,驾照是一种证件,护照也是一种证件。

ClaimsIdentity的持有者就是 ClaimsPrincipal ,一个ClaimsPrincipal可以持有多个ClaimsIdentity,就比如一个人既持有驾照,又持有护照。

 

var claimsIdentity = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, loginName) }, "Basic");
var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);
await context.Authentication.SignInAsync(_cookieAuthOptions.AuthenticationScheme, claimsPrincipal);

用Cookie代表一个通过验证的主体,必须包含Claim, ClaimsIdentity, ClaimsPrincipal这三个信息,以一个持有合法驾照的人做比方,ClaimsPrincipal就是持有证件的人,ClaimsIdentity就是证件,"Basic"就是证件类型(这里假设是驾照),Claim就是驾照中的信息。 

 

 

 

 

 

https://www.cnblogs.com/savorboard/p/aspnetcore-identity.html

public class Claim { public string ClaimType { get; set; } public string ClaimValue { get; set; } }、

# 1: Claims

ClaimType 就是Key,ClaimValue就代表一个Value。这样的话,刚好可以存储一个键值对。这时候姓名:奥巴马是不是可以存进去了

# 2: ClaimsIdentity

在有了“证件单元”之后,我们就用它可以制造一张身份证了,那么应该怎么样制造呢?有些同学可能已经想到了,对,就是新建一个对象,然后在构造函数里面把身份证单元传输进去,然后就得到一张身份证了。我们给这张身份证取一个英文名字叫 “ClaimsIdentity”,这个名字看起来还蛮符合的,既有 Claims 表示其组成部分,又有表示其用途的 Identity(身份),很满意的一个名字。

 

# 3: ClaimsPrincipal

有了身份证,我们就能证明我就是我了,有些时候一个人有很多张身份证,你猜这个人是干嘛的? 对,不是黄牛就是诈骗犯。

但是,有些时候一个人还有其他很多种身份,你猜这个人是干嘛的?这就很正常了对不对,比如你可以同时是一名教师,母亲,商人。如果你想证明你同时有这几种身份的时候,你可能需要出示教师证,你孩子的出生证,法人代表的营业执照证。

在程序中,一个身份证不仅仅代表你这个人了,而是代表一个身份,是证明你自己的主要身份哦。如果一个人还有其他很多种身份,这个时候就需要有一个东西(载体)来携带着这些证件了对吧?OK,我们给需要携带证件的这个对象取一个贴切点的名字,叫“证件当事人(ClaimsPrincipal)”吧。

首先我们在app这边有一些证件单元,然后调用ClaimsIdentity把证件单元初始化为一个身份证,然后再把身份证交给证件当事人由其保管

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值