-
- I need to register the app from Graph API.
- Add permission to an app, Microsoft Graph, and application permission.
- Grant the application permissions.
All these three steps need to done from Graph API.
The first step is done below: Application gets created and we get the application id:
'16147e04-136b-4ea8-a45d-1cc2d9d0e0af'
string tenentId = "!!!!!!!!!-f8a6-4418-b062-26ad5b6608dd";
string clientId = "!!!!!!!!-6beb-4a9c-bdc2-0092bc7feaae";
string clientScret = "!!!!!!Huo3cUHtOOCHp1iNTSRQ7w9rDUlpRl6aqv";
var accessTokenProvider = new BaseBearerTokenAuthenticationProvider(new TokenProvider());
var graphServiceClient = new GraphServiceClient(accessTokenProvider);
var requestBody = new Application
{
DisplayName = "01N",
Description="This app is created from Graph API"
};
var result = await graphServiceClient.Applications.PostAsync(requestBody);
Problem: Not able to get this created app using below code:
string clientScret = "!!!!!!Huo3cUHtOOCHp1iNTSRQ7w9rDUlpRl6aqv";
// OnBehalfOfCredential onBehalfOf = new OnBehalfOfCredential(tenentId, clientId, clientScret, token);
var accessTokenProvider = new BaseBearerTokenAuthenticationProvider(new TokenProvider());
var graphServiceClient = new GraphServiceClient(accessTokenProvider);
// var result = await graphServiceClient.ServicePrincipals.GetAsync();
var result = await graphServiceClient.ServicePrincipals.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Filter = "appId eq '16147e04-136b-4ea8-a45d-1cc2d9d0e0af'";
requestConfiguration.QueryParameters.Select = new string[] { "appId", "oauth2PermissionScopes" , "displayName", "appRoles" };
// requestConfiguration.QueryParameters.Select = new string[] { "id", "displayName", "appId", "appRoles", "oauth2PermissionScopes" };
});
The response we are getting:
{
"value": [],
"additionalData": {
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#servicePrincipals(appId,oauth2PermissionScopes,displayName,appRoles)"
},
"backingStore": {
"initializationCompleted": true,
"returnOnlyChangedValues": false
},
"odataCount": null,
"odataNextLink": null
}
Q1. How to add API permission inside created an application for Microsoft Graph: Application Permission?