35 changed files with 1344 additions and 186 deletions
@ -0,0 +1,4 @@
@@ -0,0 +1,4 @@
|
||||
{ |
||||
"version": "5.1.0", |
||||
"hash": "37fc3ca56005b7eca9143ae4c74f4163e9417856" |
||||
} |
@ -0,0 +1,4 @@
@@ -0,0 +1,4 @@
|
||||
{ |
||||
"version": "{{git_ver}}", |
||||
"hash": "{{git_hash}}" |
||||
} |
@ -1,11 +1,40 @@
@@ -1,11 +1,40 @@
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System.Linq; |
||||
using Teknik.IdentityServer.Models; |
||||
using Teknik.Utilities.Attributes; |
||||
|
||||
namespace Teknik.IdentityServer |
||||
{ |
||||
public class ApplicationDbContext : IdentityDbContext<ApplicationUser> |
||||
{ |
||||
public DbSet<AuthToken> AuthTokens { get; set; } |
||||
|
||||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { } |
||||
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder) |
||||
{ |
||||
base.OnModelCreating(modelBuilder); |
||||
|
||||
// User
|
||||
modelBuilder.Entity<ApplicationUser>().HasMany(u => u.AuthTokens).WithOne(t => t.ApplicationUser).HasForeignKey(t => t.ApplicationUserId); |
||||
|
||||
// Auth Tokens
|
||||
modelBuilder.Entity<AuthToken>().ToTable("AuthTokens"); |
||||
|
||||
// Custom Attributes
|
||||
foreach (var entityType in modelBuilder.Model.GetEntityTypes()) |
||||
{ |
||||
foreach (var property in entityType.GetProperties()) |
||||
{ |
||||
var attributes = property?.PropertyInfo?.GetCustomAttributes(typeof(CaseSensitiveAttribute), false); |
||||
if (attributes != null && attributes.Any()) |
||||
{ |
||||
property.SetAnnotation("CaseSensitive", true); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,328 @@
@@ -0,0 +1,328 @@
|
||||
// <auto-generated />
|
||||
using System; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using Microsoft.EntityFrameworkCore.Infrastructure; |
||||
using Microsoft.EntityFrameworkCore.Metadata; |
||||
using Microsoft.EntityFrameworkCore.Migrations; |
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
||||
using Teknik.IdentityServer; |
||||
|
||||
namespace Teknik.IdentityServer.Data.Migrations.ApplicationDb |
||||
{ |
||||
[DbContext(typeof(ApplicationDbContext))] |
||||
[Migration("20211206044736_AuthToken")] |
||||
partial class AuthToken |
||||
{ |
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder) |
||||
{ |
||||
#pragma warning disable 612, 618
|
||||
modelBuilder |
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128) |
||||
.HasAnnotation("ProductVersion", "5.0.7") |
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); |
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => |
||||
{ |
||||
b.Property<string>("Id") |
||||
.HasColumnType("nvarchar(450)"); |
||||
|
||||
b.Property<string>("ConcurrencyStamp") |
||||
.IsConcurrencyToken() |
||||
.HasColumnType("nvarchar(max)"); |
||||
|
||||
b.Property<string>("Name") |
||||
.HasMaxLength(256) |
||||
.HasColumnType("nvarchar(256)"); |
||||
|
||||
b.Property<string>("NormalizedName") |
||||
.HasMaxLength(256) |
||||
.HasColumnType("nvarchar(256)"); |
||||
|
||||
b.HasKey("Id"); |
||||
|
||||
b.HasIndex("NormalizedName") |
||||
.IsUnique() |
||||
.HasDatabaseName("RoleNameIndex") |
||||
.HasFilter("[NormalizedName] IS NOT NULL"); |
||||
|
||||
b.ToTable("AspNetRoles"); |
||||
}); |
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b => |
||||
{ |
||||
b.Property<int>("Id") |
||||
.ValueGeneratedOnAdd() |
||||
.HasColumnType("int") |
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); |
||||
|
||||
b.Property<string>("ClaimType") |
||||
.HasColumnType("nvarchar(max)"); |
||||
|
||||
b.Property<string>("ClaimValue") |
||||
.HasColumnType("nvarchar(max)"); |
||||
|
||||
b.Property<string>("RoleId") |
||||
.IsRequired() |
||||
.HasColumnType("nvarchar(450)"); |
||||
|
||||
b.HasKey("Id"); |
||||
|
||||
b.HasIndex("RoleId"); |
||||
|
||||
b.ToTable("AspNetRoleClaims"); |
||||
}); |
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b => |
||||
{ |
||||
b.Property<int>("Id") |
||||
.ValueGeneratedOnAdd() |
||||
.HasColumnType("int") |
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); |
||||
|
||||
b.Property<string>("ClaimType") |
||||
.HasColumnType("nvarchar(max)"); |
||||
|
||||
b.Property<string>("ClaimValue") |
||||
.HasColumnType("nvarchar(max)"); |
||||
|
||||
b.Property<string>("UserId") |
||||
.IsRequired() |
||||
.HasColumnType("nvarchar(450)"); |
||||
|
||||
b.HasKey("Id"); |
||||
|
||||
b.HasIndex("UserId"); |
||||
|
||||
b.ToTable("AspNetUserClaims"); |
||||
}); |
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b => |
||||
{ |
||||
b.Property<string>("LoginProvider") |
||||
.HasColumnType("nvarchar(450)"); |
||||
|
||||
b.Property<string>("ProviderKey") |
||||
.HasColumnType("nvarchar(450)"); |
||||
|
||||
b.Property<string>("ProviderDisplayName") |
||||
.HasColumnType("nvarchar(max)"); |
||||
|
||||
b.Property<string>("UserId") |
||||
.IsRequired() |
||||
.HasColumnType("nvarchar(450)"); |
||||
|
||||
b.HasKey("LoginProvider", "ProviderKey"); |
||||
|
||||
b.HasIndex("UserId"); |
||||
|
||||
b.ToTable("AspNetUserLogins"); |
||||
}); |
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b => |
||||
{ |
||||
b.Property<string>("UserId") |
||||
.HasColumnType("nvarchar(450)"); |
||||
|
||||
b.Property<string>("RoleId") |
||||
.HasColumnType("nvarchar(450)"); |
||||
|
||||
b.HasKey("UserId", "RoleId"); |
||||
|
||||
b.HasIndex("RoleId"); |
||||
|
||||
b.ToTable("AspNetUserRoles"); |
||||
}); |
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b => |
||||
{ |
||||
b.Property<string>("UserId") |
||||
.HasColumnType("nvarchar(450)"); |
||||
|
||||
b.Property<string>("LoginProvider") |
||||
.HasColumnType("nvarchar(450)"); |
||||
|
||||
b.Property<string>("Name") |
||||
.HasColumnType("nvarchar(450)"); |
||||
|
||||
b.Property<string>("Value") |
||||
.HasColumnType("nvarchar(max)"); |
||||
|
||||
b.HasKey("UserId", "LoginProvider", "Name"); |
||||
|
||||
b.ToTable("AspNetUserTokens"); |
||||
}); |
||||
|
||||
modelBuilder.Entity("Teknik.IdentityServer.Models.ApplicationUser", b => |
||||
{ |
||||
b.Property<string>("Id") |
||||
.HasColumnType("nvarchar(450)"); |
||||
|
||||
b.Property<int>("AccessFailedCount") |
||||
.HasColumnType("int"); |
||||
|
||||
b.Property<int>("AccountStatus") |
||||
.HasColumnType("int"); |
||||
|
||||
b.Property<int>("AccountType") |
||||
.HasColumnType("int"); |
||||
|
||||
b.Property<string>("ConcurrencyStamp") |
||||
.IsConcurrencyToken() |
||||
.HasColumnType("nvarchar(max)"); |
||||
|
||||
b.Property<DateTime>("CreationDate") |
||||
.HasColumnType("datetime2"); |
||||
|
||||
b.Property<string>("Email") |
||||
.HasMaxLength(256) |
||||
.HasColumnType("nvarchar(256)"); |
||||
|
||||
b.Property<bool>("EmailConfirmed") |
||||
.HasColumnType("bit"); |
||||
|
||||
b.Property<DateTime>("LastEdit") |
||||
.HasColumnType("datetime2"); |
||||
|
||||
b.Property<DateTime>("LastSeen") |
||||
.HasColumnType("datetime2"); |
||||
|
||||
b.Property<bool>("LockoutEnabled") |
||||
.HasColumnType("bit"); |
||||
|
||||
b.Property<DateTimeOffset?>("LockoutEnd") |
||||
.HasColumnType("datetimeoffset"); |
||||
|
||||
b.Property<string>("NormalizedEmail") |
||||
.HasMaxLength(256) |
||||
.HasColumnType("nvarchar(256)"); |
||||
|
||||
b.Property<string>("NormalizedUserName") |
||||
.HasMaxLength(256) |
||||
.HasColumnType("nvarchar(256)"); |
||||
|
||||
b.Property<string>("PGPPublicKey") |
||||
.HasColumnType("nvarchar(max)"); |
||||
|
||||
b.Property<string>("PasswordHash") |
||||
.HasColumnType("nvarchar(max)"); |
||||
|
||||
b.Property<string>("PhoneNumber") |
||||
.HasColumnType("nvarchar(max)"); |
||||
|
||||
b.Property<bool>("PhoneNumberConfirmed") |
||||
.HasColumnType("bit"); |
||||
|
||||
b.Property<string>("SecurityStamp") |
||||
.HasColumnType("nvarchar(max)"); |
||||
|
||||
b.Property<bool>("TwoFactorEnabled") |
||||
.HasColumnType("bit"); |
||||
|
||||
b.Property<string>("UserName") |
||||
.HasMaxLength(256) |
||||
.HasColumnType("nvarchar(256)"); |
||||
|
||||
b.HasKey("Id"); |
||||
|
||||
b.HasIndex("NormalizedEmail") |
||||
.HasDatabaseName("EmailIndex"); |
||||
|
||||
b.HasIndex("NormalizedUserName") |
||||
.IsUnique() |
||||
.HasDatabaseName("UserNameIndex") |
||||
.HasFilter("[NormalizedUserName] IS NOT NULL"); |
||||
|
||||
b.ToTable("AspNetUsers"); |
||||
}); |
||||
|
||||
modelBuilder.Entity("Teknik.IdentityServer.Models.AuthToken", b => |
||||
{ |
||||
b.Property<Guid>("AuthTokenId") |
||||
.ValueGeneratedOnAdd() |
||||
.HasColumnType("uniqueidentifier"); |
||||
|
||||
b.Property<string>("ApplicationUserId") |
||||
.HasColumnType("nvarchar(450)"); |
||||
|
||||
b.Property<string>("Name") |
||||
.HasColumnType("nvarchar(max)"); |
||||
|
||||
b.Property<string>("Token") |
||||
.HasColumnType("nvarchar(max)") |
||||
.HasAnnotation("CaseSensitive", true); |
||||
|
||||
b.HasKey("AuthTokenId"); |
||||
|
||||
b.HasIndex("ApplicationUserId"); |
||||
|
||||
b.ToTable("AuthTokens"); |
||||
}); |
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b => |
||||
{ |
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) |
||||
.WithMany() |
||||
.HasForeignKey("RoleId") |
||||
.OnDelete(DeleteBehavior.Cascade) |
||||
.IsRequired(); |
||||
}); |
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b => |
||||
{ |
||||
b.HasOne("Teknik.IdentityServer.Models.ApplicationUser", null) |
||||
.WithMany() |
||||
.HasForeignKey("UserId") |
||||
.OnDelete(DeleteBehavior.Cascade) |
||||
.IsRequired(); |
||||
}); |
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b => |
||||
{ |
||||
b.HasOne("Teknik.IdentityServer.Models.ApplicationUser", null) |
||||
.WithMany() |
||||
.HasForeignKey("UserId") |
||||
.OnDelete(DeleteBehavior.Cascade) |
||||
.IsRequired(); |
||||
}); |
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b => |
||||
{ |
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) |
||||
.WithMany() |
||||
.HasForeignKey("RoleId") |
||||
.OnDelete(DeleteBehavior.Cascade) |
||||
.IsRequired(); |
||||
|
||||
b.HasOne("Teknik.IdentityServer.Models.ApplicationUser", null) |
||||
.WithMany() |
||||
.HasForeignKey("UserId") |
||||
.OnDelete(DeleteBehavior.Cascade) |
||||
.IsRequired(); |
||||
}); |
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b => |
||||
{ |
||||
b.HasOne("Teknik.IdentityServer.Models.ApplicationUser", null) |
||||
.WithMany() |
||||
.HasForeignKey("UserId") |
||||
.OnDelete(DeleteBehavior.Cascade) |
||||
.IsRequired(); |
||||
}); |
||||
|
||||
modelBuilder.Entity("Teknik.IdentityServer.Models.AuthToken", b => |
||||
{ |
||||
b.HasOne("Teknik.IdentityServer.Models.ApplicationUser", "ApplicationUser") |
||||
.WithMany("AuthTokens") |
||||
.HasForeignKey("ApplicationUserId"); |
||||
|
||||
b.Navigation("ApplicationUser"); |
||||
}); |
||||
|
||||
modelBuilder.Entity("Teknik.IdentityServer.Models.ApplicationUser", b => |
||||
{ |
||||
b.Navigation("AuthTokens"); |
||||
}); |
||||
#pragma warning restore 612, 618
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
using System; |
||||
using Microsoft.EntityFrameworkCore.Migrations; |
||||
|
||||
namespace Teknik.IdentityServer.Data.Migrations.ApplicationDb |
||||
{ |
||||
public partial class AuthToken : Migration |
||||
{ |
||||
protected override void Up(MigrationBuilder migrationBuilder) |
||||
{ |
||||
migrationBuilder.CreateTable( |
||||
name: "AuthTokens", |
||||
columns: table => new |
||||
{ |
||||
AuthTokenId = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: true), |
||||
ApplicationUserId = table.Column<string>(type: "nvarchar(450)", nullable: true), |
||||
Token = table.Column<string>(type: "nvarchar(max)", nullable: true) |
||||
}, |
||||
constraints: table => |
||||
{ |
||||
table.PrimaryKey("PK_AuthTokens", x => x.AuthTokenId); |
||||
table.ForeignKey( |
||||
name: "FK_AuthTokens_AspNetUsers_ApplicationUserId", |
||||
column: x => x.ApplicationUserId, |
||||
principalTable: "AspNetUsers", |
||||
principalColumn: "Id", |
||||
onDelete: ReferentialAction.Restrict); |
||||
}); |
||||
|
||||
migrationBuilder.CreateIndex( |
||||
name: "IX_AuthTokens_ApplicationUserId", |
||||
table: "AuthTokens", |
||||
column: "ApplicationUserId"); |
||||
} |
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder) |
||||
{ |
||||
migrationBuilder.DropTable( |
||||
name: "AuthTokens"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
using System; |
||||
using System.Text.Json.Serialization; |
||||
using Teknik.Utilities.Attributes; |
||||
|
||||
namespace Teknik.IdentityServer.Models |
||||
{ |
||||
public class AuthToken |
||||
{ |
||||
public Guid AuthTokenId { get; set; } |
||||
|
||||
public string Name { get; set; } |
||||
|
||||
[JsonIgnore] |
||||
public string ApplicationUserId { get; set; } |
||||
|
||||
|
||||
[JsonIgnore] |
||||
public virtual ApplicationUser ApplicationUser { get; set; } |
||||
|
||||
[JsonIgnore] |
||||
[CaseSensitive] |
||||
public string Token { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace Teknik.IdentityServer.Models.Manage |
||||
{ |
||||
public class CreateAuthTokenModel |
||||
{ |
||||
public string Username { get; set; } |
||||
public string Name { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace Teknik.IdentityServer.Models.Manage |
||||
{ |
||||
public class DeleteAuthTokenModel |
||||
{ |
||||
public string AuthTokenId { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,10 @@
@@ -0,0 +1,10 @@
|
||||
using System; |
||||
|
||||
namespace Teknik.IdentityServer.Models.Manage |
||||
{ |
||||
public class EditAuthTokenModel |
||||
{ |
||||
public string AuthTokenId { get; set; } |
||||
public string Name { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
using System; |
||||
using Teknik.Utilities.Attributes; |
||||
|
||||
namespace Teknik.Areas.Users.Models |
||||
{ |
||||
public class AuthToken |
||||
{ |
||||
public string AuthTokenId { get; set; } |
||||
|
||||
public string Name { get; set; } |
||||
|
||||
public string Token { get; set; } |
||||
|
||||
public DateTime? LastUsed { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic; |
||||
|
||||
namespace Teknik.Areas.Users.ViewModels |
||||
{ |
||||
public class AuthTokenSettingsViewModel : SettingsViewModel |
||||
{ |
||||
public List<AuthTokenViewModel> AuthTokens { get; set; } |
||||
|
||||
public AuthTokenSettingsViewModel() |
||||
{ |
||||
AuthTokens = new List<AuthTokenViewModel>(); |
||||
} |
||||
} |
||||
} |