IQuickConnect.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using MediaBrowser.Model.QuickConnect;
  4. using MediaBrowser.Model.Services;
  5. namespace MediaBrowser.Controller.QuickConnect
  6. {
  7. /// <summary>
  8. /// Quick connect standard interface.
  9. /// </summary>
  10. public interface IQuickConnect
  11. {
  12. /// <summary>
  13. /// Gets or sets the length of user facing codes.
  14. /// </summary>
  15. public int CodeLength { get; set; }
  16. /// <summary>
  17. /// Gets or sets the string to prefix internal access tokens with.
  18. /// </summary>
  19. public string TokenNamePrefix { get; set; }
  20. /// <summary>
  21. /// Gets the current state of quick connect.
  22. /// </summary>
  23. public QuickConnectState State { get; }
  24. /// <summary>
  25. /// Gets or sets the time (in minutes) before quick connect will automatically deactivate.
  26. /// </summary>
  27. public int Timeout { get; set; }
  28. /// <summary>
  29. /// Assert that quick connect is currently active and throws an exception if it is not.
  30. /// </summary>
  31. void AssertActive();
  32. /// <summary>
  33. /// Temporarily activates quick connect for a short amount of time.
  34. /// </summary>
  35. void Activate();
  36. /// <summary>
  37. /// Changes the status of quick connect.
  38. /// </summary>
  39. /// <param name="newState">New state to change to.</param>
  40. void SetEnabled(QuickConnectState newState);
  41. /// <summary>
  42. /// Initiates a new quick connect request.
  43. /// </summary>
  44. /// <param name="friendlyName">Friendly device name to display in the request UI.</param>
  45. /// <returns>A quick connect result with tokens to proceed or a descriptive error message otherwise.</returns>
  46. QuickConnectResult TryConnect(string friendlyName);
  47. /// <summary>
  48. /// Checks the status of an individual request.
  49. /// </summary>
  50. /// <param name="secret">Unique secret identifier of the request.</param>
  51. /// <returns>Quick connect result.</returns>
  52. QuickConnectResult CheckRequestStatus(string secret);
  53. /// <summary>
  54. /// Authorizes a quick connect request to connect as the calling user.
  55. /// </summary>
  56. /// <param name="request">HTTP request object.</param>
  57. /// <param name="code">Identifying code for the request.</param>
  58. /// <returns>A boolean indicating if the authorization completed successfully.</returns>
  59. bool AuthorizeRequest(IRequest request, string code);
  60. /// <summary>
  61. /// Expire quick connect requests that are over the time limit. If <paramref name="expireAll"/> is true, all requests are unconditionally expired.
  62. /// </summary>
  63. /// <param name="expireAll">If true, all requests will be expired.</param>
  64. public void ExpireRequests(bool expireAll = false);
  65. /// <summary>
  66. /// Deletes all quick connect access tokens for the provided user.
  67. /// </summary>
  68. /// <param name="user">Guid of the user to delete tokens for.</param>
  69. /// <returns>A count of the deleted tokens.</returns>
  70. int DeleteAllDevices(Guid user);
  71. /// <summary>
  72. /// Generates a short code to display to the user to uniquely identify this request.
  73. /// </summary>
  74. /// <returns>A short, unique alphanumeric string.</returns>
  75. string GenerateCode();
  76. }
  77. }