ApiKey.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. namespace Jellyfin.Data.Entities.Security
  5. {
  6. /// <summary>
  7. /// An entity representing an API key.
  8. /// </summary>
  9. public class ApiKey
  10. {
  11. /// <summary>
  12. /// Initializes a new instance of the <see cref="ApiKey"/> class.
  13. /// </summary>
  14. /// <param name="name">The name.</param>
  15. public ApiKey(string name)
  16. {
  17. Name = name;
  18. AccessToken = Guid.NewGuid();
  19. DateCreated = DateTime.UtcNow;
  20. }
  21. /// <summary>
  22. /// Gets the id.
  23. /// </summary>
  24. /// <remarks>
  25. /// Identity, Indexed, Required.
  26. /// </remarks>
  27. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  28. public int Id { get; private set; }
  29. /// <summary>
  30. /// Gets or sets the date created.
  31. /// </summary>
  32. public DateTime DateCreated { get; set; }
  33. /// <summary>
  34. /// Gets or sets the date of last activity.
  35. /// </summary>
  36. public DateTime DateLastActivity { get; set; }
  37. /// <summary>
  38. /// Gets or sets the name.
  39. /// </summary>
  40. [MaxLength(64)]
  41. [StringLength(64)]
  42. public string Name { get; set; }
  43. /// <summary>
  44. /// Gets or sets the access token.
  45. /// </summary>
  46. public Guid AccessToken { get; set; }
  47. }
  48. }