From 9744c3ba5d49ba8d703efe31b150c804fe2a95d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Tue, 27 Dec 2016 19:29:23 +0100 Subject: [PATCH] Ignore the DbUpdateConcurrencyExceptions thrown when revoking tokens --- .../Stores/IOpenIddictApplicationStore.cs | 13 +++++++------ src/OpenIddict.Core/Stores/IOpenIddictTokenStore.cs | 5 +++-- .../Stores/OpenIddictApplicationStore.cs | 12 ++++++------ .../Stores/OpenIddictTokenStore.cs | 10 +++++++--- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/OpenIddict.Core/Stores/IOpenIddictApplicationStore.cs b/src/OpenIddict.Core/Stores/IOpenIddictApplicationStore.cs index 6c2cf396..873531ce 100644 --- a/src/OpenIddict.Core/Stores/IOpenIddictApplicationStore.cs +++ b/src/OpenIddict.Core/Stores/IOpenIddictApplicationStore.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using JetBrains.Annotations; namespace OpenIddict.Core { /// @@ -23,7 +24,7 @@ namespace OpenIddict.Core { /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the application. /// - Task CreateAsync(TApplication application, CancellationToken cancellationToken); + Task CreateAsync([NotNull] TApplication application, CancellationToken cancellationToken); /// /// Retrieves an application using its unique identifier. @@ -67,7 +68,7 @@ namespace OpenIddict.Core { /// A that can be used to monitor the asynchronous operation, /// whose result returns the client type of the application (by default, "public"). /// - Task GetClientTypeAsync(TApplication application, CancellationToken cancellationToken); + Task GetClientTypeAsync([NotNull] TApplication application, CancellationToken cancellationToken); /// /// Retrieves the display name associated with an application. @@ -78,7 +79,7 @@ namespace OpenIddict.Core { /// A that can be used to monitor the asynchronous operation, /// whose result returns the display name associated with the application. /// - Task GetDisplayNameAsync(TApplication application, CancellationToken cancellationToken); + Task GetDisplayNameAsync([NotNull] TApplication application, CancellationToken cancellationToken); /// /// Retrieves the hashed secret associated with an application. @@ -89,7 +90,7 @@ namespace OpenIddict.Core { /// A that can be used to monitor the asynchronous operation, /// whose result returns the hashed secret associated with the application. /// - Task GetHashedSecretAsync(TApplication application, CancellationToken cancellationToken); + Task GetHashedSecretAsync([NotNull] TApplication application, CancellationToken cancellationToken); /// /// Retrieves the callback address associated with an application. @@ -100,7 +101,7 @@ namespace OpenIddict.Core { /// A that can be used to monitor the asynchronous operation, /// whose result returns the redirect_uri associated with the application. /// - Task GetRedirectUriAsync(TApplication application, CancellationToken cancellationToken); + Task GetRedirectUriAsync([NotNull] TApplication application, CancellationToken cancellationToken); /// /// Retrieves the token identifiers associated with an application. @@ -111,6 +112,6 @@ namespace OpenIddict.Core { /// A that can be used to monitor the asynchronous operation, /// whose result returns the tokens associated with the application. /// - Task> GetTokensAsync(TApplication application, CancellationToken cancellationToken); + Task> GetTokensAsync([NotNull] TApplication application, CancellationToken cancellationToken); } } \ No newline at end of file diff --git a/src/OpenIddict.Core/Stores/IOpenIddictTokenStore.cs b/src/OpenIddict.Core/Stores/IOpenIddictTokenStore.cs index 1cd5088d..057eb55b 100644 --- a/src/OpenIddict.Core/Stores/IOpenIddictTokenStore.cs +++ b/src/OpenIddict.Core/Stores/IOpenIddictTokenStore.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Threading.Tasks; +using JetBrains.Annotations; namespace OpenIddict.Core { /// @@ -22,7 +23,7 @@ namespace OpenIddict.Core { /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the token. /// - Task CreateAsync(string type, CancellationToken cancellationToken); + Task CreateAsync([NotNull] string type, CancellationToken cancellationToken); /// /// Retrieves an token using its unique identifier. @@ -41,6 +42,6 @@ namespace OpenIddict.Core { /// The token to revoke. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - Task RevokeAsync(TToken token, CancellationToken cancellationToken); + Task RevokeAsync([NotNull] TToken token, CancellationToken cancellationToken); } } \ No newline at end of file diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs index 3416cf80..8e981e28 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs @@ -52,7 +52,7 @@ namespace OpenIddict.EntityFrameworkCore { /// The application to create. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - public virtual async Task CreateAsync(TApplication application, CancellationToken cancellationToken) { + public virtual async Task CreateAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { throw new ArgumentNullException(nameof(application)); } @@ -128,7 +128,7 @@ namespace OpenIddict.EntityFrameworkCore { /// A that can be used to monitor the asynchronous operation, /// whose result returns the client type of the application (by default, "public"). /// - public virtual Task GetClientTypeAsync(TApplication application, CancellationToken cancellationToken) { + public virtual Task GetClientTypeAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { throw new ArgumentNullException(nameof(application)); } @@ -145,7 +145,7 @@ namespace OpenIddict.EntityFrameworkCore { /// A that can be used to monitor the asynchronous operation, /// whose result returns the display name associated with the application. /// - public virtual Task GetDisplayNameAsync(TApplication application, CancellationToken cancellationToken) { + public virtual Task GetDisplayNameAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { throw new ArgumentNullException(nameof(application)); } @@ -162,7 +162,7 @@ namespace OpenIddict.EntityFrameworkCore { /// A that can be used to monitor the asynchronous operation, /// whose result returns the hashed secret associated with the application. /// - public virtual Task GetHashedSecretAsync(TApplication application, CancellationToken cancellationToken) { + public virtual Task GetHashedSecretAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { throw new ArgumentNullException(nameof(application)); } @@ -179,7 +179,7 @@ namespace OpenIddict.EntityFrameworkCore { /// A that can be used to monitor the asynchronous operation, /// whose result returns the redirect_uri associated with the application. /// - public virtual Task GetRedirectUriAsync(TApplication application, CancellationToken cancellationToken) { + public virtual Task GetRedirectUriAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { throw new ArgumentNullException(nameof(application)); } @@ -196,7 +196,7 @@ namespace OpenIddict.EntityFrameworkCore { /// A that can be used to monitor the asynchronous operation, /// whose result returns the tokens associated with the application. /// - public virtual async Task> GetTokensAsync(TApplication application, CancellationToken cancellationToken) { + public virtual async Task> GetTokensAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { throw new ArgumentNullException(nameof(application)); } diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs index b2eb1c72..4145db57 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs @@ -53,7 +53,7 @@ namespace OpenIddict.EntityFrameworkCore { /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the token. /// - public virtual async Task CreateAsync(string type, CancellationToken cancellationToken) { + public virtual async Task CreateAsync([NotNull] string type, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(type)) { throw new ArgumentException("The token type cannot be null or empty."); } @@ -100,14 +100,18 @@ namespace OpenIddict.EntityFrameworkCore { /// The token to revoke. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - public virtual Task RevokeAsync(TToken token, CancellationToken cancellationToken) { + public virtual async Task RevokeAsync([NotNull] TToken token, CancellationToken cancellationToken) { if (token == null) { throw new ArgumentNullException(nameof(token)); } Context.Remove(token); - return Context.SaveChangesAsync(cancellationToken); + try { + await Context.SaveChangesAsync(cancellationToken); + } + + catch (DbUpdateConcurrencyException) { } } } } \ No newline at end of file