LongNeckTimmy
LongNeckTimmy

Reputation: 167

Blazor Server Azure App Service Easy Auth

I have a .Net 6.0 Blazor Server app running in an Azure App Service. Azure gives you the ability to setup your App Service so that it does the authentication for you. This is called Easy Auth. You can configure Easy Auth with various identity providers, in my case I'm using Azure Active Directory. Here is a link explaining App Service Easy Auth in more detail.

The concept of this is that you do not need to add any authentication middleware code to your application, the App Service handles all of it for you.

I am struggling to figure out how to access the currently authenticated user and their roles from my Blazor Server code.

For a Blazor WebAssembly app running in an App Service configured with Easy Auth, when you make a call to your controllers the App Service auto-magically puts the authenticated users information in a header and you can access it that way.

I tried following this guys post, but I could not access the authenticated user. He was also struggling to access the roles of a user.

Does anyone know how I can solve this?

Upvotes: 1

Views: 709

Answers (1)

Tiny Wang
Tiny Wang

Reputation: 16066

according to this document, we are able to use /.auth/me to reach the signed in user profile after enabling easy auth.

enter image description here

Since we are now using Azure AD as the identity platform, and we are able to access the id token now, so we could try to gather the user role by decoding the id token. Or we could use the access token to call graph api and obtain the user role.

Upvotes: 1

Related Questions