This repository has been archived by the owner on Mar 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed template based on the new net 6.0 minimal templates
- Loading branch information
1 parent
7eb45e8
commit ab85e36
Showing
18 changed files
with
122 additions
and
73 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,20 @@ | ||
using BlazorWithIdentity.Client.Services.Contracts; | ||
using BlazorWithIdentity.Client; | ||
using BlazorWithIdentity.Client.Services.Contracts; | ||
using BlazorWithIdentity.Client.Services.Implementations; | ||
using BlazorWithIdentity.Client.States; | ||
using Microsoft.AspNetCore.Components.Web; | ||
using Microsoft.AspNetCore.Components.Authorization; | ||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlazorWithIdentity.Client | ||
{ | ||
public class Program | ||
{ | ||
public static async Task Main(string[] args) | ||
{ | ||
var builder = WebAssemblyHostBuilder.CreateDefault(args); | ||
builder.RootComponents.Add<App>("#app"); | ||
var builder = WebAssemblyHostBuilder.CreateDefault(args); | ||
builder.RootComponents.Add<App>("#app"); | ||
builder.RootComponents.Add<HeadOutlet>("head::after"); | ||
|
||
builder.Services.AddOptions(); | ||
builder.Services.AddAuthorizationCore(); | ||
builder.Services.AddScoped<IdentityAuthenticationStateProvider>(); | ||
builder.Services.AddScoped<AuthenticationStateProvider>(s => s.GetRequiredService<IdentityAuthenticationStateProvider>()); | ||
builder.Services.AddScoped<IAuthorizeApi, AuthorizeApi>(); | ||
builder.Services.AddOptions(); | ||
builder.Services.AddAuthorizationCore(); | ||
builder.Services.AddScoped<IdentityAuthenticationStateProvider>(); | ||
builder.Services.AddScoped<AuthenticationStateProvider>(s => s.GetRequiredService<IdentityAuthenticationStateProvider>()); | ||
builder.Services.AddScoped<IAuthorizeApi, AuthorizeApi>(); | ||
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); | ||
|
||
builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); | ||
|
||
|
||
var host = builder.Build(); | ||
await host.RunAsync(); | ||
} | ||
} | ||
} | ||
await builder.Build().RunAsync(); |
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
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
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
4 changes: 0 additions & 4 deletions
4
template/BlazorWithIdentity.Server/Controllers/SampleDataController.cs
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,82 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace BlazorWithIdentity.Server | ||
using BlazorWithIdentity.Server.Data; | ||
using BlazorWithIdentity.Server.Models; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
builder.Services.AddDbContext<ApplicationDbContext>(options => | ||
options.UseSqlite("Filename=data.db")); | ||
|
||
builder.Services.AddIdentity<ApplicationUser, IdentityRole<Guid>>() | ||
.AddEntityFrameworkStores<ApplicationDbContext>() | ||
.AddDefaultTokenProviders(); | ||
|
||
builder.Services.Configure<IdentityOptions>(options => | ||
{ | ||
// Password settings | ||
options.Password.RequireDigit = true; | ||
options.Password.RequiredLength = 6; | ||
options.Password.RequireNonAlphanumeric = true; | ||
options.Password.RequireUppercase = true; | ||
options.Password.RequireLowercase = false; | ||
|
||
// Lockout settings | ||
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); | ||
options.Lockout.MaxFailedAccessAttempts = 10; | ||
options.Lockout.AllowedForNewUsers = true; | ||
|
||
// User settings | ||
options.User.RequireUniqueEmail = false; | ||
}); | ||
|
||
builder.Services.ConfigureApplicationCookie(options => | ||
{ | ||
options.Cookie.HttpOnly = true; | ||
options.Events.OnRedirectToLogin = context => | ||
{ | ||
context.Response.StatusCode = 401; | ||
return Task.CompletedTask; | ||
}; | ||
}); | ||
|
||
|
||
builder.Services.AddControllersWithViews(); | ||
builder.Services.AddRazorPages(); | ||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
public class Program | ||
using (var serviceScope = app.Services.GetRequiredService<IServiceScopeFactory>().CreateScope()) | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
//Note: Microsoft recommends to NOT migrate your database at Startup. | ||
//You should consider your migration strategy according to the guidelines | ||
serviceScope.ServiceProvider.GetService<ApplicationDbContext>().Database.Migrate(); | ||
} | ||
|
||
app.UseWebAssemblyDebugging(); | ||
} | ||
else | ||
{ | ||
app.UseExceptionHandler("/Error"); | ||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. | ||
app.UseHsts(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseBlazorFrameworkFiles(); | ||
app.UseStaticFiles(); | ||
|
||
app.UseRouting(); | ||
app.UseAuthentication(); | ||
app.UseAuthorization(); | ||
|
||
app.MapRazorPages(); | ||
app.MapControllers(); | ||
app.MapFallbackToFile("index.html"); | ||
|
||
app.Run(); |
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
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
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
Binary file not shown.
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