首页 > 解决方案 > “权限不足,无法完成操作。” 尝试以编程方式创建新的 Azure AD 应用程序时

问题描述

我正在尝试以编程方式创建 Azure AD 应用程序(C# 脚本)我已将对 AddApplicationAsync 的调用包装在 try-catch 中

当我运行它时,我收到异常消息“权限不足,无法完成操作。”,

public void CreateNewClientApplication(string pName, Guid pResourceAppId)
        {
            var newClientApp = new Application();
            newClientApp.DisplayName = pName;
            newClientApp.ReplyUrls.Add(CreateDummyReplyUrl(pName));

            newClientApp.PasswordCredentials = new List<PasswordCredential>() {
                new PasswordCredential()
                {
                    Value = "xxxxxxxxx",
                    KeyId = Guid.NewGuid(),
                    StartDate = DateTime.UtcNow,
                    EndDate = DateTime.UtcNow.AddYears(2),
                }
            };

            RequiredResourceAccess resource = new RequiredResourceAccess();
            resource.ResourceAppId = pResourceAppId.ToString();
            newClientApp.RequiredResourceAccess.Add(resource);

            var activeDirectoryClient = AuthenticationHelper.GetActiveDirectoryClientAsApplication();
            try
            {
                activeDirectoryClient.Applications.AddApplicationAsync(newClientApp).Wait();
            }
            catch (Exception ex)
            {
                 // EXCEPTION-MESSAGE: "Insufficient privileges to complete the operation."
            }

        } 

所以我的问题是,需要什么权限? 我有这些

在此处输入图像描述

标签: azure-active-directory

解决方案


推荐阅读