ApiKey.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 the date created.
  31. /// </summary>
  32. public DateTime DateCreated { get; private set; }
  33. /// <summary>
  34. /// Gets or sets the name.
  35. /// </summary>
  36. [MaxLength(64)]
  37. [StringLength(64)]
  38. public string Name { get; set; }
  39. /// <summary>
  40. /// Gets or sets the access token.
  41. /// </summary>
  42. public Guid AccessToken { get; set; }
  43. }
  44. }