Я пытаюсь получить ключи и значения в моих пользовательских атрибутах безопасности в графе 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
Запрос о получении пользовательских атрибутов безопасности в Microsoft ⇐ C#
Место общения программистов C#
1726744422
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.");
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79002247/inquiry-about-retrieving-custom-security-attributes-in-microsoft[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия