Microsoft Security | Microsoft Graph
An API that connects multiple Microsoft services, enabling data access and automation across platforms
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm trying to register new app using GraphServiceClient, but it fails
app = ConfidentialClientApplicationBuilder.Create(config.ClientId)
.WithCertificate(certificate)
.WithAuthority(new Uri(config.Authority))
.Build();
var authProvider = new ClientCredentialProvider(app, $"{config.ApiUrl}.default");
var client = new GraphServiceClient(config.ApiUrl, authProvider)
var application = new Application
{
DisplayName = "test"
};
Application created = await client.Applications.Request().AddAsync(application);
this last call throws an exception - Method not allowed.
But I'm able to register an application by calling API using JWT token, so I believe that config properties are correct.
string[] scopes = new string[] { $"{config.ApiUrl}.default" };
AuthenticationResult result = await app.AcquireTokenForClient(scopes)
.WithSendX5C(true)
.ExecuteAsync();
...
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
HttpResponseMessage response = await httpClient.PostAsync($"{config.ApiUrl}v1.0/applications", content);
What do I miss for using GraphServiceClient?
An API that connects multiple Microsoft services, enabling data access and automation across platforms
Answer accepted by question author
For creating GraphServiceClient object I needed also to append v1.0 to url.
var client = new GraphServiceClient(config.ApiUrl + "v1.0", authProvider) // https://graph.microsoft.com/v1.0
Now it works.