MSAL with Blazor Server and Web API

Michael Prattinger 1 Reputation point
2021-10-11T21:12:11.523+00:00

Hello everyone,

we have a blazor server site with msal authentication. We now want to expose a webapi from the same site/application. Is there a way to secure the webapi with msal and aad too?

thanks in advance,
r Michael

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,166 questions
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,390 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,473 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Brando Zhang-MSFT 2,956 Reputation points Microsoft Vendor
    2021-10-12T02:18:22.22+00:00

    As far as I know, MSAL.NET (Microsoft.Identity.Client) is an authentication library which enables you to acquire tokens from Azure AD, to access protected Web APIs (Microsoft APIs or applications registered with Azure Active Directory). MSAL.NET is available on several .NET platforms. That means MASL is a library to acquire tokens from Azure AD. If you want to protect an web api, you should refer to this article.

    If you want to use MSAL to get token and access API, you could refer to this article's sample to get how to do it.

    If you want to know how to use AAD protect your web api, you could refer to this article's sample.


  2. Bruce (SqlWork.com) 56,026 Reputation points
    2021-10-12T17:46:02.36+00:00

    I would not mix a blazor server with a webapi. The blazor server has persistent connections to each client, and a large amount of state information for each client in memory. as all the blazor logic is running on the server, you may have hi cpu if you have any number of users.


  3. Bruce (SqlWork.com) 56,026 Reputation points
    2021-10-14T16:37:58.413+00:00

    your authentication setup is not clear. typically with Blazor server you would be using cookie authentication and with a webapi bearer tokens. msal is client library that uses bearer tokens, so if you are using msal, then you are already are using them.

    anyway just google asp.net core cookie and bearer token authentication for configuration examples.

    0 comments No comments