Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure AD图形API目录架构扩展_Azure_Azure Active Directory - Fatal编程技术网

Azure AD图形API目录架构扩展

Azure AD图形API目录架构扩展,azure,azure-active-directory,Azure,Azure Active Directory,我目前正在尝试使用Graph Client Library 2.0版与我的Azure Active Directory交互。我想给用户添加一个新属性,所以我需要使用模式扩展。我在这里学习了教程:,在这里学习了示例代码: 我的代码: public async Task setAccountNumber(string UserName, String AccountNumber) { ////Register an Extension Property in Azure AD

我目前正在尝试使用Graph Client Library 2.0版与我的Azure Active Directory交互。我想给用户添加一个新属性,所以我需要使用模式扩展。我在这里学习了教程:,在这里学习了示例代码:

我的代码:

public async Task setAccountNumber(string UserName, String AccountNumber)
    {
        ////Register an Extension Property in Azure AD which is the account number
        ////Define the account number property
        //ExtensionProperty accountNumber = new ExtensionProperty()
        //{
        //    Name = "AccountNumber",
        //    DataType = "String",
        //    TargetObjects = { "User" }
        //};

        //// Get a reference to our application
        //Microsoft.Azure.ActiveDirectory.GraphClient.Application app =
        //                (Microsoft.Azure.ActiveDirectory.GraphClient.Application)activeDirectoryClient.Applications.Where(
        //    a => a.AppId == Constants.ClientId).ExecuteSingleAsync().Result;

        //// Register the extension property
        //app.ExtensionProperties.Add(accountNumber);
        //await app.UpdateAsync();


        ExtensionProperty accountNumber = new ExtensionProperty()
        {
            Name = "AccountNumber",
            DataType = "String",
            TargetObjects = { "User" }
        };

        //Get the user
        User user = (User)activeDirectoryClient.Users.Where(u => u.UserPrincipalName.Equals(
            UserName, StringComparison.CurrentCultureIgnoreCase)).ExecuteSingleAsync().Result;

        //Set the Account Number property
        if (user != null)
        {
            user.SetExtendedProperty(accountNumber.Name, AccountNumber);
            await user.UpdateAsync();
            // Save the extended property value to Azure AD.
            //user.GetContext().SaveChanges();
        }

        // Retrieve the extension property value for a user for test use only!
        IReadOnlyDictionary<string, object> extendedProperties = user.GetExtendedProperties();
        object extendedProperty = extendedProperties["AccountNumber"];
}
第行:wait user.UpdateAsync

堆栈跟踪:

[DataServiceClientException: {"odata.error":{"code":"Request_BadRequest","message":{"lang":"en","value":"One or more extension property values specified are invalid."},"values":null}}]

[DataServiceRequestException: An error occurred while processing this request.]
System.Data.Services.Client.SaveResult.HandleResponse() +1038
System.Data.Services.Client.BaseSaveResult.EndRequest() +262
System.Data.Services.Client.DataServiceContext.EndSaveChanges(IAsyncResult asyncResult) +121
System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization) +99
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +144


System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +84
System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +49
Microsoft.Azure.ActiveDirectory.GraphClient.Extensions.<SaveChangesAsync>d__74.MoveNext() +1694
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +144
 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +84
DataIngestionAPI.Managers.<setAccountNumber>d__c.MoveNext() in c:\Users\Jason\Source\Repos\UCDavis Water\UCDavisResearchPlatform\DataIngestionAPI\Managers\AzureADManager.cs:107
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +144
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +84
DataIngestionAPI.Controllers.<Registration>d__6.MoveNext() in c:\Users\Jason\Source\Repos\UCDavis Water\UCDavisResearchPlatform\DataIngestionAPI\Controllers\HomeController.cs:123
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +144
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +84
System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) +89
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +110
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +92
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +71
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +196
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +141
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +65
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +189
System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +717
System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +66
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +71
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +196
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +141
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +65
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +103
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +330
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +71
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +196
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +73
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +58
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +90
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +188
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +196
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +73
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +50
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +68
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +60
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +85
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +196
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +73
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +50
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +58
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +93
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +188
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +196
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +73
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +50
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +58
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +59
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +282

非常感谢您的帮助。

因此我设法重现了这个问题。基本上,错误消息意味着服务找不到您正在查找的扩展属性。您的代码的问题是您正在指定AccountNumber作为扩展名。但是,扩展名的格式为extension\u appId\u extensionName,以确保扩展名的唯一性。注意:这里的appId是应用程序的appId又名clientId GUID,但没有破折号-即xxxx xxx变成XXXXXXXXX

因此,最简单的方法是使用上面的语法构造扩展属性名——在您的例子中,它将是extension\u appId\u AccountName,在这里替换应用程序的appId/clientId

我认为这可能是因为您复制了我们的示例,其中完整的扩展名在内存中,因为在示例中我们刚刚创建了扩展,所以我们从那里使用它。我可能会根据上面的语法更改示例以构造完整的扩展名

另外,有关目录架构扩展的更多信息,请参阅


希望这有帮助,所以我设法重现了这个问题。基本上,错误消息意味着服务找不到您正在查找的扩展属性。您的代码的问题是您正在指定AccountNumber作为扩展名。但是,扩展名的格式为extension\u appId\u extensionName,以确保扩展名的唯一性。注意:这里的appId是应用程序的appId又名clientId GUID,但没有破折号-即xxxx xxx变成XXXXXXXXX

因此,最简单的方法是使用上面的语法构造扩展属性名——在您的例子中,它将是extension\u appId\u AccountName,在这里替换应用程序的appId/clientId

我认为这可能是因为您复制了我们的示例,其中完整的扩展名在内存中,因为在示例中我们刚刚创建了扩展,所以我们从那里使用它。我可能会根据上面的语法更改示例以构造完整的扩展名

另外,有关目录架构扩展的更多信息,请参阅


希望这有帮助,

您使用的是哪个版本的Graph API客户端库?也在user.SetExtendedPropertyaccountNumber.Name行中,AccountNumber;什么是AccountNumber?它是字符串吗?感谢您的回复,我正在使用Microsoft Azure AD Graph API的网络客户端库,版本2.1.0。是的,AccountNumber是字符串,我已经尝试了字符串和字符串。那不行,谢谢。我不能责备你。我们会跟进并回复您。您使用的是哪个版本的Graph API客户端库?也在user.SetExtendedPropertyaccountNumber.Name行中,AccountNumber;什么是AccountNumber?它是字符串吗?感谢您的回复,我正在使用Microsoft Azure AD Graph API的网络客户端库,版本2.1.0。是的,AccountNumber是字符串,我已经尝试了字符串和字符串。那不行,谢谢。我不能责备你。我们会跟进并回复您。谢谢!真管用!还有一件事我想指出的是,客户端ID中的破折号需要删除。例如,如果从管理门户复制的clientID为xxx,则需要将其更改为XXXXXXXX。是-很好-谢谢。将更新答案,并带有指向架构扩展上的文档的链接。我创建了一个自定义属性,并将其映射到声明中的注册或登录策略。。尝试使用此customer属性创建新用户时,我遇到了相同的错误。{extension_Role,Admin}。。即使这个自定义属性存在,我仍然要创建这个扩展吗?你能为此提出一个新问题吗?看起来你也是在B2C租户中这样做的,所以也请添加一个[azure-ad-B2C]标签。谢谢!真管用!还有一件事我想指出的是,客户端ID中的破折号需要删除。例如,如果从管理门户复制的clientID为xxx,则需要将其更改为XXXXXXXX。是-很好-谢谢。将更新答案,并带有指向架构扩展上的文档的链接。我创建了一个自定义属性,并将其映射到声明中的注册或登录策略。。尝试使用此customer属性创建新用户时,我遇到了相同的错误。{extension_Role,Admin}。。即使这个自定义属性存在,我仍然要创建这个扩展吗?你能为此提出一个新问题吗?看起来你也是在B2C租户中这样做的,所以也请添加一个[azure-ad-B2C]标签。
[DataServiceClientException: {"odata.error":{"code":"Request_BadRequest","message":{"lang":"en","value":"One or more extension property values specified are invalid."},"values":null}}]

[DataServiceRequestException: An error occurred while processing this request.]
System.Data.Services.Client.SaveResult.HandleResponse() +1038
System.Data.Services.Client.BaseSaveResult.EndRequest() +262
System.Data.Services.Client.DataServiceContext.EndSaveChanges(IAsyncResult asyncResult) +121
System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization) +99
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +144


System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +84
System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +49
Microsoft.Azure.ActiveDirectory.GraphClient.Extensions.<SaveChangesAsync>d__74.MoveNext() +1694
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +144
 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +84
DataIngestionAPI.Managers.<setAccountNumber>d__c.MoveNext() in c:\Users\Jason\Source\Repos\UCDavis Water\UCDavisResearchPlatform\DataIngestionAPI\Managers\AzureADManager.cs:107
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +144
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +84
DataIngestionAPI.Controllers.<Registration>d__6.MoveNext() in c:\Users\Jason\Source\Repos\UCDavis Water\UCDavisResearchPlatform\DataIngestionAPI\Controllers\HomeController.cs:123
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +144
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +84
System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) +89
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +110
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +92
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +71
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +196
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +141
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +65
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +189
System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +717
System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +66
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +71
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +196
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +141
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +65
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +103
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +330
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +71
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +196
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +73
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +58
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +90
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +188
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +196
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +73
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +50
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +68
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +60
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +85
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +196
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +73
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +50
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +58
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +93
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +188
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +196
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +73
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +50
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +58
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +59
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +282