2021年2月5日星期五

Blazor Role Based Authorization Return False

I have the blazor with roled based.

I loop the claims from context.user. It has following claims:

  Hello superadmin@gmail.com !!  Type: http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name + Value: superadmin@gmail.com  Type: http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier32678458 + Value: afa68479-28eb-4823-889c-70e4b161aecf  Type: http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name15158991 + Value: superadmin@gmail.com  Type: http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress49903371 + Value: superadmin@gmail.com  Type: AspNet.Identity.SecurityStamp41337846 + Value: YLXYUYXMPICHEHR3J3SFWGPV366GEOTP  Type: http://schemas.microsoft.com/ws/2008/06/identity/claims/role62788414 + Value: Basic  Type: http://schemas.microsoft.com/ws/2008/06/identity/claims/role43488279 + Value: SuperAdmin  

In the component view I have authorise component like below

<AuthorizeView Roles="SuperAdmin">      <p>You can only see this if you're an admin.</p>  </AuthorizeView>  <AuthorizeView Roles="Basic">      <p>You can only see this if you're an basic.</p>  </AuthorizeView>  

When I run the project it showed nothing - I logged with SuperAdmin user which of cousrse has SuperAdmin role. And I check the console. It showed as below.

info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2]    Authorization failed. These requirements were not met:    RolesAuthorizationRequirement:User.IsInRole must be true for one of the following roles: (SuperAdmin)  

What wrong with this?

https://stackoverflow.com/questions/66073218/blazor-role-based-authorization-return-false February 06, 2021 at 11:06AM

没有评论:

发表评论