Browse Source

Replace IOpenIddictApplicationStore.GetTokensAsync() by IOpenIddictTokenStore.FindByApplicationIdAsync()

pull/500/head
Kévin Chalet 9 years ago
parent
commit
6116ba2d7d
  1. 33
      src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs
  2. 19
      src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs
  3. 47
      src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs
  4. 11
      src/OpenIddict.Core/Stores/IOpenIddictApplicationStore.cs
  5. 11
      src/OpenIddict.Core/Stores/IOpenIddictTokenStore.cs
  6. 40
      src/OpenIddict.Core/Stores/OpenIddictApplicationStore.cs
  7. 21
      src/OpenIddict.Core/Stores/OpenIddictTokenStore.cs

33
src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs

@ -244,8 +244,13 @@ namespace OpenIddict.Core
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation, /// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the client application corresponding to the identifier. /// whose result returns the client application corresponding to the identifier.
/// </returns> /// </returns>
public virtual Task<TApplication> FindByIdAsync(string identifier, CancellationToken cancellationToken) public virtual Task<TApplication> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
return Store.FindByIdAsync(identifier, cancellationToken); return Store.FindByIdAsync(identifier, cancellationToken);
} }
@ -258,8 +263,13 @@ namespace OpenIddict.Core
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation, /// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the client application corresponding to the identifier. /// whose result returns the client application corresponding to the identifier.
/// </returns> /// </returns>
public virtual Task<TApplication> FindByClientIdAsync(string identifier, CancellationToken cancellationToken) public virtual Task<TApplication> FindByClientIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
return Store.FindByClientIdAsync(identifier, cancellationToken); return Store.FindByClientIdAsync(identifier, cancellationToken);
} }
@ -408,25 +418,6 @@ namespace OpenIddict.Core
return Store.GetIdAsync(application, cancellationToken); return Store.GetIdAsync(application, cancellationToken);
} }
/// <summary>
/// Retrieves the token identifiers associated with an application.
/// </summary>
/// <param name="application">The application.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the tokens associated with the application.
/// </returns>
public virtual Task<ImmutableArray<string>> GetTokensAsync([NotNull] TApplication application, CancellationToken cancellationToken)
{
if (application == null)
{
throw new ArgumentNullException(nameof(application));
}
return Store.GetTokensAsync(application, cancellationToken);
}
/// <summary> /// <summary>
/// Determines whether an application is a confidential client. /// Determines whether an application is a confidential client.
/// </summary> /// </summary>

19
src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs

@ -182,8 +182,18 @@ namespace OpenIddict.Core
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation, /// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the authorization corresponding to the subject/client. /// whose result returns the authorization corresponding to the subject/client.
/// </returns> /// </returns>
public virtual Task<TAuthorization> FindAsync(string subject, string client, CancellationToken cancellationToken) public virtual Task<TAuthorization> FindAsync([NotNull] string subject, [NotNull] string client, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(subject))
{
throw new ArgumentException("The subject cannot be null or empty.", nameof(subject));
}
if (string.IsNullOrEmpty(client))
{
throw new ArgumentException("The client identifier cannot be null or empty.", nameof(client));
}
return Store.FindAsync(subject, client, cancellationToken); return Store.FindAsync(subject, client, cancellationToken);
} }
@ -196,8 +206,13 @@ namespace OpenIddict.Core
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation, /// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the authorization corresponding to the identifier. /// whose result returns the authorization corresponding to the identifier.
/// </returns> /// </returns>
public virtual Task<TAuthorization> FindByIdAsync(string identifier, CancellationToken cancellationToken) public virtual Task<TAuthorization> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
return Store.FindByIdAsync(identifier, cancellationToken); return Store.FindByIdAsync(identifier, cancellationToken);
} }

47
src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs

@ -179,6 +179,25 @@ namespace OpenIddict.Core
await UpdateAsync(token, cancellationToken); await UpdateAsync(token, cancellationToken);
} }
/// <summary>
/// Retrieves the list of tokens corresponding to the specified application identifier.
/// </summary>
/// <param name="identifier">The application identifier associated with the tokens.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the tokens corresponding to the specified application.
/// </returns>
public virtual Task<ImmutableArray<TToken>> FindByApplicationIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
return Store.FindByApplicationIdAsync(identifier, cancellationToken);
}
/// <summary> /// <summary>
/// Retrieves the list of tokens corresponding to the specified authorization identifier. /// Retrieves the list of tokens corresponding to the specified authorization identifier.
/// </summary> /// </summary>
@ -188,8 +207,13 @@ namespace OpenIddict.Core
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation, /// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the tokens corresponding to the specified authorization. /// whose result returns the tokens corresponding to the specified authorization.
/// </returns> /// </returns>
public virtual Task<ImmutableArray<TToken>> FindByAuthorizationIdAsync(string identifier, CancellationToken cancellationToken) public virtual Task<ImmutableArray<TToken>> FindByAuthorizationIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
return Store.FindByAuthorizationIdAsync(identifier, cancellationToken); return Store.FindByAuthorizationIdAsync(identifier, cancellationToken);
} }
@ -202,8 +226,13 @@ namespace OpenIddict.Core
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation, /// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the tokens corresponding to the specified hash. /// whose result returns the tokens corresponding to the specified hash.
/// </returns> /// </returns>
public virtual Task<TToken> FindByHashAsync(string hash, CancellationToken cancellationToken) public virtual Task<TToken> FindByHashAsync([NotNull] string hash, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(hash))
{
throw new ArgumentException("The hash cannot be null or empty.", nameof(hash));
}
return Store.FindByHashAsync(hash, cancellationToken); return Store.FindByHashAsync(hash, cancellationToken);
} }
@ -216,8 +245,13 @@ namespace OpenIddict.Core
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation, /// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the token corresponding to the unique identifier. /// whose result returns the token corresponding to the unique identifier.
/// </returns> /// </returns>
public virtual Task<TToken> FindByIdAsync(string identifier, CancellationToken cancellationToken) public virtual Task<TToken> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
return Store.FindByIdAsync(identifier, cancellationToken); return Store.FindByIdAsync(identifier, cancellationToken);
} }
@ -230,8 +264,13 @@ namespace OpenIddict.Core
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation, /// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the tokens corresponding to the specified subject. /// whose result returns the tokens corresponding to the specified subject.
/// </returns> /// </returns>
public virtual Task<ImmutableArray<TToken>> FindBySubjectAsync(string subject, CancellationToken cancellationToken) public virtual Task<ImmutableArray<TToken>> FindBySubjectAsync([NotNull] string subject, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(subject))
{
throw new ArgumentException("The subject cannot be null or empty.", nameof(subject));
}
return Store.FindBySubjectAsync(subject, cancellationToken); return Store.FindBySubjectAsync(subject, cancellationToken);
} }

11
src/OpenIddict.Core/Stores/IOpenIddictApplicationStore.cs

@ -207,17 +207,6 @@ namespace OpenIddict.Core
/// </returns> /// </returns>
Task<ImmutableArray<string>> GetRedirectUrisAsync([NotNull] TApplication application, CancellationToken cancellationToken); Task<ImmutableArray<string>> GetRedirectUrisAsync([NotNull] TApplication application, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the token identifiers associated with an application.
/// </summary>
/// <param name="application">The application.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the tokens associated with the application.
/// </returns>
Task<ImmutableArray<string>> GetTokensAsync([NotNull] TApplication application, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Executes the specified query. /// Executes the specified query.
/// </summary> /// </summary>

11
src/OpenIddict.Core/Stores/IOpenIddictTokenStore.cs

@ -69,6 +69,17 @@ namespace OpenIddict.Core
/// <returns>A <see cref="Task"/> that can be used to monitor the asynchronous operation.</returns> /// <returns>A <see cref="Task"/> that can be used to monitor the asynchronous operation.</returns>
Task DeleteAsync([NotNull] TToken token, CancellationToken cancellationToken); Task DeleteAsync([NotNull] TToken token, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the list of tokens corresponding to the specified application identifier.
/// </summary>
/// <param name="identifier">The application identifier associated with the tokens.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the tokens corresponding to the specified application.
/// </returns>
Task<ImmutableArray<TToken>> FindByApplicationIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Retrieves the list of tokens corresponding to the specified authorization identifier. /// Retrieves the list of tokens corresponding to the specified authorization identifier.
/// </summary> /// </summary>

40
src/OpenIddict.Core/Stores/OpenIddictApplicationStore.cs

@ -411,46 +411,6 @@ namespace OpenIddict.Core
return Task.FromResult(ImmutableArray.Create(uris)); return Task.FromResult(ImmutableArray.Create(uris));
} }
/// <summary>
/// Retrieves the token identifiers associated with an application.
/// </summary>
/// <param name="application">The application.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the tokens associated with the application.
/// </returns>
public virtual async Task<ImmutableArray<string>> GetTokensAsync([NotNull] TApplication application, CancellationToken cancellationToken)
{
if (application == null)
{
throw new ArgumentNullException(nameof(application));
}
IQueryable<TKey> Query(IQueryable<TApplication> applications)
{
return from entity in applications
where entity.Id.Equals(application.Id)
from token in entity.Tokens
select token.Id;
}
var identifiers = await ListAsync(Query, cancellationToken);
if (identifiers.IsDefaultOrEmpty)
{
return ImmutableArray.Create<string>();
}
var builder = ImmutableArray.CreateBuilder<string>(identifiers.Length);
foreach (var identifier in identifiers)
{
builder.Add(ConvertIdentifierToString(identifier));
}
return builder.ToImmutable();
}
/// <summary> /// <summary>
/// Executes the specified query. /// Executes the specified query.
/// </summary> /// </summary>

21
src/OpenIddict.Core/Stores/OpenIddictTokenStore.cs

@ -82,6 +82,27 @@ namespace OpenIddict.Core
/// <returns>A <see cref="Task"/> that can be used to monitor the asynchronous operation.</returns> /// <returns>A <see cref="Task"/> that can be used to monitor the asynchronous operation.</returns>
public abstract Task DeleteAsync([NotNull] TToken token, CancellationToken cancellationToken); public abstract Task DeleteAsync([NotNull] TToken token, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the list of tokens corresponding to the specified application identifier.
/// </summary>
/// <param name="identifier">The application identifier associated with the tokens.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the tokens corresponding to the specified application.
/// </returns>
public virtual Task<ImmutableArray<TToken>> FindByApplicationIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
var key = ConvertIdentifierFromString(identifier);
return ListAsync(tokens => tokens.Where(token => token.Application.Id.Equals(key)), cancellationToken);
}
/// <summary> /// <summary>
/// Retrieves the list of tokens corresponding to the specified authorization identifier. /// Retrieves the list of tokens corresponding to the specified authorization identifier.
/// </summary> /// </summary>

Loading…
Cancel
Save