简体   繁体   English

通过 C# 更新 Azure AD 应用程序

[英]Updating Azure AD Application via C#

I have an already existing Azure AD Application.我有一个已经存在的 Azure AD 应用程序。 I would like to be able to update it via C# code, just like I do via the Azure CLI.我希望能够通过 C# 代码对其进行更新,就像我通过 Azure CLI 一样。 All I need is to add two new reply URLs to the application.我只需要向应用程序添加两个新的回复 URL。

With the Azure CLI I use:使用 Azure CLI 我使用:

az ad app update --id <my_app_id> --reply-urls <url_1> <url_2>

How can I get the equivalent but within C# code?如何在 C# 代码中获得等效项? I've found that the Azure SDK does not provide such a functionality, or at least I couldn't find it.我发现 Azure SDK 没有提供这样的功能,或者至少我找不到。 I have a Service Principal which I want this operation done through.我有一个服务主体,我希望通过它完成此操作。

Here's one solution I came up with, turns out you can use System.Diagnostics.Process to invoke CMD.exe via C# and use the cli through there:这是我想出的一个解决方案,原来您可以使用System.Diagnostics.Process通过 C# 调用 CMD.exe 并通过那里使用 cli:

string strCmdText;
            strCmdText = "/C az login --service-principal -u <client_id> -p <client_secret> --tenant <tenant_id>";
            System.Diagnostics.Process.Start("CMD.exe", strCmdText);
            System.Diagnostics.Process.Start("CMD.exe", "/C az ad app update --id <app_id> --reply-urls https://testfromcsharp.com/");

and it worked.它奏效了。

You can use this graph api to update your azure ad appliction.您可以使用此图 api来更新您的 azure 广告应用程序。 And pls note that the application id used in the request url is the object id of the azure ad application but not the application id.请注意,请求 url 中使用的application id是 azure 广告应用的 object id,而不是应用 id。

在此处输入图像描述

You can first call Get https://graph.microsoft.com/v1.0/applications/object_id_here first to get the current web claim of this app, that should be similar to您可以先调用Get https://graph.microsoft.com/v1.0/applications/object_id_here以获取此应用程序的当前web声明,应该类似于

{
    "web": {
        "homePageUrl": null,
        "logoutUrl": null,
        "redirectUris": [
            "http://localhost:3000"
        ],
        "implicitGrantSettings": {
            "enableAccessTokenIssuance": true,
            "enableIdTokenIssuance": true
        }
    }
}

Then you modify the redirectUris property with all the urls you wanna set to the application, pls note this update will cover all the original redirect urls.然后你用你想设置给应用程序的所有 url 修改redirectUris属性,请注意这个更新将覆盖所有原始重定向 url。 Then copy the json content and call the PATCH request to update the api.然后复制json内容并调用PATCH请求更新api。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用C#控制台应用程序查询Azure AD - Querying Azure AD using c# console application 使用 Azure AD 并在 C# Windows 应用程序中获取应用程序角色 - Using Azure AD and Getting App Role in C# Windows Application 如何在多租户应用中通过C#以编程方式切换Azure AD目录 - How to switch Azure AD directory programatically via C# in a multi tenant app 通过GRAPH更新Azure AD中的用户时出现Json序列化错误 - Json serialization error when updating user in Azure AD via GRAPH C#代码的Azure AD授权问题 - Azure AD Authorization issue with c# code 是否可以通过C#在Azure AD中管理用户配置文件? - Is it possible to manage userprofiles in azure AD by c#? 无法在 C# 中获取 Azure AD 令牌 - Not able to get Azure AD token in C# 有没有办法通过控制台应用程序C#连接启用了Azure AD MFA的Outlook邮箱? - Is there a way to connect Azure AD MFA enabled outlook mailbox through a console application C#? 使用C#中的Azure AD Graph API向已创建的应用程序添加角色 - Add role to already created application using Azure AD Graph API in C# Azure AD应用程序-如何从C#或Powershell设置一些参数? - Azure AD Application - how to set some parameters from C# or Powershell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM