Browse Source

Update the OpenIddictAuthorizationManager.CreateAsync() method to require the authorization type

pull/567/head
Kévin Chalet 9 years ago
parent
commit
4d8914bbe6
  1. 19
      src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs
  2. 6
      src/OpenIddict.Core/Stores/IOpenIddictAuthorizationStore.cs
  3. 6
      src/OpenIddict.Core/Stores/OpenIddictAuthorizationStore.cs
  4. 6
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs

19
src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs

@ -96,12 +96,6 @@ namespace OpenIddict.Core
await Store.SetStatusAsync(authorization, OpenIddictConstants.Statuses.Valid, cancellationToken); await Store.SetStatusAsync(authorization, OpenIddictConstants.Statuses.Valid, cancellationToken);
} }
// If no type was explicitly specified, assume that the authorization is a permanent authorization.
if (string.IsNullOrEmpty(await Store.GetTypeAsync(authorization, cancellationToken)))
{
await Store.SetTypeAsync(authorization, OpenIddictConstants.AuthorizationTypes.Permanent, cancellationToken);
}
var results = await ValidateAsync(authorization, cancellationToken); var results = await ValidateAsync(authorization, cancellationToken);
if (results.Any(result => result != ValidationResult.Success)) if (results.Any(result => result != ValidationResult.Success))
{ {
@ -145,6 +139,7 @@ namespace OpenIddict.Core
/// <param name="principal">The principal associated with the authorization.</param> /// <param name="principal">The principal associated with the authorization.</param>
/// <param name="subject">The subject associated with the authorization.</param> /// <param name="subject">The subject associated with the authorization.</param>
/// <param name="client">The client associated with the authorization.</param> /// <param name="client">The client associated with the authorization.</param>
/// <param name="type">The authorization type.</param>
/// <param name="scopes">The minimal scopes associated with the authorization.</param> /// <param name="scopes">The minimal scopes associated with the authorization.</param>
/// <param name="properties">The authentication properties associated with the authorization.</param> /// <param name="properties">The authentication properties associated with the authorization.</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>
@ -153,7 +148,7 @@ namespace OpenIddict.Core
/// </returns> /// </returns>
public virtual Task<TAuthorization> CreateAsync( public virtual Task<TAuthorization> CreateAsync(
[NotNull] ClaimsPrincipal principal, [NotNull] string subject, [NotNull] ClaimsPrincipal principal, [NotNull] string subject,
[NotNull] string client, ImmutableArray<string> scopes, [NotNull] string client, [NotNull] string type, ImmutableArray<string> scopes,
[CanBeNull] ImmutableDictionary<string, string> properties, CancellationToken cancellationToken = default) [CanBeNull] ImmutableDictionary<string, string> properties, CancellationToken cancellationToken = default)
{ {
if (principal == null) if (principal == null)
@ -175,7 +170,9 @@ namespace OpenIddict.Core
{ {
ApplicationId = client, ApplicationId = client,
Principal = principal, Principal = principal,
Subject = subject Status = OpenIddictConstants.Statuses.Valid,
Subject = subject,
Type = type
}; };
descriptor.Scopes.UnionWith(scopes); descriptor.Scopes.UnionWith(scopes);
@ -241,13 +238,13 @@ namespace OpenIddict.Core
/// </summary> /// </summary>
/// <param name="subject">The subject associated with the authorization.</param> /// <param name="subject">The subject associated with the authorization.</param>
/// <param name="client">The client associated with the authorization.</param> /// <param name="client">The client associated with the authorization.</param>
/// <param name="status">The status associated with the authorization.</param> /// <param name="status">The authorization status.</param>
/// <param name="type">The type associated with the authorization.</param> /// <param name="type">The authorization type.</param>
/// <param name="scopes">The minimal scopes associated with the authorization.</param> /// <param name="scopes">The minimal scopes associated with the authorization.</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> /// <returns>
/// 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 authorizations corresponding to the subject/client. /// whose result returns the authorizations corresponding to the criteria.
/// </returns> /// </returns>
public virtual async Task<ImmutableArray<TAuthorization>> FindAsync( public virtual async Task<ImmutableArray<TAuthorization>> FindAsync(
[NotNull] string subject, [NotNull] string client, [NotNull] string subject, [NotNull] string client,

6
src/OpenIddict.Core/Stores/IOpenIddictAuthorizationStore.cs

@ -80,12 +80,12 @@ namespace OpenIddict.Core
/// </summary> /// </summary>
/// <param name="subject">The subject associated with the authorization.</param> /// <param name="subject">The subject associated with the authorization.</param>
/// <param name="client">The client associated with the authorization.</param> /// <param name="client">The client associated with the authorization.</param>
/// <param name="status">The status associated with the authorization.</param> /// <param name="status">The authorization status.</param>
/// <param name="type">The type associated with the authorization.</param> /// <param name="type">The authorization type.</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> /// <returns>
/// 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 authorizations corresponding to the subject/client. /// whose result returns the authorizations corresponding to the criteria.
/// </returns> /// </returns>
Task<ImmutableArray<TAuthorization>> FindAsync( Task<ImmutableArray<TAuthorization>> FindAsync(
[NotNull] string subject, [NotNull] string client, [NotNull] string subject, [NotNull] string client,

6
src/OpenIddict.Core/Stores/OpenIddictAuthorizationStore.cs

@ -134,12 +134,12 @@ namespace OpenIddict.Core
/// </summary> /// </summary>
/// <param name="subject">The subject associated with the authorization.</param> /// <param name="subject">The subject associated with the authorization.</param>
/// <param name="client">The client associated with the authorization.</param> /// <param name="client">The client associated with the authorization.</param>
/// <param name="status">The status associated with the authorization.</param> /// <param name="status">The authorization status.</param>
/// <param name="type">The type associated with the authorization.</param> /// <param name="type">The authorization type.</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> /// <returns>
/// 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 authorizations corresponding to the subject/client. /// whose result returns the authorizations corresponding to the criteria.
/// </returns> /// </returns>
public virtual Task<ImmutableArray<TAuthorization>> FindAsync( public virtual Task<ImmutableArray<TAuthorization>> FindAsync(
[NotNull] string subject, [NotNull] string client, [NotNull] string subject, [NotNull] string client,

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

@ -223,12 +223,12 @@ namespace OpenIddict.EntityFrameworkCore
/// </summary> /// </summary>
/// <param name="subject">The subject associated with the authorization.</param> /// <param name="subject">The subject associated with the authorization.</param>
/// <param name="client">The client associated with the authorization.</param> /// <param name="client">The client associated with the authorization.</param>
/// <param name="status">The status associated with the authorization.</param> /// <param name="status">The authorization status.</param>
/// <param name="type">The type associated with the authorization.</param> /// <param name="type">The authorization type.</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> /// <returns>
/// 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 authorizations corresponding to the subject/client. /// whose result returns the authorizations corresponding to the criteria.
/// </returns> /// </returns>
public override async Task<ImmutableArray<TAuthorization>> FindAsync( public override async Task<ImmutableArray<TAuthorization>> FindAsync(
[NotNull] string subject, [NotNull] string client, [NotNull] string subject, [NotNull] string client,

Loading…
Cancel
Save