我正在玩4.5中的新东西并写了一个简单的控制台应用程序,它应该检查基于新索赔的安全模型中的一些东西.我创建了ClaimsAuthorizationManager和ClaimsAuthenticationManager的自定义实现,将它们添加到应用程序配置文件,将AppDomain主体策略设置为Windows主体,除了调用AuthenticationManager.Authenticate方法之外,几乎每个都可以正常工作.
正在按预期调用AuthorizationManager.CheckAccess.
我想这是正确的行为,因为当运行控制台应用程序时,用户已经过身份验证,并且无需在应用启动时执行此操作.但是我想基于改变一些声明 - 让我们说存储在数据库中的配置文件.当然我可以手动完成并自己处理CurrentPrinciapal对象.但是我想知道是否有办法迫使应用程序使用AuthManager为我做这件事.
只是好奇:)
所以,这里有两位经理.他们基本上什么都不做,只是为了设置断点而存在:)
public class AuthorizationManager : ClaimsAuthorizationManager
{
public override bool CheckAccess(AuthorizationContext context)
{
return base.CheckAccess(context);
}
}
public class Authenticationmanager : ClaimsAuthenticationManager
{
public override ClaimsPrincipal Authenticate(string resourceName, ClaimsPrincipal incomingPrincipal)
{
return base.Authenticate(resourceName, incomingPrincipal);
}
}
Run Code Online (Sandbox Code Playgroud)
App.config看起来像这样:
<configuration>
<configSections>
<section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.identityModel>
<identityConfiguration>
<claimsAuthenticationManager type="ClaimsSandbox.Authenticationmanager, ClaimsSandbox"/>
<claimsAuthorizationManager type="ClaimsSandbox.AuthorizationManager, ClaimsSandbox"/>
</identityConfiguration>
</system.identityModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
并没有什么特别的代码: …
我正在玩JwtTokens并且无法使它们正常工作.我正在使用http://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/.我知道代码是乱七八糟的,但只是为了展示我正在尝试做的事情.问题是我希望JwtTokenHandler因为生命周期而无法通过验证.
var key = "5A0AB091-3F84-4EC4-B227-0834FCD8B1B4";
var domain = "http://localhost";
var allowedAudience = "http://localhost";
var signatureAlgorithm = "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256";
var digestAlgorithm = "http://www.w3.org/2001/04/xmlenc#sha256";
var issuer = "self";
var securityKey = System.Text.Encoding.Unicode.GetBytes(key);
var inMemorySymmetricSecurityKey = new InMemorySymmetricSecurityKey(securityKey);
var now = DateTime.UtcNow;
var expiry = now.AddSeconds(1);
var tokenHandler = new JwtSecurityTokenHandler();
var claimsList = new List<Claim>()
{
new Claim(ClaimTypes.Name, "user"),
new Claim(ClaimTypes.Webpage, allowedAudience),
new Claim(ClaimTypes.Uri, domain),
new Claim(ClaimTypes.Expiration,expiry.Ticks.ToString())
};
var roles = new List<string>() { "admin" };
claimsList.AddRange(roles.Select(role => new Claim(ClaimTypes.Role, role))); …
Run Code Online (Sandbox Code Playgroud) 我在使用.Net MVC 5 app配置ADFS时遇到问题.
我已经在VS 2015中配置我的项目以使用声明并且它工作正常,但我有一个问题.
我可以登录,使用ADFS,我可以检查用户角色等.当我尝试使用时出现问题
[Authorize(Roles="somenonExistingRole")]
Run Code Online (Sandbox Code Playgroud)
尽管我已经通过身份验证,但是当重新进行身份验证时,我被重定向到ADFS页面,并且我被重定向到我的页面,其中发生了循环.页面将我发送到ADFS门户,ADFS将我重定向到门户网站,并在几次尝试后从ADFS(到许多请求)收到错误
我是否必须自己实施角色提供程序?或者我需要配置额外的东西.也许我可以限制尝试次数?当我的角色已经完成时,为什么我会被重定向到ADFS?
在代码中没有多少显示实际,按要求:我测试的控制器:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[Authorize]
public ActionResult About()
{
var u = HttpContext.User;
if (u.IsInRole("/"))
{
ViewBag.Message = "User is in role.";
}
else
{
ViewBag.Message = "User is NOT in role.";
}
return View();
}
[Authorize(Roles = "/nonexistingRole")]
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
和配置身份验证部分
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new …
Run Code Online (Sandbox Code Playgroud) 有人使用过Windows Azure Access Control和WPF客户端吗?我喜欢使用Live ID验证Zune客户端.
我需要在我的WPF应用程序中使用Windows Live ID进行身份验证.
我有一个与Windows Azure Acces Control一起使用的网站,我在我的网站中使用Roles的声明,但我需要知道,如果它可能使用WPF应用程序的声明.
我找不到任何关于WPF和Windows Azure Access Control的内容,仅适用于ASP.NET
非常感谢.!
所有,
我一直在阅读基于声明的身份验证,但我仍然有点困惑.我正在努力巩固我的理解,特别是与SharePoint 2010/2013有关,但也通常(即ASP.NET).
我对各种技术术语的理解如下:
WIF(Windows Identity Foundation) - 用于消费身份声明和构建自定义STS等的.NET库(API集).
依赖方 - 索赔的"消费者"(即SharePoint,ASP.NET网站等).索赔是通过STS(仅限IP-STS?)提供的.
STS(安全令牌服务) - 一种发布安全令牌的专用Web服务.有两种口味,有些STS可能同时都有两种口味?
可信身份提供程序(SharePoint术语) - AKA.IP-STS.
SharePoint 2010/2013 STS - 使用WIF开发的SharePoint Service应用程序,仅用作RP-STS.充当许多用户可配置的可信身份提供商(IP-STS)的可插入聚合点.如果需要,可以使用WIF手工构建.
ADFS 2.0 - 专门用于仅针对Active Directory实例联合组织的Windows角色.公开使用WIF构建的IP-STS端点.我对ADFS 2.0的理解是它不允许您"聚合"其他身份提供者 - 它只允许您针对可能不是本地的特定AD实例进行身份验证,因此需要联合以支持SSO .
Windows Azure ACS 2.0 - 专门用于联合任何已配置的第三方身份提供商(即Microsoft帐户,Google,Facebook,ADFS 2.0)的服务.充当其他身份提供商的可插入聚合点,其作用有点像依赖方.公开使用WIF构建的IP-STS端点.它聚合的身份提供商不一定是IP-STS,但ACS 2.0使用其内置的IP-STS通过声明公开所有内容.
SharePoint 2010/2013问题:
我的主要问题是我看过几篇关于ADFS 2.0和SharePoint的文章,几乎就像你用ADFS 2.0 取代内置的SharePoint 2010/2013 STS一样!希望这只是我的阅读,但它让我理解困惑.
2.1.SharePoint STS已经支持AD身份验证作为OOTB可信身份提供程序选项,如果您想使用ADFS 2.0,则可以将其添加为我见过博客帖子的可信身份提供程序(IP-STS).
2.2.根据我对ADFS 2.0的描述,为SharePoint STS更改它实际上会给你一个不太灵活的解决方案吗?
声明:
ASP.NET WIF问题: …
我正在开发一个Asp.NET MVC5 Web应用程序(.NET 4.6),我需要向具有特定声明的一组用户显示一些额外的HTML行.我见过一些冗长的解决方案,但我更喜欢保持简短,所以我想出了这个
@{
if (System.Security.Claims.ClaimsPrincipal.Current.Claims.ToList().FirstOrDefault(c => c.Type == "role" && c.Value == "AwesomeUserRole") != null) {
<!-- my HTML goes here -->
}
}
Run Code Online (Sandbox Code Playgroud)
这是检查经过身份验证的用户声明的好方法,还是有最佳做法可以遵循?任何更清洁/更有效的解决方案也是受欢迎的.
考虑使用访问控制服务(ACS)和Windows Identity Foundation(WIF)来保护我的WCF数据服务Web API应用程序.
如何使用声明来唯一标识用户?
我的想法是使用标准声明NameIdentifier和WIF声明IdentityProvider的组合来为任何用户创建唯一ID.
这个组合真的稳定而独特吗?IP会突然改变它的IdentityProvider字符串吗?
这里的想法是将两半的连接字符串存储为任何用户的唯一ID.
NameIdentifier声明是否有任何安全隐患?
干杯,
M.
我正在开发一个MVC 5互联网应用程序并正在使用Identity 2.1
.
如何claim
在用户登录后向用户添加一个我知道的位置username
?
这是我有的:
public void AddClaimToUser(string userName, string type, string value )
{
var AuthenticationManager = HttpContext.Current.GetOwinContext().Authentication;
var Identity = new ClaimsIdentity(userName);
Identity.AddClaim(new Claim(type, value));
AuthenticationManager.AuthenticationResponseGrant = new AuthenticationResponseGrant(new ClaimsPrincipal(Identity), new AuthenticationProperties { IsPersistent = true });
}
Run Code Online (Sandbox Code Playgroud)
但是,在我调用此方法并检查用户的声明后,claim
未列出添加的内容.
这是我用于在控制器中获取声明的代码:
var identity = (ClaimsIdentity)User.Identity;
IEnumerable<Claim> claims = identity.Claims;
Run Code Online (Sandbox Code Playgroud)
提前致谢.
claims-based-identity claims asp.net-mvc-5 asp.net-identity-2
jwt的私人索赔和公共索赔之间有什么区别?
我对这两种说法之间的区别感到困惑。据我了解,它们都是自定义声明。那么区别是什么呢?
我将声明添加到声明主体身份并让用户登录。在后续请求中,添加的声明可在应用程序中任何位置的声明主体中使用,但只能持续 25 分钟。我没有测试过25到30分钟。30 分钟后,声明主体身份仍经过身份验证,但仅包含来自身份数据库的声明。登录时添加的“CookieClaim”丢失。声明主体身份“IsAuthenticated”仍然是 true,并且导航菜单等中的问候语仍然是“Hi emailaddress”。如果我们在20分钟内提出请求也没关系。
我希望只要用户登录,这些声明就可用。
该应用程序使用 OAuth 从多个外部提供商获取用户的访问令牌和其他信息,该信息用于整个应用程序的授权。我选择将声明中的信息放入cookie中,因为它可能会定期更改,并且不适合存储在Identity数据库中。
以下代码来自我用来演示的 asp.net core 2.2 应用程序的支架 LoginModel。它与我的主应用程序不完全相同,但添加了声明,输入“CookieClaim”并使用相同的方法登录。从“IdentityUser user...”开始的四行实际上是我对模板 asp.net core Web 应用程序所做的唯一更改(使用本地用户帐户,在搭建“登录”页面之后)
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
{
returnUrl = returnUrl ?? Url.Content("~/");
if (ModelState.IsValid)
{
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, set lockoutOnFailure: true
var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: true);
if (result.Succeeded)
{
IdentityUser user = await _signInManager.UserManager.FindByEmailAsync(Input.Email);
ClaimsPrincipal currentUser = …
Run Code Online (Sandbox Code Playgroud)