标签: claims-based-identity

向5岁的人解释"基于声明的身份验证"

嗯,不完全是一个5岁的孩子,但如果可能请避免使用流行语和企业语.

基于声明的身份验证现在似乎风靡一时,但我找不到一个简单而实际的解释,它实际上是什么,它与我们现在的不同(我假设"我们现在拥有的")基于角色的身份验证),使用它有什么好处,等等.

terminology claims-based-identity

182
推荐指数
6
解决办法
3万
查看次数

ASP.NET MVC中基于角色的访问控制(RBAC)与基于声明的访问控制(CBAC)

使用CBACRBAC的主要好处是什么?何时使用CBAC更好,何时使用RBAC更好?

我试图理解CBAC模型的一般概念,但总体思路对我来说仍然不明确.

asp.net-mvc access-control claims-based-identity role-based role-base-authorization

129
推荐指数
9
解决办法
4万
查看次数

防伪令牌问题(MVC 5)

我遇到了防伪令牌的问题:(我已经创建了自己的User类,但是现在每次进入/ Account/Register页面时我都会收到错误.错误是:

" http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier "或" http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider " 类型的声明是不在提供的ClaimsIdentity上.要使用基于声明的身份验证启用防伪令牌支持,请验证配置的声明提供程序是否在其生成的ClaimsIdentity实例上提供这两个声明.如果配置的声明提供程序使用不同的声明类型作为唯一标识符,则可以通过设置静态属性AntiForgeryConfig.UniqueClaimTypeIdentifier来配置它.

我找到了这篇文章:

http://stack247.wordpress.com/2013/02/22/antiforgerytoken-a-claim-of-type-nameidentifier-or-identityprovider-was-not-present-on-provided-claimsidentity/

所以我将Application_Start方法更改为:

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();

    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);

    AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.Email;
}
Run Code Online (Sandbox Code Playgroud)

但是当我这样做时,我收到了这个错误:

提供的ClaimsIdentity中没有" http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress " 类型的声明.

有没有人遇到过这个?如果是这样,你知道如何解决它吗?

提前干杯,
r3plica

更新1

这是我的自定义用户类:

public class Profile : User, IProfile
{
    public Profile()
        : base()
    {
        this.LastLoginDate = DateTime.UtcNow;
        this.DateCreated = DateTime.UtcNow;
    }

    public Profile(string userName)
        : base(userName)
    {
        this.CreatedBy = this.Id;

        this.LastLoginDate = DateTime.UtcNow;
        this.DateCreated = DateTime.UtcNow;

        this.IsApproved = true;
    }

    [NotMapped]
    public HttpPostedFileBase File { …
Run Code Online (Sandbox Code Playgroud)

c# authentication asp.net-mvc claims-based-identity

112
推荐指数
6
解决办法
6万
查看次数

MVC 5访问声明身份用户数据

我正在使用Entity Framework 5 Database First方法开发MVC 5 Web应用程序.我正在使用OWIN进行用户身份验证.下面显示我的帐户控制器中的登录方法.

public ActionResult Login(LoginViewModel model, string returnUrl)
{
    if (ModelState.IsValid)
    {
        var user = _AccountService.VerifyPassword(model.UserName, model.Password, false);
        if (user != null)
        {
            var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, model.UserName), }, DefaultAuthenticationTypes.ApplicationCookie, ClaimTypes.Name, ClaimTypes.Role);

            identity.AddClaim(new Claim(ClaimTypes.Role, "guest"));
            identity.AddClaim(new Claim(ClaimTypes.GivenName, "A Person"));
            identity.AddClaim(new Claim(ClaimTypes.Sid, user.userID)); //OK to store userID here?

            AuthenticationManager.SignIn(new AuthenticationProperties
            {
                IsPersistent = model.RememberMe
            }, identity);

            return RedirectToAction("Index", "MyDashboard");
        }
        else
        {
            ModelState.AddModelError("", "Invalid username or password."); …
Run Code Online (Sandbox Code Playgroud)

asp.net authentication asp.net-mvc claims-based-identity asp.net-mvc-5

109
推荐指数
9
解决办法
18万
查看次数

ASP.NET身份中角色与声明的最佳实践

我对claimsin 的使用完全不熟悉,ASP.NETIdentity并希望了解使用中的最佳实践Roles and/or Claims.

经过这一切阅读后,我仍然有类似的问题......

问:我们不再使用角色吗?
问:如果是这样,为什么Roles仍然提供?
问:我们应该只使用索赔吗?
问:我们应该一起使用角色和声明吗?

我最初的想法是我们"应该"一起使用它们.我认为他们支持的Claims子类别Roles.

例如:
角色:会计
索赔:CanUpdateLedger,CanOnlyReadLedger,CanDeleteFromLedger

问:他们打算互相排斥吗?
问:或者最好只去索赔并"完全符合"你的要求吗?
问:那么这里的最佳做法是什么?

示例:一起使用角色和声明
当然,您必须为此编写自己的属性逻辑...

[Authorize(Roles="Accounting")]
[ClaimAuthorize(Permission="CanUpdateLedger")]
public ActionResult CreateAsset(Asset entity)
{
    // Do stuff here

    return View();
}
Run Code Online (Sandbox Code Playgroud)

示例:完全限定您的索赔

[ClaimAuthorize(Permission="Accounting.Ledger.CanUpdate")]
public ActionResult CreateAsset(Asset entity)
{
    // Do stuff here

    return View();
}
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc roles claims-based-identity

83
推荐指数
4
解决办法
3万
查看次数

nameidentifier声明的目的是什么?

http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier应该使用什么类型的声明?

这是主要问题,这里还有其他问题.

它与http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name索赔有什么不同?

对于特定用户而言,与名称声明相反,它是永久性的吗

它是全局范围的还是IdP范围的?

federated-identity claims-based-identity adfs2.0

68
推荐指数
3
解决办法
3万
查看次数

为什么我的ClaimsIdentity IsAuthenticated始终为false(对于web api授权过滤器)?

在Web API项目中,我重写了正常的身份验证过程来检查令牌.代码看起来像这样:

if ( true ) // validate the token or whatever here
{
    var claims = new List<Claim>();
    claims.Add( new Claim( ClaimTypes.Name, "MyUser" ) );
    claims.Add( new Claim( ClaimTypes.NameIdentifier, "MyUserID" ) );
    claims.Add( new Claim( ClaimTypes.Role, "MyRole" ) );

    var claimsIdentity = new ClaimsIdentity( claims );

    var principal = new ClaimsPrincipal( new[] { claimsIdentity } );
    Thread.CurrentPrincipal = principal;
    HttpContext.Current.User = principal;
}
Run Code Online (Sandbox Code Playgroud)

然后,当我将[Authorize]属性应用于控制器时,它无法授权.

调试代码确认相同的行为:

// ALWAYS FALSE!
if ( HttpContext.Current.User.Identity.IsAuthenticated ) {
    // do something
} …
Run Code Online (Sandbox Code Playgroud)

c# asp.net claims-based-identity asp.net-4.5 asp.net-web-api

65
推荐指数
2
解决办法
3万
查看次数

嵌入式语句不能是声明或带标签的语句

我正在尝试使用声明身份asp.net创建用户我在创建声明身份用户时遇到此错误.

  ApplicationUser user = new ApplicationUser { 
                        EmailConfirmed = true, 
                        UserName = model.myUser.Email,
                        Email = model.myUser.Email ,
                        PhoneNumber = model.myUser.PhoneNumber,
                        PhoneNumberConfirmed = true,
                        UserImagePath = model.myUser.UserImagePath,
                        FirstName= model.myUser.FirstName,
                        LastName = model.myUser.LastName,
                        DateOfBirth = model.myUser.DateOfBirth,
                        Culture = model.myUser.Culture,
                        Role = model.myUser.Role
                    };
Run Code Online (Sandbox Code Playgroud)

但是当代码是

var user= new ApplicationUser { 

                            UserName = model.myUser.Email,
                            Email = model.myUser.Email ,

                        };
Run Code Online (Sandbox Code Playgroud)

它工作得很好,所以我想知道出了什么问题

c# model-view-controller claims-based-identity

52
推荐指数
2
解决办法
5万
查看次数

使用Windows域帐户和应用程序管理的帐户

创建一个基于Windows域用户进行身份验证的ASP.NET MVC应用程序很容易.创建一个使用Entity Framework存储的个人帐户也很容易.事实上,两者都有项目模板.

但我想利用BOTH各种认证在同一应用程序.我试图结合两个项目模板的代码.我在Startup.Auth.cs中遇到问题.

// from "Individual Accounts" template
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    LoginPath = new PathString("/Account/Login"),
    Provider = new CookieAuthenticationProvider
    {
        OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
            validateInterval: TimeSpan.FromMinutes(30),
            regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
    }
});
Run Code Online (Sandbox Code Playgroud)

中间件中存在cookie身份验证似乎导致域身份变为未经身份验证.如果我采用此行,域身份验证将起作用.但没有它,我似乎无法支持个人用户帐户.

我已经下载了katana项目源代码并检查了CookieAuthenticationHandler.cs,但我不太明白它是如何在OWIN管道的上下文中工作的.

如何使用ASP.net身份框架允许我的应用程序从Windows域或特定于应用程序的用户存储中验证用户?

c# asp.net-mvc claims-based-identity asp.net-mvc-5 asp.net-identity

39
推荐指数
2
解决办法
1993
查看次数

ASP.NET身份和声明

我正试图摆脱WebForms并学习MVC,特别是使用新的ASP.NET身份模型.但是,我似乎无法找到Microsoft的任何正式文档,它们演示了如何创建声明对象,并将其存储在数据库中以供经过身份验证的用户使用.

我的网站,需要做以下事情:

  1. 验证用户 - TICK
  2. 创建一个声明,并在其中存储用户信息,以便我可以在整个会话中使用它 - 没有提示
  3. 从新的ASP.NET角色表中撤回用户角色 - NOT TICK

任何人都可以阐明如何实现这一目标吗?

asp.net-mvc claims-based-identity

38
推荐指数
2
解决办法
3万
查看次数