Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,775 questions
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?
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.