Blazor server and Web API connection with AD authentication

71185955 40 Reputation points
2023-04-04T08:17:08.0466667+00:00

I want to use Blasor Server application with Windows authentication and authorization and it would connent to a Web API. Could you help me how to check user state and role to reach API endpoints if I use JWT token, please? I would like to use our on-premise AD and not just a single Blazor server app if it is possible.

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,500 questions
Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,244 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 61,731 Reputation points
    2023-04-04T15:59:10.45+00:00

    you question is not clear. where is JWT token coming from and what account does it represent? Blazor server is just one authenticated request. The identify from this request can be injected into Blazor components. In your case IIS performed windows autheication, then pass the token to the blazor startup code which created the Identity principal and stored in the connection state. There is no default role provider windows authentication. you will need to create one. if you do, then the roles can be added to principal. now your blazor server code needs to call a web api. this is where you could use a JWT. your blazor server code build a JWT token and pass to the webapi. you should also have webapi callback to verify the token, that the webapi site could use, or use shared signing keys.