Запрос о получении пользовательских атрибутов безопасности в MicrosoftC#

Место общения программистов C#
Ответить
Anonymous
 Запрос о получении пользовательских атрибутов безопасности в Microsoft

Сообщение Anonymous »

Я пытаюсь получить ключи и значения в моих пользовательских атрибутах безопасности в графе Microsoft, но, к сожалению, я не смог и не нашел способов получить это. поскольку я искал на многих веб-сайтах информацию о том, как получить ключ и значение. ниже мой код, который я пытался получить подробности. другие данные, такие как имя и телефон, работают нормально.
// The client credentials flow requires that you request the
// /.default scope, and pre-configure your permissions on the
// app registration in Azure. An administrator must grant consent
// to those permissions beforehand.
var scopes = new[] { "https://graph.microsoft.com/.default" };

// Values from app registration
var clientId = "xxxx";
var tenantId = "xxx";
var clientSecret = "xxxxx";

// using Azure.Identity;
var options = new ClientSecretCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,
};

var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret, options);

var graphClient = new GraphServiceClient(clientSecretCredential, scopes);

var result = await graphClient.Users[id].GetAsync((requestConfiguration) =>
{

requestConfiguration.QueryParameters.Select = new string[] { "customSecurityAttributes" };

});

var user = result.CustomSecurityAttributes;

// Assume custom security attributes are part of AdditionalData
if (user.AdditionalData != null)
{
// Use reflection to access private or non-public members
foreach (var attribute in user.AdditionalData)
{
Console.WriteLine($"Public Key: {attribute.Key}, Public Value: {attribute.Value}");

// Get the type of the value object to inspect non-public members
Type valueType = attribute.Value.GetType();

// Get all fields including non-public fields
var fields = valueType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);

// Loop through non-public fields and print their values
foreach (var field in fields)
{
var fieldValue = field.GetValue(attribute.Value);
Console.WriteLine($"Non-Public Field: {field.Name}, Value: {fieldValue}");
}

// Get all properties including non-public properties
var properties = valueType.GetProperties(BindingFlags.NonPublic | BindingFlags.Instance);

// Loop through non-public properties and print their values
foreach (var property in properties)
{
var propertyValue = property.GetValue(attribute.Value);
Console.WriteLine($"Non-Public Property: {property.Name}, Value: {propertyValue}");
}
}
}
else
{
Console.WriteLine("No custom security attributes found.");
}


Подробнее здесь: https://stackoverflow.com/questions/790 ... -microsoft
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»