This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
CreateHostBuilder(args).Build().Run(); | |
} | |
public static IHostBuilder CreateHostBuilder(string[] args) => | |
Host.CreateDefaultBuilder(args) | |
.ConfigureWebHostDefaults(webBuilder => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace AzureAdAppRolesWebSample | |
{ | |
public static class AppRoles | |
{ | |
public const string SettingsReader = "settings-reader"; | |
public const string SettingsWriter = "settings-writer"; | |
public const string Admin = "Admin"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Authorization; | |
using Microsoft.AspNetCore.Mvc; | |
using System.Linq; | |
namespace AzureAdAppRolesWebSample.Controllers | |
{ | |
[Authorize] | |
[ApiController] | |
[Route("[controller]")] | |
public class SampleController : ControllerBase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Authentication.JwtBearer; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Hosting; | |
using Microsoft.IdentityModel.Tokens; | |
using System.Net; | |
using System.Text; | |
using System.Threading.Tasks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Graph; | |
using Microsoft.Graph.Auth; | |
using Microsoft.Identity.Client; | |
using System; | |
using System.Collections.Generic; | |
using System.Text.Encodings.Web; | |
using System.Text.Json; | |
using System.Text.Unicode; | |
using System.Threading.Tasks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static GraphServiceClient CreateGraphServiceClient() | |
{ | |
var confidentialClientApplication = ConfidentialClientApplicationBuilder | |
.Create(AppId) | |
.WithTenantId(TenantId) | |
.WithClientSecret(ClientSecret) | |
.Build(); | |
var authProvider = new ClientCredentialProvider(confidentialClientApplication); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
private const string TenantId = ""; | |
private const string AppId = ""; | |
private const string ClientSecret = ""; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ConsoleApp1.Models; | |
using Microsoft.EntityFrameworkCore; | |
using System; | |
using System.Threading.Tasks; | |
namespace ConsoleApp1 | |
{ | |
internal class Program | |
{ | |
private static async Task Main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ConsoleApp1.Models; | |
using Microsoft.EntityFrameworkCore; | |
using System; | |
using System.Threading.Tasks; | |
namespace ConsoleApp1 | |
{ | |
internal class Program | |
{ | |
private static async Task Main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.EntityFrameworkCore; | |
using Microsoft.Extensions.Logging; | |
namespace ConsoleApp1.Models | |
{ | |
public class ItemContext : DbContext | |
{ | |
public DbSet<Item> Items { get; set; } | |
public static readonly ILoggerFactory ItemContextLoggerFactory |