Code: Select all
TestApp.Client
[*]
Code: Select all
TestApp.API
[*]
Code: Select all
TestApp.Domain
[*]
Code: Select all
TestApp.Application
[*]
Code: Select all
TestApp.Shared
Die Authentifizierung erfolgt derzeit in der Client -Ebene mit einem GraphServiceClient und Tokens aus Azure AD, und dann konsumiert die API -Ebene diese Daten. Program.cs:
// Configure MSAL authentication
builder.Services.AddMsalAuthentication(options =>
{
builder.Configuration.Bind("AzureAd", options.ProviderOptions.Authentication);
options.ProviderOptions.DefaultAccessTokenScopes.Add("https://graph.microsoft.com/User.Read");
options.ProviderOptions.DefaultAccessTokenScopes.Add("https://graph.microsoft.com/User.Read.All");
options.UserOptions.RoleClaim = "appRole";
})
.AddAccountClaimsPrincipalFactory();
// Configure Graph Client
var baseUrl = builder.Configuration.GetSection("MicrosoftGraph")["BaseUrl"];
var scopes = builder.Configuration.GetSection("MicrosoftGraph:Scopes")
.Get();
builder.Services.AddGraphClient(baseUrl, scopes);
Service:
using TestApp.Client.Services.Interfaces;
using TestApp.Shared.DTOs;
using Microsoft.Graph;
using Microsoft.Graph.Models;
using System.Net.Http;
using System.Net.Http.Json;
namespace TestApp.Client.Services;
public class AdUserService(
HttpClient httpClient,
GraphServiceClient graphClient,
INotificationService notificationService
) : IAdUserService
{
private readonly GraphServiceClient _graphClient = graphClient;
public async Task GetCurrentUserAsync()
{
var result = await _graphClient.Me.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Select = new[]
{ "id,displayName", "jobTitle", "mobilePhone", "mail", "givenName", "surname" };
});
return result;
}
public async Task GetAdUsersAsync2()
{
var adUsers = new List();
var result = await _graphClient.Users.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Top = 100;
requestConfiguration.QueryParameters.Filter =
"endsWith(mail,'@pasar.com.ph') and accountEnabled eq true";
});
if (result?.Value != null)
{
adUsers.AddRange(result.Value);
}
return adUsers;
}
}
< /code>
Meine Fragen < /strong> < /p>
Kann die Authentifizierung der Windows -Authentifizierung in dieser Art von geschichteten ASP.NET -Kernarchitektur direkt ersetzen. Berechtigungen, Zugriff auf das Benutzerverzeichnis)? />asp.net Core Web API + Client < /li>
Derzeit authentifiziert sich über Azure AD + Microsoft-Graph < /li>
< /ul>
Eine Anleitung zur Anleitung zur Windows-Authentifizierung kann ein Drop-In-Ersatz sein.>