ba4d487c65
Move the pending requests and authorized secrets out of process so the initiate, authorize and exchange legs can land on different replicas.
60 lines
3.2 KiB
C#
60 lines
3.2 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using MediaBrowser.Controller.Authentication;
|
|
using MediaBrowser.Model.QuickConnect;
|
|
|
|
namespace MediaBrowser.Controller.QuickConnect;
|
|
|
|
/// <summary>
|
|
/// Holds the state of in-flight quick connect requests. The three legs of a quick connect flow -
|
|
/// initiate, authorize and exchange - can each land on a different instance, so the state has to be
|
|
/// reachable from all of them.
|
|
/// </summary>
|
|
public interface IQuickConnectStore
|
|
{
|
|
/// <summary>
|
|
/// Looks up a pending request by the secret handed to the initiating client.
|
|
/// </summary>
|
|
/// <param name="secret">The request secret.</param>
|
|
/// <param name="cancellationToken">A cancellation token.</param>
|
|
/// <returns>The request, or <c>null</c> when it is unknown or has expired.</returns>
|
|
Task<QuickConnectResult?> GetRequestBySecretAsync(string secret, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Looks up a pending request by the code shown to the user.
|
|
/// </summary>
|
|
/// <param name="code">The user facing code.</param>
|
|
/// <param name="cancellationToken">A cancellation token.</param>
|
|
/// <returns>The request, or <c>null</c> when it is unknown or has expired.</returns>
|
|
Task<QuickConnectResult?> GetRequestByCodeAsync(string code, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Stores a new or updated request until <paramref name="expiresUtc"/>.
|
|
/// </summary>
|
|
/// <param name="request">The request to store.</param>
|
|
/// <param name="expiresUtc">The instant the request stops being resolvable.</param>
|
|
/// <param name="cancellationToken">A cancellation token.</param>
|
|
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|
Task SetRequestAsync(QuickConnectResult request, DateTime expiresUtc, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Stores the authentication minted for an authorized request until <paramref name="expiresUtc"/>.
|
|
/// </summary>
|
|
/// <param name="secret">The request secret the client exchanges.</param>
|
|
/// <param name="authenticationResult">The authentication to hand out.</param>
|
|
/// <param name="expiresUtc">The instant the authentication stops being exchangeable.</param>
|
|
/// <param name="cancellationToken">A cancellation token.</param>
|
|
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|
Task SetAuthorizationAsync(string secret, AuthenticationResult authenticationResult, DateTime expiresUtc, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Atomically takes the authentication for <paramref name="secret"/> and removes it, so that two
|
|
/// instances racing on the same secret cannot both hand out an access token.
|
|
/// </summary>
|
|
/// <param name="secret">The request secret.</param>
|
|
/// <param name="cancellationToken">A cancellation token.</param>
|
|
/// <returns>The authentication, or <c>null</c> when the secret is unknown, expired or already exchanged.</returns>
|
|
Task<AuthenticationResult?> TryConsumeAuthorizationAsync(string secret, CancellationToken cancellationToken = default);
|
|
}
|