Browse Source

Update OpenIddictAuthorizationStore/OpenIddictTokenStore to avoid throwing exceptions when no application or authorization is specified

pull/458/head
Kévin Chalet 9 years ago
parent
commit
bc7b158677
  1. 23
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs
  2. 36
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs

23
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs

@ -125,21 +125,26 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentNullException(nameof(descriptor)); throw new ArgumentNullException(nameof(descriptor));
} }
var key = ConvertIdentifierFromString(descriptor.ApplicationId);
var application = await Applications.SingleOrDefaultAsync(entity => entity.Id.Equals(key));
if (application == null)
{
throw new InvalidOperationException("The application associated with the authorization cannot be found.");
}
var authorization = new TAuthorization var authorization = new TAuthorization
{ {
Application = application,
Scope = string.Join(" ", descriptor.Scopes), Scope = string.Join(" ", descriptor.Scopes),
Subject = descriptor.Subject Subject = descriptor.Subject
}; };
// Bind the authorization to the specified application, if applicable.
if (!string.IsNullOrEmpty(descriptor.ApplicationId))
{
var key = ConvertIdentifierFromString(descriptor.ApplicationId);
var application = await Applications.SingleOrDefaultAsync(entity => entity.Id.Equals(key));
if (application == null)
{
throw new InvalidOperationException("The application associated with the authorization cannot be found.");
}
authorization.Application = application;
}
return await CreateAsync(authorization, cancellationToken); return await CreateAsync(authorization, cancellationToken);
} }

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

@ -139,27 +139,33 @@ namespace OpenIddict.EntityFrameworkCore
Type = descriptor.Type Type = descriptor.Type
}; };
// Bind the token to the specified client application. // Bind the token to the specified client application, if applicable.
var key = ConvertIdentifierFromString(descriptor.ApplicationId); if (!string.IsNullOrEmpty(descriptor.ApplicationId))
var application = await Applications.SingleOrDefaultAsync(entity => entity.Id.Equals(key));
if (application == null)
{ {
throw new InvalidOperationException("The application associated with the token cannot be found."); var key = ConvertIdentifierFromString(descriptor.ApplicationId);
}
token.Application = application; var application = await Applications.SingleOrDefaultAsync(entity => entity.Id.Equals(key));
if (application == null)
{
throw new InvalidOperationException("The application associated with the token cannot be found.");
}
// Bind the token to the specified authorization. token.Application = application;
key = ConvertIdentifierFromString(descriptor.AuthorizationId); }
var authorization = await Authorizations.SingleOrDefaultAsync(entity => entity.Id.Equals(key)); // Bind the token to the specified authorization, if applicable.
if (authorization == null) if (!string.IsNullOrEmpty(descriptor.AuthorizationId))
{ {
throw new InvalidOperationException("The authorization associated with the token cannot be found."); var key = ConvertIdentifierFromString(descriptor.AuthorizationId);
}
token.Authorization = authorization; var authorization = await Authorizations.SingleOrDefaultAsync(entity => entity.Id.Equals(key));
if (authorization == null)
{
throw new InvalidOperationException("The authorization associated with the token cannot be found.");
}
token.Authorization = authorization;
}
return await CreateAsync(token, cancellationToken); return await CreateAsync(token, cancellationToken);
} }

Loading…
Cancel
Save