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>
CodePudding user response:
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);
}
}