Claims Identity
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SecurityDemo
{
class Program
{
static void Main(string[] args)
{
Setup();
CheckCompatibility();
CheckNewClaimsUsage();
Console.ReadLine();
}
private static void Setup()
{
IList<Claim> claimCollection = new List<Claim>
{
new Claim(ClaimTypes.Name, "Andras")
, new Claim(ClaimTypes.Country, "Sweden")
, new Claim(ClaimTypes.Gender, "M")
, new Claim(ClaimTypes.Surname, "Nemes")
, new Claim(ClaimTypes.Email, "hello@me.com")
, new Claim(ClaimTypes.Role, "IT")
};
ClaimsIdentity claimsIdentity =new ClaimsIdentity(claimCollection, "My e-commerce website");
Console.WriteLine(claimsIdentity.IsAuthenticated);
ClaimsPrincipal principal = new ClaimsPrincipal(claimsIdentity);
Thread.CurrentPrincipal = principal;
}
private static void CheckCompatibility()
{
IPrincipal currentPrincipal = Thread.CurrentPrincipal;
Console.WriteLine(currentPrincipal.Identity.Name);
}
private static void CheckNewClaimsUsage()
{
ClaimsPrincipal currentClaimsPrincipal = ClaimsPrincipal.Current;//Thread.CurrentPrincipal as ClaimsPrincipal;
Claim nameClaim = currentClaimsPrincipal.FindFirst(ClaimTypes.Name);
Console.WriteLine(nameClaim.Value);
foreach (ClaimsIdentity ci in currentClaimsPrincipal.Identities)
{
Console.WriteLine(ci.Name);
}
}
}
}
Claims Identity的更多相关文章
- 全新的membership框架Asp.net Identity(2)——绕不过的Claims
本来想直接就开始介绍Identity的部分,奈何自己挖坑太深,高举高打的方法不行.只能自己默默下载了Katana的源代码研究了好一段时间.发现要想能够理解好用好Identity, Claims是一个绕 ...
- Identity Server 4 - Hybrid Flow - Claims
前一篇 Identity Server 4 - Hybrid Flow - MVC客户端身份验证: https://www.cnblogs.com/cgzl/p/9253667.html Claims ...
- AspNet Identity 和 Owin 谁是谁
英文原文:http://tech.trailmax.info/2014/08/aspnet-identity-and-owin-who-is-who/ 最近我发现Stackoverflow上有一个非常 ...
- 译:Asp.Net Identity与Owin,到底谁是谁?
送给正在学习Asp.Net Identity的你 :-) 原文出自 trailmax 的博客AspNet Identity and Owin. Who is who. Recently I have ...
- Identity Server 4 - Hybrid Flow - MVC客户端身份验证
预备知识 可能需要看一点点预备知识 OAuth 2.0 不完全简介: https://www.cnblogs.com/cgzl/p/9221488.html OpenID Connect 不完全简介: ...
- Web API2 使用默认Identity
当您选择个人账户在Web API项目模板,项目包含一个令牌授权服务器验证用户凭证和问题.下面的图显示了相同的凭证流的Web API组件. 发送一个未经授权的请求 首先,运行应用程序并单击按钮调用的AP ...
- 【译】Asp.Net Identity与Owin,到底谁是谁?
送给正在学习Asp.Net Identity的你 :-) 原文出自 trailmax 的博客AspNet Identity and Owin. Who is who. Recently I have ...
- SharePoint Adventures : Using Claims with Reporting Services
Cannot convert claims identity to a windows token. This may be due to user not logging in using win ...
- DotNet 资源大全中文版(Awesome最新版)
Awesome系列的.Net资源整理.awesome-dotnet是由quozd发起和维护.内容包括:编译器.压缩.应用框架.应用模板.加密.数据库.反编译.IDE.日志.风格指南等. 算法与数据结构 ...
随机推荐
- Box2D淌坑日记: 关节(Joint)和旋转关节(b2RevoluteJoint)
关节在Box2D的对象组织结构中,与b2Body(刚体)并列.因此两种对象都是由b2World创建并直接管理. 然而Joint有依赖于b2Body的地方,就是它的销毁:当关节所涉及到的刚体被销毁,关节 ...
- mysql查询结果添加编号
第一种方法: select (@i:=@i+1) as i,table_name.* from table_name,(select @i:=0) as it 第二种方 ...
- 序列化(Serialization)据为JSONP远端请求
Insus.NET前些日子,有分享了一段代码,<使用JSONP跨域请求数据>http://www.cnblogs.com/insus/p/3512271.html 是使用jQuery的Da ...
- Linux Shell编程基础
在学习Linux BASH Shell编程的过程中,发现由于不经常用,所以很多东西很容易忘记,所以写篇文章来记录一下 ls 显示当前路径下的文件,常用的有 -l 显示长格式 -a 显示所有包括隐 ...
- LeetCode 3Sum Smaller
原题链接在这里:https://leetcode.com/problems/3sum-smaller/ 题目: Given an array of n integers nums and a targ ...
- 安卓和ios的lineheight的不一样如何解决?
lineheight在pc端上显示很正常,但是在手机就很不同,在iphone6上,设置了lineheight,但是文本上面多了几像素,如果你设置lineheight在35px一下的按钮(用span做的 ...
- github 或者gitlab 设置添加SSH, 避免每次提交重复输入用户名
克隆项目二种方式: 1. 使用https url克隆, 复制https url 然后到 git clone https-url 2.使用 SSH url 克隆却需要在克隆之前先配置和添加好 SSH ...
- ubuntu 常用命令集合版(二)【大侠勿喷,菜鸟欢迎】(转)
原文:http://page.renren.com/600759338/note/729595757 1.shutdown: 关闭系统,如果停留在TTY,请改用halt, poweroff等命令常用参 ...
- .net 直接输出远程文件到浏览器和下载文件保存到本机
利用了xmlhttp,实现代码比较简单具体实现如下: 首先bin文件引入,com->microsoft xml v3.0 具体代码如下: protected void Button1_Click ...
- sqlyong64位破解
姓名(Name):cr173 序列号(Code):8d8120df-a5c3-4989-8f47-5afc79c56e7c 或者(OR) 姓名(Name):cr173 序列号(Code):59adfd ...