-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,007 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Microsoft.AspNetCore.Identity; | ||
using System.Data; | ||
using System.Security.Claims; | ||
using System; | ||
using Wordle.Api.Models; | ||
|
||
namespace Wordle.Api.Identity; | ||
public static class IdentitySeed | ||
{ | ||
public static async Task SeedAsync(UserManager<AppUser> userManager, RoleManager<IdentityRole> roleManager, WordleDbContext db) | ||
{ | ||
// Seed Roles | ||
await SeedRolesAsync(roleManager); | ||
|
||
// Seed Admin User | ||
await SeedAdminUserAsync(userManager); | ||
} | ||
|
||
private static async Task SeedRolesAsync(RoleManager<IdentityRole> roleManager) | ||
{ | ||
// Seed Roles | ||
if (!await roleManager.RoleExistsAsync(Roles.Admin)) | ||
{ | ||
await roleManager.CreateAsync(new IdentityRole(Roles.Admin)); | ||
} | ||
} | ||
|
||
private static async Task SeedAdminUserAsync(UserManager<AppUser> userManager) | ||
{ | ||
// Seed Admin User | ||
if (await userManager.FindByEmailAsync("[email protected]") == null) | ||
{ | ||
AppUser user = new AppUser | ||
{ | ||
UserName = "[email protected]", | ||
Email = "[email protected]" | ||
}; | ||
|
||
IdentityResult result = userManager.CreateAsync(user, "P@ssw0rd123").Result; | ||
|
||
if (result.Succeeded) | ||
{ | ||
await userManager.AddToRoleAsync(user, Roles.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Wordle.Api.Identity; | ||
public class JwtConfiguration | ||
{ | ||
public required string Secret { get; set; } | ||
public required string Issuer { get; set; } | ||
public required string Audience { get; set; } | ||
public int ExpirationInMinutes { get; set; } = 1440; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace Wordle.Api.Identity; | ||
public static class Roles | ||
{ | ||
public const string Admin = "Admin"; | ||
} |
Oops, something went wrong.