diff --git a/src/OpenIddict.Abstractions/OpenIddictConstants.cs b/src/OpenIddict.Abstractions/OpenIddictConstants.cs
index 3ca574d1..6337b175 100644
--- a/src/OpenIddict.Abstractions/OpenIddictConstants.cs
+++ b/src/OpenIddict.Abstractions/OpenIddictConstants.cs
@@ -118,11 +118,6 @@ namespace OpenIddict.Abstractions
public const string UnsupportedTokenType = "unsupported_token_type";
}
- public static class Exceptions
- {
- public const string ConcurrencyError = "concurrency_error";
- }
-
public static class GrantTypes
{
public const string AuthorizationCode = "authorization_code";
diff --git a/src/OpenIddict.Abstractions/OpenIddictException.cs b/src/OpenIddict.Abstractions/OpenIddictException.cs
deleted file mode 100644
index 564873c2..00000000
--- a/src/OpenIddict.Abstractions/OpenIddictException.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-using System;
-
-namespace OpenIddict.Abstractions
-{
- ///
- /// Represents an OpenIddict exception.
- ///
- public class OpenIddictException : Exception
- {
- ///
- /// Creates a new .
- ///
- /// The reason of the exception.
- /// The exception message.
- public OpenIddictException(string reason, string message)
- : base(message)
- {
- Reason = reason;
- }
-
- ///
- /// Creates a new .
- ///
- /// The reason of the exception.
- /// The exception message.
- /// The inner exception.
- public OpenIddictException(string reason, string message, Exception innerException)
- : base(message, innerException)
- {
- Reason = reason;
- }
-
- ///
- /// Gets the reason that caused the exception to be thrown.
- ///
- public string Reason { get; }
- }
-}
diff --git a/src/OpenIddict.Abstractions/OpenIddictExceptions.cs b/src/OpenIddict.Abstractions/OpenIddictExceptions.cs
new file mode 100644
index 00000000..b9d65650
--- /dev/null
+++ b/src/OpenIddict.Abstractions/OpenIddictExceptions.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Collections.Immutable;
+using System.ComponentModel.DataAnnotations;
+
+namespace OpenIddict.Abstractions
+{
+ ///
+ /// Exposes common exceptions thrown by OpenIddict.
+ ///
+ public static class OpenIddictExceptions
+ {
+ ///
+ /// Represents an OpenIddict concurrency exception.
+ ///
+ public class ConcurrencyException : Exception
+ {
+ ///
+ /// Creates a new .
+ ///
+ /// The exception message.
+ public ConcurrencyException(string message)
+ : this(message, exception: null)
+ {
+ }
+
+ ///
+ /// Creates a new .
+ ///
+ /// The exception message.
+ /// The inner exception.
+ public ConcurrencyException(string message, Exception exception)
+ : base(message, exception)
+ {
+ }
+ }
+
+ ///
+ /// Represents an OpenIddict validation exception.
+ ///
+ public class ValidationException : Exception
+ {
+ ///
+ /// Creates a new .
+ ///
+ /// The exception message.
+ public ValidationException(string message)
+ : this(message, ImmutableArray.Create())
+ {
+ }
+
+ ///
+ /// Creates a new .
+ ///
+ /// The exception message.
+ /// The validation results.
+ public ValidationException(string message, ImmutableArray results)
+ : this(message, results, exception: null)
+ {
+ }
+
+ ///
+ /// Creates a new .
+ ///
+ /// The exception message.
+ /// The validation results.
+ /// The inner exception.
+ public ValidationException(string message, ImmutableArray results, Exception exception)
+ : base(message, exception)
+ {
+ Results = results;
+ }
+
+ ///
+ /// Gets the validation results associated with this exception.
+ ///
+ public ImmutableArray Results { get; }
+ }
+ }
+}
diff --git a/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs b/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs
index ee9dbf30..d6dda21a 100644
--- a/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs
+++ b/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs
@@ -8,6 +8,7 @@ using System;
using System.Collections.Immutable;
using System.ComponentModel.DataAnnotations;
using System.Linq;
+using System.Text;
using System.Threading;
using System.Threading.Tasks;
using CryptoHelper;
@@ -126,14 +127,6 @@ namespace OpenIddict.Core
OpenIddictConstants.ClientTypes.Confidential, cancellationToken);
}
- // If the client is not a public application, throw an
- // exception as the client secret is required in this case.
- if (string.IsNullOrEmpty(secret) && !await IsPublicAsync(application, cancellationToken))
- {
- throw new InvalidOperationException("A client secret must be provided when creating " +
- "a confidential or hybrid application.");
- }
-
// If a client secret was provided, obfuscate it.
if (!string.IsNullOrEmpty(secret))
{
@@ -144,7 +137,16 @@ namespace OpenIddict.Core
var results = await ValidateAsync(application, cancellationToken);
if (results.Any(result => result != ValidationResult.Success))
{
- throw new ValidationException(results.FirstOrDefault(result => result != ValidationResult.Success), null, application);
+ var builder = new StringBuilder();
+ builder.AppendLine("One or more validation error(s) occurred while trying to create a new application:");
+ builder.AppendLine();
+
+ foreach (var result in results)
+ {
+ builder.AppendLine(result.ErrorMessage);
+ }
+
+ throw new OpenIddictExceptions.ValidationException(builder.ToString(), results);
}
@@ -427,23 +429,7 @@ namespace OpenIddict.Core
throw new ArgumentNullException(nameof(application));
}
- async Task ResolveClientTypeAsync()
- {
- var type = await Store.GetClientTypeAsync(application, cancellationToken);
-
- // Ensure the application type returned by the store is supported by the manager.
- if (!string.Equals(type, OpenIddictConstants.ClientTypes.Confidential, StringComparison.OrdinalIgnoreCase) &&
- !string.Equals(type, OpenIddictConstants.ClientTypes.Hybrid, StringComparison.OrdinalIgnoreCase) &&
- !string.Equals(type, OpenIddictConstants.ClientTypes.Public, StringComparison.OrdinalIgnoreCase))
- {
- throw new InvalidOperationException("Only 'confidential', 'hybrid' or 'public' applications are " +
- "supported by the default application manager.");
- }
-
- return type;
- }
-
- return new ValueTask(ResolveClientTypeAsync());
+ return Store.GetClientTypeAsync(application, cancellationToken);
}
///
@@ -840,7 +826,16 @@ namespace OpenIddict.Core
var results = await ValidateAsync(application, cancellationToken);
if (results.Any(result => result != ValidationResult.Success))
{
- throw new ValidationException(results.FirstOrDefault(result => result != ValidationResult.Success), null, application);
+ var builder = new StringBuilder();
+ builder.AppendLine("One or more validation error(s) occurred while trying to update an existing application:");
+ builder.AppendLine();
+
+ foreach (var result in results)
+ {
+ builder.AppendLine(result.ErrorMessage);
+ }
+
+ throw new OpenIddictExceptions.ValidationException(builder.ToString(), results);
}
await Store.UpdateAsync(application, cancellationToken);
@@ -1022,56 +1017,6 @@ namespace OpenIddict.Core
}
}
- var permissions = await Store.GetPermissionsAsync(application, cancellationToken);
- if (permissions.Contains(OpenIddictConstants.Permissions.GrantTypes.AuthorizationCode))
- {
- if (!permissions.Contains(OpenIddictConstants.Permissions.Endpoints.Authorization) &&
- permissions.Any(permission => permission.StartsWith(OpenIddictConstants.Permissions.Prefixes.Endpoint)))
- {
- builder.Add(new ValidationResult(
- "The authorization code flow permission requires adding the authorization endpoint permission."));
- }
-
- if (!permissions.Contains(OpenIddictConstants.Permissions.Endpoints.Token) &&
- permissions.Any(permission => permission.StartsWith(OpenIddictConstants.Permissions.Prefixes.Endpoint)))
- {
- builder.Add(new ValidationResult(
- "The authorization code flow permission requires adding the token endpoint permission."));
- }
- }
-
- if (permissions.Contains(OpenIddictConstants.Permissions.GrantTypes.ClientCredentials) &&
- !permissions.Contains(OpenIddictConstants.Permissions.Endpoints.Token) &&
- permissions.Any(permission => permission.StartsWith(OpenIddictConstants.Permissions.Prefixes.Endpoint)))
- {
- builder.Add(new ValidationResult(
- "The client credentials flow permission requires adding the token endpoint permission."));
- }
-
- if (permissions.Contains(OpenIddictConstants.Permissions.GrantTypes.Implicit) &&
- !permissions.Contains(OpenIddictConstants.Permissions.Endpoints.Authorization) &&
- permissions.Any(permission => permission.StartsWith(OpenIddictConstants.Permissions.Prefixes.Endpoint)))
- {
- builder.Add(new ValidationResult(
- "The implicit flow permission requires adding the authorization endpoint permission."));
- }
-
- if (permissions.Contains(OpenIddictConstants.Permissions.GrantTypes.Password) &&
- !permissions.Contains(OpenIddictConstants.Permissions.Endpoints.Token) &&
- permissions.Any(permission => permission.StartsWith(OpenIddictConstants.Permissions.Prefixes.Endpoint)))
- {
- builder.Add(new ValidationResult(
- "The password flow permission requires adding the token endpoint permission."));
- }
-
- if (permissions.Contains(OpenIddictConstants.Permissions.GrantTypes.RefreshToken) &&
- !permissions.Contains(OpenIddictConstants.Permissions.Endpoints.Token) &&
- permissions.Any(permission => permission.StartsWith(OpenIddictConstants.Permissions.Prefixes.Endpoint)))
- {
- builder.Add(new ValidationResult(
- "The refresh token flow permission requires adding the token endpoint permission."));
- }
-
return builder.Count == builder.Capacity ?
builder.MoveToImmutable() :
builder.ToImmutable();
diff --git a/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs b/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs
index 26d5bb83..79b78ec0 100644
--- a/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs
+++ b/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs
@@ -9,6 +9,7 @@ using System.Collections.Immutable;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Security.Claims;
+using System.Text;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
@@ -105,7 +106,16 @@ namespace OpenIddict.Core
var results = await ValidateAsync(authorization, cancellationToken);
if (results.Any(result => result != ValidationResult.Success))
{
- throw new ValidationException(results.FirstOrDefault(result => result != ValidationResult.Success), null, authorization);
+ var builder = new StringBuilder();
+ builder.AppendLine("One or more validation error(s) occurred while trying to create a new authorization:");
+ builder.AppendLine();
+
+ foreach (var result in results)
+ {
+ builder.AppendLine(result.ErrorMessage);
+ }
+
+ throw new OpenIddictExceptions.ValidationException(builder.ToString(), results);
}
await Store.CreateAsync(authorization, cancellationToken);
@@ -976,7 +986,16 @@ namespace OpenIddict.Core
var results = await ValidateAsync(authorization, cancellationToken);
if (results.Any(result => result != ValidationResult.Success))
{
- throw new ValidationException(results.FirstOrDefault(result => result != ValidationResult.Success), null, authorization);
+ var builder = new StringBuilder();
+ builder.AppendLine("One or more validation error(s) occurred while trying to update an existing authorization:");
+ builder.AppendLine();
+
+ foreach (var result in results)
+ {
+ builder.AppendLine(result.ErrorMessage);
+ }
+
+ throw new OpenIddictExceptions.ValidationException(builder.ToString(), results);
}
await Store.UpdateAsync(authorization, cancellationToken);
diff --git a/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs b/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs
index b0a76f9b..7e481815 100644
--- a/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs
+++ b/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs
@@ -9,6 +9,7 @@ using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.DataAnnotations;
using System.Linq;
+using System.Text;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
@@ -99,7 +100,16 @@ namespace OpenIddict.Core
var results = await ValidateAsync(scope, cancellationToken);
if (results.Any(result => result != ValidationResult.Success))
{
- throw new ValidationException(results.FirstOrDefault(result => result != ValidationResult.Success), null, scope);
+ var builder = new StringBuilder();
+ builder.AppendLine("One or more validation error(s) occurred while trying to create a new scope:");
+ builder.AppendLine();
+
+ foreach (var result in results)
+ {
+ builder.AppendLine(result.ErrorMessage);
+ }
+
+ throw new OpenIddictExceptions.ValidationException(builder.ToString(), results);
}
await Store.CreateAsync(scope, cancellationToken);
@@ -592,7 +602,16 @@ namespace OpenIddict.Core
var results = await ValidateAsync(scope, cancellationToken);
if (results.Any(result => result != ValidationResult.Success))
{
- throw new ValidationException(results.FirstOrDefault(result => result != ValidationResult.Success), null, scope);
+ var builder = new StringBuilder();
+ builder.AppendLine("One or more validation error(s) occurred while trying to update an existing scope:");
+ builder.AppendLine();
+
+ foreach (var result in results)
+ {
+ builder.AppendLine(result.ErrorMessage);
+ }
+
+ throw new OpenIddictExceptions.ValidationException(builder.ToString(), results);
}
await Store.UpdateAsync(scope, cancellationToken);
diff --git a/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs b/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs
index 6b932b31..0a1ff9b1 100644
--- a/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs
+++ b/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs
@@ -106,7 +106,16 @@ namespace OpenIddict.Core
var results = await ValidateAsync(token, cancellationToken);
if (results.Any(result => result != ValidationResult.Success))
{
- throw new ValidationException(results.FirstOrDefault(result => result != ValidationResult.Success), null, token);
+ var builder = new StringBuilder();
+ builder.AppendLine("One or more validation error(s) occurred while trying to create a new token:");
+ builder.AppendLine();
+
+ foreach (var result in results)
+ {
+ builder.AppendLine(result.ErrorMessage);
+ }
+
+ throw new OpenIddictExceptions.ValidationException(builder.ToString(), results);
}
await Store.CreateAsync(token, cancellationToken);
@@ -1035,7 +1044,16 @@ namespace OpenIddict.Core
var results = await ValidateAsync(token, cancellationToken);
if (results.Any(result => result != ValidationResult.Success))
{
- throw new ValidationException(results.FirstOrDefault(result => result != ValidationResult.Success), null, token);
+ var builder = new StringBuilder();
+ builder.AppendLine("One or more validation error(s) occurred while trying to update an existing token:");
+ builder.AppendLine();
+
+ foreach (var result in results)
+ {
+ builder.AppendLine(result.ErrorMessage);
+ }
+
+ throw new OpenIddictExceptions.ValidationException(builder.ToString(), results);
}
await Store.UpdateAsync(token, cancellationToken);
diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs
index 2fa3d0da..3f36f56b 100644
--- a/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs
+++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs
@@ -221,7 +221,7 @@ namespace OpenIddict.EntityFramework
catch (DbUpdateConcurrencyException exception)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The application was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the application from the database and retry the operation.")
.ToString(), exception);
@@ -978,7 +978,7 @@ namespace OpenIddict.EntityFramework
catch (DbUpdateConcurrencyException exception)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The application was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the application from the database and retry the operation.")
.ToString(), exception);
diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs
index da315e4d..24a9ea58 100644
--- a/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs
+++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs
@@ -203,7 +203,7 @@ namespace OpenIddict.EntityFramework
catch (DbUpdateConcurrencyException exception)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The authorization was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the authorization from the database and retry the operation.")
.ToString(), exception);
@@ -1008,7 +1008,7 @@ namespace OpenIddict.EntityFramework
catch (DbUpdateConcurrencyException exception)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The authorization was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the authorization from the database and retry the operation.")
.ToString(), exception);
diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs
index f7617b7c..512a1446 100644
--- a/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs
+++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs
@@ -155,7 +155,7 @@ namespace OpenIddict.EntityFramework
catch (DbUpdateConcurrencyException exception)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The scope was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the scope from the database and retry the operation.")
.ToString(), exception);
@@ -659,7 +659,7 @@ namespace OpenIddict.EntityFramework
catch (DbUpdateConcurrencyException exception)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The scope was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the scope from the database and retry the operation.")
.ToString(), exception);
diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs
index 1fc62c77..05f76e44 100644
--- a/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs
+++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs
@@ -173,7 +173,7 @@ namespace OpenIddict.EntityFramework
catch (DbUpdateConcurrencyException exception)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The token was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the token from the database and retry the operation.")
.ToString(), exception);
@@ -1190,7 +1190,7 @@ namespace OpenIddict.EntityFramework
catch (DbUpdateConcurrencyException exception)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The token was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the token from the database and retry the operation.")
.ToString(), exception);
diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs
index 0e856dd6..353a058a 100644
--- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs
+++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs
@@ -264,7 +264,7 @@ namespace OpenIddict.EntityFrameworkCore
catch (DbUpdateConcurrencyException exception)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The application was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the application from the database and retry the operation.")
.ToString(), exception);
@@ -1021,7 +1021,7 @@ namespace OpenIddict.EntityFrameworkCore
catch (DbUpdateConcurrencyException exception)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The application was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the application from the database and retry the operation.")
.ToString(), exception);
diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs
index 77a3d95a..8245cd25 100644
--- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs
+++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs
@@ -240,7 +240,7 @@ namespace OpenIddict.EntityFrameworkCore
catch (DbUpdateConcurrencyException exception)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The authorization was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the authorization from the database and retry the operation.")
.ToString(), exception);
@@ -1067,7 +1067,7 @@ namespace OpenIddict.EntityFrameworkCore
catch (DbUpdateConcurrencyException exception)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The authorization was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the authorization from the database and retry the operation.")
.ToString(), exception);
diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs
index af4a19f5..e869d482 100644
--- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs
+++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs
@@ -172,7 +172,7 @@ namespace OpenIddict.EntityFrameworkCore
catch (DbUpdateConcurrencyException exception)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The scope was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the scope from the database and retry the operation.")
.ToString(), exception);
@@ -676,7 +676,7 @@ namespace OpenIddict.EntityFrameworkCore
catch (DbUpdateConcurrencyException exception)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The scope was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the scope from the database and retry the operation.")
.ToString(), exception);
diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs
index 1432b1c8..013890c2 100644
--- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs
+++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs
@@ -194,7 +194,7 @@ namespace OpenIddict.EntityFrameworkCore
catch (DbUpdateConcurrencyException exception)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The token was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the token from the database and retry the operation.")
.ToString(), exception);
@@ -1228,7 +1228,7 @@ namespace OpenIddict.EntityFrameworkCore
catch (DbUpdateConcurrencyException exception)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The token was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the token from the database and retry the operation.")
.ToString(), exception);
diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs
index 3bb980d6..dee64213 100644
--- a/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs
+++ b/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs
@@ -137,7 +137,7 @@ namespace OpenIddict.MongoDb
entity.Id == application.Id &&
entity.ConcurrencyToken == application.ConcurrencyToken)).DeletedCount == 0)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The application was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the application from the database and retry the operation.")
.ToString());
@@ -821,7 +821,7 @@ namespace OpenIddict.MongoDb
entity.Id == application.Id &&
entity.ConcurrencyToken == timestamp, application, null, cancellationToken)).MatchedCount == 0)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The application was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the application from the database and retry the operation.")
.ToString());
diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs
index 7ecbeec1..5171f88a 100644
--- a/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs
+++ b/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs
@@ -137,7 +137,7 @@ namespace OpenIddict.MongoDb
entity.Id == authorization.Id &&
entity.ConcurrencyToken == authorization.ConcurrencyToken)).DeletedCount == 0)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The authorization was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the authorization from the database and retry the operation.")
.ToString());
@@ -885,7 +885,7 @@ namespace OpenIddict.MongoDb
entity.Id == authorization.Id &&
entity.ConcurrencyToken == timestamp, authorization, null, cancellationToken)).MatchedCount == 0)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The authorization was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the authorization from the database and retry the operation.")
.ToString());
diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs
index 301c631a..5c094c1a 100644
--- a/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs
+++ b/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs
@@ -137,7 +137,7 @@ namespace OpenIddict.MongoDb
entity.Id == scope.Id &&
entity.ConcurrencyToken == scope.ConcurrencyToken)).DeletedCount == 0)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The scope was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the scope from the database and retry the operation.")
.ToString());
@@ -618,7 +618,7 @@ namespace OpenIddict.MongoDb
entity.Id == scope.Id &&
entity.ConcurrencyToken == timestamp, scope, null, cancellationToken)).MatchedCount == 0)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The scope was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the scope from the database and retry the operation.")
.ToString());
diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs
index 53974c1d..8029871e 100644
--- a/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs
+++ b/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs
@@ -137,7 +137,7 @@ namespace OpenIddict.MongoDb
entity.Id == token.Id &&
entity.ConcurrencyToken == token.ConcurrencyToken)).DeletedCount == 0)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The token was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the token from the database and retry the operation.")
.ToString());
@@ -999,7 +999,7 @@ namespace OpenIddict.MongoDb
entity.Id == token.Id &&
entity.ConcurrencyToken == timestamp, token, null, cancellationToken)).MatchedCount == 0)
{
- throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder()
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
.AppendLine("The token was concurrently updated and cannot be persisted in its current state.")
.Append("Reload the token from the database and retry the operation.")
.ToString());
diff --git a/src/OpenIddict.Server/Internal/OpenIddictServerProvider.Helpers.cs b/src/OpenIddict.Server/Internal/OpenIddictServerProvider.Helpers.cs
index bcb8299c..5c43a13b 100644
--- a/src/OpenIddict.Server/Internal/OpenIddictServerProvider.Helpers.cs
+++ b/src/OpenIddict.Server/Internal/OpenIddictServerProvider.Helpers.cs
@@ -409,7 +409,7 @@ namespace OpenIddict.Server.Internal
return true;
}
- catch (OpenIddictException exception) when (exception.Reason == OpenIddictConstants.Exceptions.ConcurrencyError)
+ catch (OpenIddictExceptions.ConcurrencyException exception)
{
logger.LogDebug(0, exception, "A concurrency exception occurred while trying to revoke the authorization " +
"associated with the token '{Identifier}'.", identifier);
@@ -445,7 +445,7 @@ namespace OpenIddict.Server.Internal
return true;
}
- catch (OpenIddictException exception) when (exception.Reason == OpenIddictConstants.Exceptions.ConcurrencyError)
+ catch (OpenIddictExceptions.ConcurrencyException exception)
{
logger.LogDebug(0, exception, "A concurrency exception occurred while trying to revoke the token '{Identifier}'.", identifier);
@@ -507,7 +507,7 @@ namespace OpenIddict.Server.Internal
return true;
}
- catch (OpenIddictException exception) when (exception.Reason == OpenIddictConstants.Exceptions.ConcurrencyError)
+ catch (OpenIddictExceptions.ConcurrencyException exception)
{
logger.LogDebug(0, exception, "A concurrency exception occurred while trying to redeem with the token '{Identifier}'.", identifier);
@@ -547,7 +547,7 @@ namespace OpenIddict.Server.Internal
return true;
}
- catch (OpenIddictException exception) when (exception.Reason == OpenIddictConstants.Exceptions.ConcurrencyError)
+ catch (OpenIddictExceptions.ConcurrencyException exception)
{
logger.LogDebug(0, exception, "A concurrency exception occurred while trying to update the " +
"expiration date of the token '{Identifier}'.", identifier);