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.日志.风格指南等. 算法与数据结构 ...
随机推荐
- mybatis 分页
http://www.cnblogs.com/xiaoxinwt/p/5329840.html
- [archlinux][hardware] 查看SSD的使用寿命
因为最近把16GB的SSD做成了HDD的cache,所以比较关系寿命问题. 使用smartctl工具. 参考:https://www.v2ex.com/t/261373 linux 下面只有 smar ...
- JS中的事件冒泡(Bubble)和事件捕获(capture)以及如何阻止事件的冒泡
对“捕获”和“冒泡”这两个概念,通常我们对冒泡了解和使用的会更多一些,因为在我们使用的所有浏览器中,都支持事件冒泡 ,即事件由子元素向祖先元素传播的,就 像气泡从水底向水面上浮一样.而在像firefo ...
- sdk 更新的时连接不上dl-ssl.google.com解决办法
今天有朋友说sdk的更新不了,借了个VPN给他也没解决问题,后来还是他自己解决了,下面分享下经验 这里介绍一种不需要FQ的解决办法,修改C:\Windows\System32\drivers\etc下 ...
- C语言 ---- 循环分支 iOS学习-----细碎知识点总结
#import <Foundation/Foundation.h> // #import是OC种的导入头文件或者是系统框架的指令 // 定义了一个Season枚举类型enum Seaso ...
- Jmeter工作原理
- ERROR 1010 (HY000): Error dropping database (can't rmdir '.\qpweb', errno: 41) 删库失败问题的解决
Win8 下,MySQL5.5,root 用户登录 MySQL 5.5 Command Line Client,删除 qpweb 数据,执行命令 drop database qpweb;报错信息:ER ...
- 一种构造WEB服务器端recv和send接口阻塞现象的方法
send阻塞 socket recv send接口阻塞,会导致服务器端不在响应客户端任何请求,所以一般情况, 会将socket设置为非阻塞状态, 但是有些场景,例如ssl_accept就需要使用阻塞的 ...
- lua MVC框架 Orbit初探
介绍 http://keplerproject.github.io/orbit/ Orbit是lua语言版本的MVC框架. 此框架完全抛弃CGILUA的脚本模型, 支持的应用, 每个应用可以卸载一个单 ...
- R&&rstudio
R sudo apt-get install R-base Rstudio()下载Rstudio桌面版失败 sudo apt-get install gdebi-core 如果提示少了什么东西,运行下 ...