var newApp = new Application{ DisplayName = "My Application", SignInAudience = "AzureADMyOrg", RequiredResourceAccess = new List<RequiredResourceAccess> { new RequiredResourceAccess { ResourceAppId = "00000003-0000-0000-c000-000000000000", // Microsoft Graph ResourceAccess = new List<ResourceAccess> { new ResourceAccess { Id = Guid.Parse("e1fe6dd8-ba31-4d61-89e7-88639da4683d"), // User.Read Type = "Scope" }, new ResourceAccess { Id = Guid.Parse("df021288-bdef-4463-88db-98f22de89214"), // User.Read.All Type = "Role" } } } }, Web = new WebApplication { RedirectUris = new List<string> { "https://localhost:5001/signin-oidc" }, ImplicitGrantSettings = new ImplicitGrantSettings { EnableIdTokenIssuance = true } }, Api = new ApiApplication { Oauth2PermissionScopes = new List<PermissionScope> { new PermissionScope { AdminConsentDescription = "Allow app to read data", AdminConsentDisplayName = "Read data", Id = Guid.NewGuid(), IsEnabled = true, Type = "User", UserConsentDescription = "Allow app to read your data", UserConsentDisplayName = "Read your data", Value = "Data.Read" } } }};var app = await graphClient.Applications.PostAsync(newApp);Console.WriteLine($"Created app: {app.AppId}");
var owners = await graphClient.Applications["object-id"].Owners.GetAsync();foreach (var owner in owners.Value){ if (owner is User user) { Console.WriteLine($"Owner: {user.DisplayName}"); }}
var ownerRef = new ReferenceCreate{ OdataId = $"https://graph.microsoft.com/v1.0/users/{userId}"};await graphClient.Applications["object-id"].Owners.Ref.PostAsync(ownerRef);
var webApp = new Application{ DisplayName = "My Web App", SignInAudience = "AzureADMultipleOrgs", Web = new WebApplication { RedirectUris = new List<string> { "https://myapp.com/signin-oidc", "https://myapp.com/signout-callback-oidc" }, LogoutUrl = "https://myapp.com/signout-oidc" }};var app = await graphClient.Applications.PostAsync(webApp);
var spaApp = new Application{ DisplayName = "My SPA", SignInAudience = "AzureADandPersonalMicrosoftAccount", Spa = new SpaApplication { RedirectUris = new List<string> { "http://localhost:3000", "https://myspa.com" } }, RequiredResourceAccess = new List<RequiredResourceAccess> { new RequiredResourceAccess { ResourceAppId = "00000003-0000-0000-c000-000000000000", ResourceAccess = new List<ResourceAccess> { new ResourceAccess { Id = Guid.Parse("e1fe6dd8-ba31-4d61-89e7-88639da4683d"), Type = "Scope" } } } }};
var nativeApp = new Application{ DisplayName = "My Mobile App", SignInAudience = "AzureADandPersonalMicrosoftAccount", PublicClient = new PublicClientApplication { RedirectUris = new List<string> { "msauth.com.mycompany.myapp://auth", "http://localhost" } }, IsFallbackPublicClient = true};