|
|
@ -142,9 +142,7 @@ namespace OpenIddict.EntityFramework |
|
|
// Bind the token to the specified client application, if applicable.
|
|
|
// Bind the token to the specified client application, if applicable.
|
|
|
if (!string.IsNullOrEmpty(descriptor.ApplicationId)) |
|
|
if (!string.IsNullOrEmpty(descriptor.ApplicationId)) |
|
|
{ |
|
|
{ |
|
|
var key = ConvertIdentifierFromString(descriptor.ApplicationId); |
|
|
var application = await Applications.FindAsync(cancellationToken, ConvertIdentifierFromString(descriptor.ApplicationId)); |
|
|
|
|
|
|
|
|
var application = await Applications.SingleOrDefaultAsync(entity => entity.Id.Equals(key)); |
|
|
|
|
|
if (application == null) |
|
|
if (application == null) |
|
|
{ |
|
|
{ |
|
|
throw new InvalidOperationException("The application associated with the token cannot be found."); |
|
|
throw new InvalidOperationException("The application associated with the token cannot be found."); |
|
|
@ -156,9 +154,7 @@ namespace OpenIddict.EntityFramework |
|
|
// Bind the token to the specified authorization, if applicable.
|
|
|
// Bind the token to the specified authorization, if applicable.
|
|
|
if (!string.IsNullOrEmpty(descriptor.AuthorizationId)) |
|
|
if (!string.IsNullOrEmpty(descriptor.AuthorizationId)) |
|
|
{ |
|
|
{ |
|
|
var key = ConvertIdentifierFromString(descriptor.AuthorizationId); |
|
|
var authorization = await Authorizations.FindAsync(cancellationToken, ConvertIdentifierFromString(descriptor.AuthorizationId)); |
|
|
|
|
|
|
|
|
var authorization = await Authorizations.SingleOrDefaultAsync(entity => entity.Id.Equals(key)); |
|
|
|
|
|
if (authorization == null) |
|
|
if (authorization == null) |
|
|
{ |
|
|
{ |
|
|
throw new InvalidOperationException("The authorization associated with the token cannot be found."); |
|
|
throw new InvalidOperationException("The authorization associated with the token cannot be found."); |
|
|
@ -193,6 +189,20 @@ namespace OpenIddict.EntityFramework |
|
|
catch (DbUpdateConcurrencyException) { } |
|
|
catch (DbUpdateConcurrencyException) { } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Retrieves an token using its unique identifier.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="identifier">The unique identifier associated with the token.</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 token corresponding to the unique identifier.
|
|
|
|
|
|
/// </returns>
|
|
|
|
|
|
public override Task<TToken> FindByIdAsync(string identifier, CancellationToken cancellationToken) |
|
|
|
|
|
{ |
|
|
|
|
|
return Tokens.FindAsync(cancellationToken, ConvertIdentifierFromString(identifier)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Executes the specified query.
|
|
|
/// Executes the specified query.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
@ -251,15 +261,13 @@ namespace OpenIddict.EntityFramework |
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(identifier)) |
|
|
if (!string.IsNullOrEmpty(identifier)) |
|
|
{ |
|
|
{ |
|
|
var key = ConvertIdentifierFromString(identifier); |
|
|
var authorization = await Authorizations.FindAsync(cancellationToken, ConvertIdentifierFromString(identifier)); |
|
|
|
|
|
|
|
|
var authorization = await Authorizations.SingleOrDefaultAsync(element => element.Id.Equals(key)); |
|
|
|
|
|
if (authorization == null) |
|
|
if (authorization == null) |
|
|
{ |
|
|
{ |
|
|
throw new InvalidOperationException("The authorization associated with the token cannot be found."); |
|
|
throw new InvalidOperationException("The authorization associated with the token cannot be found."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
authorization.Tokens.Add(token); |
|
|
token.Authorization = authorization; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
else |
|
|
else |
|
|
@ -268,7 +276,7 @@ namespace OpenIddict.EntityFramework |
|
|
|
|
|
|
|
|
// Try to retrieve the authorization associated with the token.
|
|
|
// Try to retrieve the authorization associated with the token.
|
|
|
// If none can be found, assume that no authorization is attached.
|
|
|
// If none can be found, assume that no authorization is attached.
|
|
|
var authorization = await Authorizations.SingleOrDefaultAsync(element => element.Tokens.Any(t => t.Id.Equals(key))); |
|
|
var authorization = await Authorizations.FirstOrDefaultAsync(element => element.Tokens.Any(t => t.Id.Equals(key))); |
|
|
if (authorization != null) |
|
|
if (authorization != null) |
|
|
{ |
|
|
{ |
|
|
authorization.Tokens.Remove(token); |
|
|
authorization.Tokens.Remove(token); |
|
|
@ -294,15 +302,13 @@ namespace OpenIddict.EntityFramework |
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(identifier)) |
|
|
if (!string.IsNullOrEmpty(identifier)) |
|
|
{ |
|
|
{ |
|
|
var key = ConvertIdentifierFromString(identifier); |
|
|
var application = await Applications.FindAsync(cancellationToken, ConvertIdentifierFromString(identifier)); |
|
|
|
|
|
|
|
|
var application = await Applications.SingleOrDefaultAsync(element => element.Id.Equals(key)); |
|
|
|
|
|
if (application == null) |
|
|
if (application == null) |
|
|
{ |
|
|
{ |
|
|
throw new InvalidOperationException("The application associated with the token cannot be found."); |
|
|
throw new InvalidOperationException("The application associated with the token cannot be found."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
application.Tokens.Add(token); |
|
|
token.Application = application; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
else |
|
|
else |
|
|
@ -311,7 +317,7 @@ namespace OpenIddict.EntityFramework |
|
|
|
|
|
|
|
|
// Try to retrieve the application associated with the token.
|
|
|
// Try to retrieve the application associated with the token.
|
|
|
// If none can be found, assume that no application is attached.
|
|
|
// If none can be found, assume that no application is attached.
|
|
|
var application = await Applications.SingleOrDefaultAsync(element => element.Tokens.Any(t => t.Id.Equals(key))); |
|
|
var application = await Applications.FirstOrDefaultAsync(element => element.Tokens.Any(t => t.Id.Equals(key))); |
|
|
if (application != null) |
|
|
if (application != null) |
|
|
{ |
|
|
{ |
|
|
application.Tokens.Remove(token); |
|
|
application.Tokens.Remove(token); |
|
|
|