Azure AD Compilation error

Hi Guys,

I'm trying to add Azure AD authentication to an angular radzen app (.net core 3.1). I added packages to server project:
Microsoft.AspNetCore.Authentication.AzureAD.UI --version 3.1.1
Microsoft.AspNetCore.Authentication --version 3.1.1

Next, I created a Startup.Custom.cs file and wrote this:

partial void OnConfigureServices(IServiceCollection services)

{

    services.Configure<CookiePolicyOptions>(options =>

    {

        options.CheckConsentNeeded = context => true;

        options.MinimumSameSitePolicy = SameSiteMode.None;

    });

    services.AddAuthentication(AzureADDefaults.AuthenticationScheme)

        .AddAzureAD(options => Configuration.Bind("AzureAd", options));

    services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>

    {

        options.Authority = options.Authority + "/v2.0/";

        options.TokenValidationParameters.ValidateIssuer = false;

    });

}

Later I added entries in appsettings.json to describe Azure AD parameters:

"AzureAd": {

"Instance": "https://login.microsoftonline.com/",

"Domain": "xxx.onmicrosoft.com",

"TenantId": "...",

"ClientId": "...",

"CallbackPath": "/signin-oidc"

}

When I try to run project error message is shown:

radzen: Generating code ...
radzen: Code generation done in 467ms.
dotnet: Unhandled exception.
dotnet: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Razor.Runtime, Version=3.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. El sistema no puede encontrar el archivo especificado.

I try to add this package however error doesn't disappear. Any clues?

Thanks in advance.

Hi @Carlos_Carminati,

According to Nuget this package version doesn't exist. You may have to create a .NET Core 2.2 application.

Hi Atanas,

I created a new app .net 2.2 and follow previous procedure to add azure ad but Authentication doesn’t work. Do you have a step by step guide to this? I Think this scenario will be Common in web Apps With organization auth or B2C. In my case Customer ask for it.

I will appreciate your Assistance.

Regards

Hi @Carlos_Carminati,

Radzen doesn't support Azure AD authentication out of the box. It supports ASP.NET Core Identity and Active Directory.

Hi Carlos -
I'm trying to get Azure AD to work with my app as well so I can have MFA at login. Did you get Azure AD to work with Radzen?

Thx,

Bob

Hi Bob,

Azure AD is not supported in radzen angular projects. But, I use MSGraph to workaround this limitation. Steps are:
1 - Follow instructions in MS Graph (Angular)?
2 - In Main Layout, Load event, or in Home page, Load event add an Invoke data source method and find "getMe" under OData MsGraph saving user name and user id in session variables. If you have concerns about visibility of this data you could offuscate it. You can show User Name in layout.
3 - Use a table in your DB to CRUD users allowed to access the app and roles assigned. If a user is not allowed redirect to a public page that notify how to require access.
4 - Check in main menu visibility rol of user to show or hide menu option.
5 - In load event of all pages check if user has necessary rol and if not allowed redirect to Unauthorized page.

Lot of work but it works.

Let me know if you have other questions.

Regards!