Home > Enterprise >  Updating Azure AD Application via C#
Updating Azure AD Application via C#

Time:12-01

I have an already existing Azure AD Application. I would like to be able to update it via C# code, just like I do via the Azure CLI. All I need is to add two new reply URLs to the application.

With the Azure CLI I use:

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

How can I get the equivalent but within C# code? I've found that the Azure SDK does not provide such a functionality, or at least I couldn't find it. I have a Service Principal which I want this operation done through.

CodePudding user response:

You can use this enter image description here

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

{
    "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. Then copy the json content and call the PATCH request to update the api.

enter image description here

CodePudding user response:

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:

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.

EDIT: The best solution was to use the Microsoft Graph SDK within my .NET project and authenticate/invoke functions through it. https://docs.microsoft.com/en-us/graph/sdks/sdks-overview

  • Related