简体   繁体   中英

Updating Azure Application via Microsoft Graph SDK

I am using the Microsoft Graph SDK ( https://github.com/microsoftgraph/msgraph-sdk-dotnet ) in my .NET Core 3.1 project logged in to my Service Principal. I can retrieve the Azure Application's Web Reply URLs:

var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var rootItem = await graphClient.Applications.Request().GetAsync();
Microsoft.Graph.Application app = new Microsoft.Graph.Application();
            foreach (var item in rootItem)
            {
                if (item.DisplayName.Equals("MyApp"))
                {
                    app = item;
                }
            }

I am able to retrieve the actual Application object just fine. My question is, how do I update app.Web.RedirectUris through the SDK? I am able to do so via the Azure CLI with az ad app update --id <my_app_id> --reply-urls <url_1> <url_2>

You need to get an Microsoft.Graph.IApplicationRequestBuilder for the specific Application and then call UpdateAsync() method.

var rootItem = await client.Applications.Request().GetAsync();
Microsoft.Graph.Application app = new Microsoft.Graph.Application();
foreach (var item in rootItem)
{
    if (item.DisplayName.Equals("MyApp"))
    {
        app = item;
        app.Web.RedirectUris = new List<string> { "uri1", "uri2" };
        await client.Applications[app.Id].Request().UpdateAsync(app);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM