Reputation: 17182
I want to add custom attributes specific to user, say for example LeavePolicyId, in Windows Azure Active Directory User.
I tried different ways - using PowerShell CmdLets, using Azure WAAD Graph API, and obviously through Azure Managementment portal UI. But all efforts never gave me a solution.
I see present list of attributes available here - http://technet.microsoft.com/en-us/library/dn194096.aspx. But I want to add custom ones.
Please let me know if there is another way to solve this?
Thanks,
Upvotes: 3
Views: 18341
Reputation: 616
You can use ExtendedProperty, add the property to an App register in AAD(Azure Active Directory) to an user, and then asing the value...
ExtensionProperty identidadSecreta = new ExtensionProperty
{
Name = "LaIdentidadSecreta",
DataType = "String",
TargetObjects = { "User" }
};
myApplication.ExtensionProperties.Add(identidadSecreta);
await myApplication.UpdateAsync();
client.Context.SaveChanges();
Then to the user:
User user = null;
try
{
ActiveDirectoryClient client = AuthenticationHelper.GetActiveDirectoryClient();
user = (User)await client.Users.GetByObjectId(objectId).ExecuteAsync();
user.SetExtendedProperty("extension_e99c8a1afb544da491b098931b0a2ad8_LaidentidadSecreta", "Bruno Días");
await user.UpdateAsync();
Geting the value:
string extensionValue = (String)user.GetExtendedProperties()["extension_e99c8a1afb544da491b098931b0a2ad8_LaidentidadSecreta"];// The Guid is the App Guid.
Beaware of this !!!. Fortunately if you initialize the ActiveDirectoryClient and use Microsoft.Data.Services.Client version 5.7.0 will work.
//////
private static void UndeclaredPropertyHandler(MessageWriterSettingsArgs args)
{
var field = args.Settings.GetType().GetField("settings",
BindingFlags.NonPublic | BindingFlags.Instance);
var settingsObject = field?.GetValue(args.Settings);
var settings = settingsObject as ODataMessageWriterSettings;
if (settings != null)
{
settings.UndeclaredPropertyBehaviorKinds =
ODataUndeclaredPropertyBehaviorKinds.SupportUndeclaredValueProperty;
}
}
public async Task<ActionResult> SomeMethod(string objectId)
{
User user = null;
try
{
// forma normal
ActiveDirectoryClient client = AuthenticationHelper.GetActiveDirectoryClient();
// #adicional
client.Context
.Configurations.RequestPipeline
.OnMessageWriterSettingsCreated(UndeclaredPropertyHandler);
// #adicional
Upvotes: 2
Reputation: 141
It looks like there is a way to do this via the Graph API...it's not going to look much like extending the AD DS schema...but Azure AD doesn't look much like that anyway.
That article has more info...
Upvotes: 1