ApiKey.cs 1.5 KB

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