public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); services.AddApplicationInsightsTelemetry(Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"]); services.AddServerSideBlazor() .AddHubOptions(options => { // Increase the limits to 256 kB options.MaximumReceiveMessageSize = 262144; }); services.AddControllers(); services.AddHostedService <TreeServiceWarmUp>(); services.AddSingleton <GitHubClientFactory>(); services.AddSingleton <TreeService>(); services.AddSingleton <AzureDevOpsTreeProvider>(); services.AddSingleton <GitHubTreeProvider>(); services.AddBlazoredLocalStorage(); services.AddResponseCompression(options => { // State changes are sent via WebSockets not via request or cookie values options.EnableForHttps = true; // Only compress text/html options.MimeTypes = new[] { "text/html" }; }); services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; }) .AddCookie(options => { options.LoginPath = "/signin"; options.LogoutPath = "/signout"; }) .AddGitHub(options => { options.ClientId = Configuration["GitHubClientId"]; options.ClientSecret = Configuration["GitHubClientSecret"]; options.ClaimActions.MapJsonKey(ThemesOfDotNetConstants.GitHubAvatarUrl, ThemesOfDotNetConstants.GitHubAvatarUrl); options.Events.OnCreatingTicket = async context => { var accessToken = context.AccessToken; var orgName = ThemesOfDotNetConstants.ProductTeamOrg; var teamName = ThemesOfDotNetConstants.ProductTeamSlug; var userName = context.Identity.Name; var isMember = await GitHubAuthHelpers.IsMemberOfTeamAsync(accessToken, orgName, teamName, userName); if (isMember) { context.Identity.AddClaim(new Claim(context.Identity.RoleClaimType, ThemesOfDotNetConstants.ProductTeamRole)); } }; }); }
public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); services.AddServerSideBlazor(); services.AddControllers(); services.AddHostedService <TreeServiceWarmUp>(); services.AddSingleton <GitHubClientFactory>(); services.AddSingleton <TreeService>(); services.AddSingleton <AzureDevOpsTreeProvider>(); services.AddSingleton <GitHubTreeProvider>(); services.AddBlazoredLocalStorage(); services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; }) .AddCookie(options => { options.LoginPath = "/signin"; options.LogoutPath = "/signout"; }) .AddGitHub(options => { options.ClientId = Configuration["GitHubClientId"]; options.ClientSecret = Configuration["GitHubClientSecret"]; options.ClaimActions.MapJsonKey(ThemesOfDotNetConstants.GitHubAvatarUrl, ThemesOfDotNetConstants.GitHubAvatarUrl); options.Events.OnCreatingTicket = async context => { var accessToken = context.AccessToken; var orgName = ThemesOfDotNetConstants.ProductTeamOrg; var teamName = ThemesOfDotNetConstants.ProductTeamSlug; var userName = context.Identity.Name; var isMember = await GitHubAuthHelpers.IsMemberOfTeamAsync(accessToken, orgName, teamName, userName); if (isMember) { context.Identity.AddClaim(new Claim(context.Identity.RoleClaimType, ThemesOfDotNetConstants.ProductTeamRole)); } }; }); }