claims

Correct use of JwtTokens in C#

前提是你 提交于 2019-12-01 03:30:24
I'm playing a with JwtTokens and can't make them work properly. I'm using http://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/ for it. I know the code is a mess but is just to show what I'm trying to do. The problem is that I want the JwtTokenHandler to fail the validation because of the lifetime. 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";

How to pass claims mapping options to IdentityServerJwt in ASP.NET Core 3.0 Preview 5?

邮差的信 提交于 2019-12-01 01:59:22
Inspired by an article on custom claims , I've added a tenant id custom claim to my Identity server sign in process as follows: using System; using System.Security.Claims; using System.Threading.Tasks; using MyNamespace.Models; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Options; using MyNamespace.Data; using MyNamespace.Constants; namespace MyNamespace.Factories { public class TenantClaimsPrincipalFactory : UserClaimsPrincipalFactory<ApplicationUser> { public TenantClaimsPrincipalFactory( UserManager<ApplicationUser> userManager, IOptions<IdentityOptions> optionsAccessor)

Redirect loop with .Net MVC Authorize attribute with ADFS Claims

余生长醉 提交于 2019-11-30 02:57:20
问题 I have a problem configuring ADFS with my .Net MVC 5 app. I have configured my project in VS 2015 to use claims and it works ok, but I have an issue. I can sign in, ussing ADFS, I can check user roles etc. The problem occures when i try to use [Authorize(Roles="somenonExistingRole")] despite that I'm already authenticated I am redirected to ADFS page, when Authentication takes place again, and I'm redirected to my page, where loop occures. Page send me to ADFS portal , ADFS redirects my to

ASP.NET Core JWT and Claims

这一生的挚爱 提交于 2019-11-29 16:29:11
问题 I have a question regarding JWT authentication in ASP.NET Core and Claims, because I don't know if I get everything correctly. When I create a JWT token in ASP.NET I add some Claims, some of which can be custom. What happens when the request with JWT token is sent from the client to API. How is User.Claims filled ? Does it use the claims that are read from JWT? I would like to create a custom Identity provider ( don't want to use this provided by ASP.NET), with my own tables for user data,

MVC5 AntiForgeryToken Claims/“Sequence contains more than one element”

一笑奈何 提交于 2019-11-29 13:17:27
Case: I have an MVC5 application (basically the MVC5 template with a scaffolded view) with the Google authentication method enabled. The application has been configured to accept email as user name and to store the claims assigned from Google like Surname, givenname, email, nameidentifier, etc, to the membership database (AspNetUserClaims). When I register and log in with a "local" user everything is fine. If I log in with a Google user its fine. If I log in with an account set up to have both a local and external login I get the error below. I have tried changing the type for the token to

Claims transformation support missing in ASP.NET Core 2.0

半腔热情 提交于 2019-11-29 02:22:23
I am using JWT Bearer auth in my new asp.net core 2.0 api app and want to add some extra claims to the current identity. This extra info is located in another api which need to be queried. My understanding is that claims transformation would be the proper place to do this. In .net core 1.1 you have the IClaimsTransformer interface in Microsoft.AspNetCore.Authentication nuget package, but I cannot install this one in my .net core 2.0 app. Is there a alternative way to transform claims in asp.net core 2.0 and is this the correct approach for my use case? Canada Wan IClaimsTransformer has been

Access Claim values in controller in MVC 5

六眼飞鱼酱① 提交于 2019-11-28 04:51:22
I have used OWIN authentication in my application. Login Action var claims = new List<Claim>(); claims.Add(new Claim(ClaimTypes.Name, result.UserFirstName)); claims.Add(new Claim(ClaimTypes.Sid, result.UserID.ToString())); var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie); I want to access the UserName and UserID from different action. How can I access the values which is added in the claims? Update I have tried var claims = new List<Claim>(); claims.Add(new Claim(ClaimTypes.Name, result.UserFirstName + " " + result.UserLastName)); claims.Add(new Claim

MVC5 Claims version of the Authorize attribute

自古美人都是妖i 提交于 2019-11-27 02:45:01
I'm trying out some of the new stuff in VS2013 RC with MVC5 and the new OWIN authentication middleware. So, I'm used to using the [Authorize] attribute to limit actions by role but I'm trying to use claims/activity based authorization, and I can't find an equivalent attribute for it. Is there an obvious one I'm missing or do I need to roll my own? I kinda expected there to be one out of the box. What I'm looking for specifically is something along the lines of [Authorize("ClaimType","ClaimValue")] I suppose. Thanks in advance. Stimul8d I ended up just writing a simple attribute to handle it. I

MVC5 Claims version of the Authorize attribute

核能气质少年 提交于 2019-11-26 10:09:02
问题 I\'m trying out some of the new stuff in VS2013 RC with MVC5 and the new OWIN authentication middleware. So, I\'m used to using the [Authorize] attribute to limit actions by role but I\'m trying to use claims/activity based authorization, and I can\'t find an equivalent attribute for it. Is there an obvious one I\'m missing or do I need to roll my own? I kinda expected there to be one out of the box. What I\'m looking for specifically is something along the lines of [Authorize(\"ClaimType\",\

Is claims based authorization appropriate for individual resources

空扰寡人 提交于 2019-11-26 05:39:21
问题 I understand the usage of claims for things I would commonly refer to as \"roles\" or \"permissions\". I know that claims are more general, but from what I have seen in practice, it usually boils down to this: If user has this set of claims they can access certain areas, or perform certain functions. Imagine a wiki application. You might have a content_contributor claim that would allow a user to add content, a content_admin claim that would allow a user to remove content, and a modify_user