Browse Source

Ignore the DbUpdateConcurrencyExceptions thrown when revoking tokens

pull/307/head
Kévin Chalet 9 years ago
parent
commit
9744c3ba5d
  1. 13
      src/OpenIddict.Core/Stores/IOpenIddictApplicationStore.cs
  2. 5
      src/OpenIddict.Core/Stores/IOpenIddictTokenStore.cs
  3. 12
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs
  4. 10
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs

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

@ -7,6 +7,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations;
namespace OpenIddict.Core { namespace OpenIddict.Core {
/// <summary> /// <summary>
@ -23,7 +24,7 @@ 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 unique identifier associated with the application. /// whose result returns the unique identifier associated with the application.
/// </returns> /// </returns>
Task<string> CreateAsync(TApplication application, CancellationToken cancellationToken); Task<string> CreateAsync([NotNull] TApplication application, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Retrieves an application using its unique identifier. /// Retrieves an application using its unique identifier.
@ -67,7 +68,7 @@ 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 type of the application (by default, "public"). /// whose result returns the client type of the application (by default, "public").
/// </returns> /// </returns>
Task<string> GetClientTypeAsync(TApplication application, CancellationToken cancellationToken); Task<string> GetClientTypeAsync([NotNull] TApplication application, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Retrieves the display name associated with an application. /// Retrieves the display name associated with an application.
@ -78,7 +79,7 @@ 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 display name associated with the application. /// whose result returns the display name associated with the application.
/// </returns> /// </returns>
Task<string> GetDisplayNameAsync(TApplication application, CancellationToken cancellationToken); Task<string> GetDisplayNameAsync([NotNull] TApplication application, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Retrieves the hashed secret associated with an application. /// Retrieves the hashed secret associated with an application.
@ -89,7 +90,7 @@ 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 hashed secret associated with the application. /// whose result returns the hashed secret associated with the application.
/// </returns> /// </returns>
Task<string> GetHashedSecretAsync(TApplication application, CancellationToken cancellationToken); Task<string> GetHashedSecretAsync([NotNull] TApplication application, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Retrieves the callback address associated with an application. /// Retrieves the callback address associated with an application.
@ -100,7 +101,7 @@ 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 redirect_uri associated with the application. /// whose result returns the redirect_uri associated with the application.
/// </returns> /// </returns>
Task<string> GetRedirectUriAsync(TApplication application, CancellationToken cancellationToken); Task<string> GetRedirectUriAsync([NotNull] TApplication application, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Retrieves the token identifiers associated with an application. /// Retrieves the token identifiers associated with an application.
@ -111,6 +112,6 @@ 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 associated with the application. /// whose result returns the tokens associated with the application.
/// </returns> /// </returns>
Task<IEnumerable<string>> GetTokensAsync(TApplication application, CancellationToken cancellationToken); Task<IEnumerable<string>> GetTokensAsync([NotNull] TApplication application, CancellationToken cancellationToken);
} }
} }

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

@ -6,6 +6,7 @@
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations;
namespace OpenIddict.Core { namespace OpenIddict.Core {
/// <summary> /// <summary>
@ -22,7 +23,7 @@ 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 unique identifier associated with the token. /// whose result returns the unique identifier associated with the token.
/// </returns> /// </returns>
Task<string> CreateAsync(string type, CancellationToken cancellationToken); Task<string> CreateAsync([NotNull] string type, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Retrieves an token using its unique identifier. /// Retrieves an token using its unique identifier.
@ -41,6 +42,6 @@ namespace OpenIddict.Core {
/// <param name="token">The token to revoke.</param> /// <param name="token">The token to revoke.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</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.</returns> /// <returns>A <see cref="Task"/> that can be used to monitor the asynchronous operation.</returns>
Task RevokeAsync(TToken token, CancellationToken cancellationToken); Task RevokeAsync([NotNull] TToken token, CancellationToken cancellationToken);
} }
} }

12
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs

@ -52,7 +52,7 @@ namespace OpenIddict.EntityFrameworkCore {
/// <param name="application">The application to create.</param> /// <param name="application">The application to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</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.</returns> /// <returns>A <see cref="Task"/> that can be used to monitor the asynchronous operation.</returns>
public virtual async Task<string> CreateAsync(TApplication application, CancellationToken cancellationToken) { public virtual async Task<string> CreateAsync([NotNull] TApplication application, CancellationToken cancellationToken) {
if (application == null) { if (application == null) {
throw new ArgumentNullException(nameof(application)); throw new ArgumentNullException(nameof(application));
} }
@ -128,7 +128,7 @@ namespace OpenIddict.EntityFrameworkCore {
/// 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 type of the application (by default, "public"). /// whose result returns the client type of the application (by default, "public").
/// </returns> /// </returns>
public virtual Task<string> GetClientTypeAsync(TApplication application, CancellationToken cancellationToken) { public virtual Task<string> GetClientTypeAsync([NotNull] TApplication application, CancellationToken cancellationToken) {
if (application == null) { if (application == null) {
throw new ArgumentNullException(nameof(application)); throw new ArgumentNullException(nameof(application));
} }
@ -145,7 +145,7 @@ namespace OpenIddict.EntityFrameworkCore {
/// 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 display name associated with the application. /// whose result returns the display name associated with the application.
/// </returns> /// </returns>
public virtual Task<string> GetDisplayNameAsync(TApplication application, CancellationToken cancellationToken) { public virtual Task<string> GetDisplayNameAsync([NotNull] TApplication application, CancellationToken cancellationToken) {
if (application == null) { if (application == null) {
throw new ArgumentNullException(nameof(application)); throw new ArgumentNullException(nameof(application));
} }
@ -162,7 +162,7 @@ namespace OpenIddict.EntityFrameworkCore {
/// 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 hashed secret associated with the application. /// whose result returns the hashed secret associated with the application.
/// </returns> /// </returns>
public virtual Task<string> GetHashedSecretAsync(TApplication application, CancellationToken cancellationToken) { public virtual Task<string> GetHashedSecretAsync([NotNull] TApplication application, CancellationToken cancellationToken) {
if (application == null) { if (application == null) {
throw new ArgumentNullException(nameof(application)); throw new ArgumentNullException(nameof(application));
} }
@ -179,7 +179,7 @@ namespace OpenIddict.EntityFrameworkCore {
/// 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 redirect_uri associated with the application. /// whose result returns the redirect_uri associated with the application.
/// </returns> /// </returns>
public virtual Task<string> GetRedirectUriAsync(TApplication application, CancellationToken cancellationToken) { public virtual Task<string> GetRedirectUriAsync([NotNull] TApplication application, CancellationToken cancellationToken) {
if (application == null) { if (application == null) {
throw new ArgumentNullException(nameof(application)); throw new ArgumentNullException(nameof(application));
} }
@ -196,7 +196,7 @@ namespace OpenIddict.EntityFrameworkCore {
/// 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 associated with the application. /// whose result returns the tokens associated with the application.
/// </returns> /// </returns>
public virtual async Task<IEnumerable<string>> GetTokensAsync(TApplication application, CancellationToken cancellationToken) { public virtual async Task<IEnumerable<string>> GetTokensAsync([NotNull] TApplication application, CancellationToken cancellationToken) {
if (application == null) { if (application == null) {
throw new ArgumentNullException(nameof(application)); throw new ArgumentNullException(nameof(application));
} }

10
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs

@ -53,7 +53,7 @@ namespace OpenIddict.EntityFrameworkCore {
/// 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 unique identifier associated with the token. /// whose result returns the unique identifier associated with the token.
/// </returns> /// </returns>
public virtual async Task<string> CreateAsync(string type, CancellationToken cancellationToken) { public virtual async Task<string> CreateAsync([NotNull] string type, CancellationToken cancellationToken) {
if (string.IsNullOrEmpty(type)) { if (string.IsNullOrEmpty(type)) {
throw new ArgumentException("The token type cannot be null or empty."); throw new ArgumentException("The token type cannot be null or empty.");
} }
@ -100,14 +100,18 @@ namespace OpenIddict.EntityFrameworkCore {
/// <param name="token">The token to revoke.</param> /// <param name="token">The token to revoke.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</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.</returns> /// <returns>A <see cref="Task"/> that can be used to monitor the asynchronous operation.</returns>
public virtual Task RevokeAsync(TToken token, CancellationToken cancellationToken) { public virtual async Task RevokeAsync([NotNull] TToken token, CancellationToken cancellationToken) {
if (token == null) { if (token == null) {
throw new ArgumentNullException(nameof(token)); throw new ArgumentNullException(nameof(token));
} }
Context.Remove(token); Context.Remove(token);
return Context.SaveChangesAsync(cancellationToken); try {
await Context.SaveChangesAsync(cancellationToken);
}
catch (DbUpdateConcurrencyException) { }
} }
} }
} }
Loading…
Cancel
Save