diff --git a/Jellyfin.Data/Entities/Security/ApiKey.cs b/Jellyfin.Data/Entities/Security/ApiKey.cs
new file mode 100644
index 0000000000..2a3ad09c43
--- /dev/null
+++ b/Jellyfin.Data/Entities/Security/ApiKey.cs
@@ -0,0 +1,50 @@
+using System;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+
+namespace Jellyfin.Data.Entities.Security
+{
+ ///
+ /// An entity representing an API key.
+ ///
+ public class ApiKey
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The name.
+ public ApiKey(string name)
+ {
+ Name = name;
+
+ AccessToken = Guid.NewGuid();
+ DateCreated = DateTime.UtcNow;
+ }
+
+ ///
+ /// Gets the id.
+ ///
+ ///
+ /// Identity, Indexed, Required.
+ ///
+ [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
+ public int Id { get; private set; }
+
+ ///
+ /// Gets the date created.
+ ///
+ public DateTime DateCreated { get; private set; }
+
+ ///
+ /// Gets or sets the name.
+ ///
+ [MaxLength(64)]
+ [StringLength(64)]
+ public string Name { get; set; }
+
+ ///
+ /// Gets or sets the access token.
+ ///
+ public Guid AccessToken { get; set; }
+ }
+}
diff --git a/Jellyfin.Server.Implementations/JellyfinDb.cs b/Jellyfin.Server.Implementations/JellyfinDb.cs
index db648472d1..0559e57833 100644
--- a/Jellyfin.Server.Implementations/JellyfinDb.cs
+++ b/Jellyfin.Server.Implementations/JellyfinDb.cs
@@ -4,6 +4,7 @@
using System;
using System.Linq;
using Jellyfin.Data.Entities;
+using Jellyfin.Data.Entities.Security;
using Jellyfin.Data.Interfaces;
using Microsoft.EntityFrameworkCore;
@@ -29,6 +30,8 @@ namespace Jellyfin.Server.Implementations
public virtual DbSet ActivityLogs { get; set; }
+ public virtual DbSet ApiKeys { get; set; }
+
public virtual DbSet DisplayPreferences { get; set; }
public virtual DbSet ImageInfos { get; set; }
@@ -196,6 +199,10 @@ namespace Jellyfin.Server.Implementations
// Indexes
+ modelBuilder.Entity()
+ .HasIndex(entity => entity.AccessToken)
+ .IsUnique();
+
modelBuilder.Entity()
.HasIndex(entity => entity.Username)
.IsUnique();