# Any examples of how to set up role-based authorization with Blazor WASM and ASP.NET Core API?

**URL:** <https://devforum.okta.com/t/any-examples-of-how-to-set-up-role-based-authorization-with-blazor-wasm-and-asp-net-core-api/12672>\
**Category:** OAuth/OIDC\
**Tags:** dotnet, api\
**Created:** [January 28, 2021, 11:16pm UTC](https://devforum.okta.com/t/any-examples-of-how-to-set-up-role-based-authorization-with-blazor-wasm-and-asp-net-core-api/12672 "2021-01-28T23:16:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![davewevans72](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/davewevans72/32/2331_2.png) [@davewevans72](https://devforum.okta.com/u/davewevans72)\
**Post date:** [January 28, 2021, 11:16pm UTC](https://devforum.okta.com/t/any-examples-of-how-to-set-up-role-based-authorization-with-blazor-wasm-and-asp-net-core-api/12672/1 "2021-01-28T23:16:07Z")

</div>

I keep running into walls trying to set up Okta with Blazor WASM and [ASP.NET](http://ASP.NET) Core API. I just started with Okta and I am by no means an expert at identity. I’ve Googled for hours and I cannot find a comprehensive example of how to set this up. I have the authentication and the token validation working, but how do I add roles? I’ve tried mapping Groups to roles per the instructions in a 2-year old YouTube video by the dude with long gray hair, but that didn’t work. I thought Okta is supposed to make this easy!  
Lost and frustrated. Please help.

---

<div class="post-metadata">

**Author:** ![Fuzzard](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/fuzzard/32/1909_2.png) [@Fuzzard](https://devforum.okta.com/u/Fuzzard)\
**Post date:** [January 29, 2021, 5:22pm UTC](https://devforum.okta.com/t/any-examples-of-how-to-set-up-role-based-authorization-with-blazor-wasm-and-asp-net-core-api/12672/2 "2021-01-29T17:22:00Z")

</div>

let us know if the official Microsoft docs on this help

> **[About authorization in .NET microservices and web applications](https://docs.microsoft.com/en-us/dotnet/architecture/microservices/secure-net-microservices-web-applications/authorization-net-microservices-web-applications)**
>
> Security in .NET Microservices and Web Applications - Get an overview of the main authorization options in ASP.NET Core applications - role-based and policy-based.

> **[Role-based authorization in ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/security/authorization/roles?view=aspnetcore-5.0)**
>
> Learn how to restrict ASP.NET Core controller and action access by passing roles to the Authorize attribute.

---

<div class="post-metadata">

**Author:** ![davewevans72](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/davewevans72/32/2331_2.png) [@davewevans72](https://devforum.okta.com/u/davewevans72)\
**Post date:** [January 29, 2021, 5:38pm UTC](https://devforum.okta.com/t/any-examples-of-how-to-set-up-role-based-authorization-with-blazor-wasm-and-asp-net-core-api/12672/3 "2021-01-29T17:38:28Z")

</div>

Thanks.  
The problem I’m having now I’m not getting the “groups” claim in the payload. It doesn’t show up in the Token Preview. I understand I need to map groups to roles in [ASP.NET](http://ASP.NET) identity. But I can’t get the claim.

 ![Capture3](https://global.discourse-cdn.com/oktadev/original/2X/e/e3dc1daf71c5e6bff6580508f8219e0e79a4e4c7.png) ![Capture2](https://global.discourse-cdn.com/oktadev/original/2X/7/7f155e1ca17a38c2fe97cdc04965c4372f9d79ab.png) ![Capture](https://global.discourse-cdn.com/oktadev/original/2X/8/8438921fca9a9c4becb26abd25f743b65e2dc97e.png)

If I can get the groups claim then I can take it from there.

---

<div class="post-metadata">

**Author:** ![sigama](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/sigama/32/5811_2.png) [@sigama](https://devforum.okta.com/u/sigama)\
**Post date:** [January 29, 2021, 5:47pm UTC](https://devforum.okta.com/t/any-examples-of-how-to-set-up-role-based-authorization-with-blazor-wasm-and-asp-net-core-api/12672/4 "2021-01-29T17:47:40Z")

</div>

@davewevans72 please change your filter from Starts with to Matches regex and set that to .\* to get all groups.

---

<div class="post-metadata">

**Author:** ![pmmout](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@pmmout](https://devforum.okta.com/u/pmmout)\
**Post date:** [May 12, 2021, 1:43pm UTC](https://devforum.okta.com/t/any-examples-of-how-to-set-up-role-based-authorization-with-blazor-wasm-and-asp-net-core-api/12672/5 "2021-05-12T13:43:17Z")

</div>

Hi davewevans72, did you get the answer. Can you get claims from groups in Blazor?

---

<div class="post-metadata">

**Author:** ![davewevans72](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/davewevans72/32/2331_2.png) [@davewevans72](https://devforum.okta.com/u/davewevans72)\
**Post date:** [May 12, 2021, 4:59pm UTC](https://devforum.okta.com/t/any-examples-of-how-to-set-up-role-based-authorization-with-blazor-wasm-and-asp-net-core-api/12672/6 "2021-05-12T16:59:26Z")

</div>

Not really. But I followed the advice in this post:  
[https://devforum.okta.com/t/blazor-wasm-net-core-3-1-api-userinfo/11878/2](https://devforum.okta.com/t/blazor-wasm-net-core-3-1-api-userinfo/11878/2)

Basically, it intercepts the token at the API end, reaches out to the Okta API and gets the claims. Then adds those claims. I believe I saved the uid from Okta as the users oktaUserId. Something like that. That’s how I map the users in my db with the ones in Okta.  
This works fine but it would be nice to have a more direct way of getting the claims.

---

<div class="post-metadata">

**Author:** ![pmmout](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@pmmout](https://devforum.okta.com/u/pmmout)\
**Post date:** [May 13, 2021, 9:47am UTC](https://devforum.okta.com/t/any-examples-of-how-to-set-up-role-based-authorization-with-blazor-wasm-and-asp-net-core-api/12672/7 "2021-05-13T09:47:51Z")

</div>

Ok, Thanks. If I get something I let you know.

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [February 7, 2024, 7:26pm UTC](https://devforum.okta.com/t/any-examples-of-how-to-set-up-role-based-authorization-with-blazor-wasm-and-asp-net-core-api/12672/8 "2024-02-07T19:26:33Z")

</div>

Closed on February 7, 2024, 7:26pm UTC


