Browse Source

Backport the extensions/helpers changes to OpenIddict 1.x

pull/2236/head
Kévin Chalet 8 years ago
parent
commit
2dedef105f
  1. 2
      OpenIddict.sln
  2. 41
      src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkExtensions.cs
  3. 59
      src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkHelpers.cs
  4. 1
      src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreCustomizer.cs
  5. 106
      src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreExtensions.cs
  6. 123
      src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreHelpers.cs
  7. 4
      src/OpenIddict.Server/Internal/OpenIddictServerProvider.Exchange.cs
  8. 23
      src/OpenIddict.Server/Internal/OpenIddictServerProvider.Helpers.cs
  9. 9
      src/OpenIddict.Server/Internal/OpenIddictServerProvider.Introspection.cs
  10. 2
      src/OpenIddict.Server/Internal/OpenIddictServerProvider.Revocation.cs
  11. 6
      src/OpenIddict.Server/Internal/OpenIddictServerProvider.cs
  12. 89
      src/OpenIddict.Server/OpenIddictServerHelpers.cs
  13. 56
      test/OpenIddict.EntityFrameworkCore.Tests/OpenIddictEntityFrameworkCoreExtensionsTests.cs
  14. 70
      test/OpenIddict.EntityFrameworkCore.Tests/OpenIddictEntityFrameworkCoreHelpersTests.cs
  15. 50
      test/OpenIddict.Server.Tests/Internal/OpenIddictServerProviderTests.Exchange.cs
  16. 14
      test/OpenIddict.Server.Tests/Internal/OpenIddictServerProviderTests.Introspection.cs
  17. 8
      test/OpenIddict.Server.Tests/Internal/OpenIddictServerProviderTests.Revocation.cs
  18. 14
      test/OpenIddict.Server.Tests/Internal/OpenIddictServerProviderTests.Serialization.cs
  19. 32
      test/OpenIddict.Server.Tests/Internal/OpenIddictServerProviderTests.cs

2
OpenIddict.sln

@ -65,7 +65,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenIddict.MongoDb.Tests",
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{D8075F1F-6257-463B-B481-BDC7C5ABA292}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenIddict.Extensions", "shared\OpenIddict.Extensions\OpenIddict.Extensions.csproj", "{B90761B9-7582-44CB-AB0D-3C4058693227}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenIddict.Extensions", "shared\OpenIddict.Extensions\OpenIddict.Extensions.csproj", "{B90761B9-7582-44CB-AB0D-3C4058693227}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

41
src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkExtensions.cs

@ -5,7 +5,6 @@
*/
using System;
using System.Data.Entity;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection.Extensions;
using OpenIddict.EntityFramework;
@ -81,45 +80,5 @@ namespace Microsoft.Extensions.DependencyInjection
return builder;
}
/// <summary>
/// Registers the OpenIddict entity sets in the Entity Framework 6.x context
/// using the default OpenIddict models and the default key type (string).
/// </summary>
/// <param name="builder">The builder used to configure the Entity Framework context.</param>
/// <returns>The Entity Framework context builder.</returns>
public static DbModelBuilder UseOpenIddict([NotNull] this DbModelBuilder builder)
=> builder.UseOpenIddict<OpenIddictApplication,
OpenIddictAuthorization,
OpenIddictScope,
OpenIddictToken, string>();
/// <summary>
/// Registers the OpenIddict entity sets in the Entity Framework 6.x
/// context using the specified entities and the specified key type.
/// Note: using this method requires creating non-generic derived classes
/// for all the OpenIddict entities (application, authorization, scope, token).
/// </summary>
/// <param name="builder">The builder used to configure the Entity Framework context.</param>
/// <returns>The Entity Framework context builder.</returns>
public static DbModelBuilder UseOpenIddict<TApplication, TAuthorization, TScope, TToken, TKey>([NotNull] this DbModelBuilder builder)
where TApplication : OpenIddictApplication<TKey, TAuthorization, TToken>
where TAuthorization : OpenIddictAuthorization<TKey, TApplication, TToken>
where TScope : OpenIddictScope<TKey>
where TToken : OpenIddictToken<TKey, TApplication, TAuthorization>
where TKey : IEquatable<TKey>
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
builder.Configurations.Add(new OpenIddictApplicationConfiguration<TApplication, TAuthorization, TToken, TKey>());
builder.Configurations.Add(new OpenIddictAuthorizationConfiguration<TAuthorization, TApplication, TToken, TKey>());
builder.Configurations.Add(new OpenIddictScopeConfiguration<TScope, TKey>());
builder.Configurations.Add(new OpenIddictTokenConfiguration<TToken, TApplication, TAuthorization, TKey>());
return builder;
}
}
}

59
src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkHelpers.cs

@ -0,0 +1,59 @@
/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://github.com/openiddict/openiddict-core for more information concerning
* the license and the contributors participating to this project.
*/
using JetBrains.Annotations;
using OpenIddict.EntityFramework;
using OpenIddict.EntityFramework.Models;
namespace System.Data.Entity
{
/// <summary>
/// Exposes extensions allowing to register the OpenIddict Entity Framework 6.x entity sets.
/// </summary>
public static class OpenIddictEntityFrameworkHelpers
{
/// <summary>
/// Registers the OpenIddict entity sets in the Entity Framework 6.x context
/// using the default OpenIddict models and the default key type (string).
/// </summary>
/// <param name="builder">The builder used to configure the Entity Framework context.</param>
/// <returns>The Entity Framework context builder.</returns>
public static DbModelBuilder UseOpenIddict([NotNull] this DbModelBuilder builder)
=> builder.UseOpenIddict<OpenIddictApplication,
OpenIddictAuthorization,
OpenIddictScope,
OpenIddictToken, string>();
/// <summary>
/// Registers the OpenIddict entity sets in the Entity Framework 6.x
/// context using the specified entities and the specified key type.
/// Note: using this method requires creating non-generic derived classes
/// for all the OpenIddict entities (application, authorization, scope, token).
/// </summary>
/// <param name="builder">The builder used to configure the Entity Framework context.</param>
/// <returns>The Entity Framework context builder.</returns>
public static DbModelBuilder UseOpenIddict<TApplication, TAuthorization, TScope, TToken, TKey>([NotNull] this DbModelBuilder builder)
where TApplication : OpenIddictApplication<TKey, TAuthorization, TToken>
where TAuthorization : OpenIddictAuthorization<TKey, TApplication, TToken>
where TScope : OpenIddictScope<TKey>
where TToken : OpenIddictToken<TKey, TApplication, TAuthorization>
where TKey : IEquatable<TKey>
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
builder.Configurations
.Add(new OpenIddictApplicationConfiguration<TApplication, TAuthorization, TToken, TKey>())
.Add(new OpenIddictAuthorizationConfiguration<TAuthorization, TApplication, TToken, TKey>())
.Add(new OpenIddictScopeConfiguration<TScope, TKey>())
.Add(new OpenIddictTokenConfiguration<TToken, TApplication, TAuthorization, TKey>());
return builder;
}
}
}

1
src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreCustomizer.cs

@ -8,7 +8,6 @@ using System;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
using OpenIddict.EntityFrameworkCore.Models;
namespace OpenIddict.EntityFrameworkCore

106
src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreExtensions.cs

@ -6,9 +6,6 @@
using System;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.Extensions.DependencyInjection.Extensions;
using OpenIddict.EntityFrameworkCore;
using OpenIddict.EntityFrameworkCore.Models;
@ -83,108 +80,5 @@ namespace Microsoft.Extensions.DependencyInjection
return builder;
}
/// <summary>
/// Registers the OpenIddict entity sets in the Entity Framework Core context
/// using the default OpenIddict models and the default key type (string).
/// </summary>
/// <param name="builder">The builder used to configure the Entity Framework context.</param>
/// <returns>The Entity Framework context builder.</returns>
public static DbContextOptionsBuilder UseOpenIddict([NotNull] this DbContextOptionsBuilder builder)
=> builder.UseOpenIddict<OpenIddictApplication,
OpenIddictAuthorization,
OpenIddictScope,
OpenIddictToken, string>();
/// <summary>
/// Registers the OpenIddict entity sets in the Entity Framework Core
/// context using the default OpenIddict models and the specified key type.
/// </summary>
/// <param name="builder">The builder used to configure the Entity Framework context.</param>
/// <returns>The Entity Framework context builder.</returns>
public static DbContextOptionsBuilder UseOpenIddict<TKey>([NotNull] this DbContextOptionsBuilder builder)
where TKey : IEquatable<TKey>
=> builder.UseOpenIddict<OpenIddictApplication<TKey>,
OpenIddictAuthorization<TKey>,
OpenIddictScope<TKey>,
OpenIddictToken<TKey>, TKey>();
/// <summary>
/// Registers the OpenIddict entity sets in the Entity Framework Core
/// context using the specified entities and the specified key type.
/// </summary>
/// <param name="builder">The builder used to configure the Entity Framework context.</param>
/// <returns>The Entity Framework context builder.</returns>
public static DbContextOptionsBuilder UseOpenIddict<TApplication, TAuthorization, TScope, TToken, TKey>([NotNull] this DbContextOptionsBuilder builder)
where TApplication : OpenIddictApplication<TKey, TAuthorization, TToken>
where TAuthorization : OpenIddictAuthorization<TKey, TApplication, TToken>
where TScope : OpenIddictScope<TKey>
where TToken : OpenIddictToken<TKey, TApplication, TAuthorization>
where TKey : IEquatable<TKey>
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
var extension = new OpenIddictEntityFrameworkCoreExtension<TApplication, TAuthorization, TScope, TToken, TKey>();
((IDbContextOptionsBuilderInfrastructure) builder).AddOrUpdateExtension(extension);
return builder;
}
/// <summary>
/// Registers the OpenIddict entity sets in the Entity Framework Core context
/// using the default OpenIddict models and the default key type (string).
/// </summary>
/// <param name="builder">The builder used to configure the Entity Framework context.</param>
/// <returns>The Entity Framework context builder.</returns>
public static ModelBuilder UseOpenIddict([NotNull] this ModelBuilder builder)
=> builder.UseOpenIddict<OpenIddictApplication,
OpenIddictAuthorization,
OpenIddictScope,
OpenIddictToken, string>();
/// <summary>
/// Registers the OpenIddict entity sets in the Entity Framework Core
/// context using the default OpenIddict models and the specified key type.
/// </summary>
/// <param name="builder">The builder used to configure the Entity Framework context.</param>
/// <returns>The Entity Framework context builder.</returns>
public static ModelBuilder UseOpenIddict<TKey>([NotNull] this ModelBuilder builder) where TKey : IEquatable<TKey>
=> builder.UseOpenIddict<OpenIddictApplication<TKey>,
OpenIddictAuthorization<TKey>,
OpenIddictScope<TKey>,
OpenIddictToken<TKey>, TKey>();
/// <summary>
/// Registers the OpenIddict entity sets in the Entity Framework Core
/// context using the specified entities and the specified key type.
/// </summary>
/// <param name="builder">The builder used to configure the Entity Framework context.</param>
/// <returns>The Entity Framework context builder.</returns>
public static ModelBuilder UseOpenIddict<TApplication, TAuthorization, TScope, TToken, TKey>([NotNull] this ModelBuilder builder)
where TApplication : OpenIddictApplication<TKey, TAuthorization, TToken>
where TAuthorization : OpenIddictAuthorization<TKey, TApplication, TToken>
where TScope : OpenIddictScope<TKey>
where TToken : OpenIddictToken<TKey, TApplication, TAuthorization>
where TKey : IEquatable<TKey>
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
new OpenIddictApplicationConfiguration<TApplication, TAuthorization, TToken, TKey>()
.Configure(builder.Entity<TApplication>());
new OpenIddictAuthorizationConfiguration<TAuthorization, TApplication, TToken, TKey>()
.Configure(builder.Entity<TAuthorization>());
new OpenIddictScopeConfiguration<TScope, TKey>()
.Configure(builder.Entity<TScope>());
new OpenIddictTokenConfiguration<TToken, TApplication, TAuthorization, TKey>()
.Configure(builder.Entity<TToken>());
return builder;
}
}
}

123
src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreHelpers.cs

@ -0,0 +1,123 @@
/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://github.com/openiddict/openiddict-core for more information concerning
* the license and the contributors participating to this project.
*/
using System;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using OpenIddict.EntityFrameworkCore;
using OpenIddict.EntityFrameworkCore.Models;
namespace Microsoft.EntityFrameworkCore
{
/// <summary>
/// Exposes extensions allowing to register the OpenIddict Entity Framework Core entity sets.
/// </summary>
public static class OpenIddictEntityFrameworkCoreHelpers
{
/// <summary>
/// Registers the OpenIddict entity sets in the Entity Framework Core context
/// using the default OpenIddict models and the default key type (string).
/// </summary>
/// <param name="builder">The builder used to configure the Entity Framework context.</param>
/// <returns>The Entity Framework context builder.</returns>
public static DbContextOptionsBuilder UseOpenIddict([NotNull] this DbContextOptionsBuilder builder)
=> builder.UseOpenIddict<OpenIddictApplication,
OpenIddictAuthorization,
OpenIddictScope,
OpenIddictToken, string>();
/// <summary>
/// Registers the OpenIddict entity sets in the Entity Framework Core
/// context using the default OpenIddict models and the specified key type.
/// </summary>
/// <param name="builder">The builder used to configure the Entity Framework context.</param>
/// <returns>The Entity Framework context builder.</returns>
public static DbContextOptionsBuilder UseOpenIddict<TKey>([NotNull] this DbContextOptionsBuilder builder)
where TKey : IEquatable<TKey>
=> builder.UseOpenIddict<OpenIddictApplication<TKey>,
OpenIddictAuthorization<TKey>,
OpenIddictScope<TKey>,
OpenIddictToken<TKey>, TKey>();
/// <summary>
/// Registers the OpenIddict entity sets in the Entity Framework Core
/// context using the specified entities and the specified key type.
/// </summary>
/// <param name="builder">The builder used to configure the Entity Framework context.</param>
/// <returns>The Entity Framework context builder.</returns>
public static DbContextOptionsBuilder UseOpenIddict<TApplication, TAuthorization, TScope, TToken, TKey>([NotNull] this DbContextOptionsBuilder builder)
where TApplication : OpenIddictApplication<TKey, TAuthorization, TToken>
where TAuthorization : OpenIddictAuthorization<TKey, TApplication, TToken>
where TScope : OpenIddictScope<TKey>
where TToken : OpenIddictToken<TKey, TApplication, TAuthorization>
where TKey : IEquatable<TKey>
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
var extension = new OpenIddictEntityFrameworkCoreExtension<TApplication, TAuthorization, TScope, TToken, TKey>();
((IDbContextOptionsBuilderInfrastructure) builder).AddOrUpdateExtension(extension);
return builder;
}
/// <summary>
/// Registers the OpenIddict entity sets in the Entity Framework Core context
/// using the default OpenIddict models and the default key type (string).
/// </summary>
/// <param name="builder">The builder used to configure the Entity Framework context.</param>
/// <returns>The Entity Framework context builder.</returns>
public static ModelBuilder UseOpenIddict([NotNull] this ModelBuilder builder)
=> builder.UseOpenIddict<OpenIddictApplication,
OpenIddictAuthorization,
OpenIddictScope,
OpenIddictToken, string>();
/// <summary>
/// Registers the OpenIddict entity sets in the Entity Framework Core
/// context using the default OpenIddict models and the specified key type.
/// </summary>
/// <param name="builder">The builder used to configure the Entity Framework context.</param>
/// <returns>The Entity Framework context builder.</returns>
public static ModelBuilder UseOpenIddict<TKey>([NotNull] this ModelBuilder builder) where TKey : IEquatable<TKey>
=> builder.UseOpenIddict<OpenIddictApplication<TKey>,
OpenIddictAuthorization<TKey>,
OpenIddictScope<TKey>,
OpenIddictToken<TKey>, TKey>();
/// <summary>
/// Registers the OpenIddict entity sets in the Entity Framework Core
/// context using the specified entities and the specified key type.
/// </summary>
/// <param name="builder">The builder used to configure the Entity Framework context.</param>
/// <returns>The Entity Framework context builder.</returns>
public static ModelBuilder UseOpenIddict<TApplication, TAuthorization, TScope, TToken, TKey>([NotNull] this ModelBuilder builder)
where TApplication : OpenIddictApplication<TKey, TAuthorization, TToken>
where TAuthorization : OpenIddictAuthorization<TKey, TApplication, TToken>
where TScope : OpenIddictScope<TKey>
where TToken : OpenIddictToken<TKey, TApplication, TAuthorization>
where TKey : IEquatable<TKey>
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
new OpenIddictApplicationConfiguration<TApplication, TAuthorization, TToken, TKey>()
.Configure(builder.Entity<TApplication>());
new OpenIddictAuthorizationConfiguration<TAuthorization, TApplication, TToken, TKey>()
.Configure(builder.Entity<TAuthorization>());
new OpenIddictScopeConfiguration<TScope, TKey>()
.Configure(builder.Entity<TScope>());
new OpenIddictTokenConfiguration<TToken, TApplication, TAuthorization, TKey>()
.Configure(builder.Entity<TToken>());
return builder;
}
}
}

4
src/OpenIddict.Server/Internal/OpenIddictServerProvider.Exchange.cs

@ -353,7 +353,7 @@ namespace OpenIddict.Server.Internal
if (!options.DisableTokenStorage)
{
// Extract the token identifier from the authentication ticket.
var identifier = context.Ticket.GetProperty(OpenIddictConstants.Properties.InternalTokenId);
var identifier = context.Ticket.GetInternalTokenId();
Debug.Assert(!string.IsNullOrEmpty(identifier), "The authentication ticket should contain a token identifier.");
// If the authorization code/refresh token is already marked as redeemed, this may indicate that
@ -409,7 +409,7 @@ namespace OpenIddict.Server.Internal
if (!options.DisableAuthorizationStorage)
{
// Extract the authorization identifier from the authentication ticket.
var identifier = context.Ticket.GetProperty(OpenIddictConstants.Properties.InternalAuthorizationId);
var identifier = context.Ticket.GetInternalAuthorizationId();
if (!string.IsNullOrEmpty(identifier))
{
var authorization = await authorizationManager.FindByIdAsync(identifier);

23
src/OpenIddict.Server/Internal/OpenIddictServerProvider.Helpers.cs

@ -90,7 +90,7 @@ namespace OpenIddict.Server.Internal
// Attach the unique identifier of the ad hoc authorization to the authentication ticket
// so that it is attached to all the derived tokens, allowing batched revocations support.
ticket.SetProperty(OpenIddictConstants.Properties.InternalAuthorizationId, identifier);
ticket.SetInternalAuthorizationId(identifier);
}
}
@ -131,7 +131,7 @@ namespace OpenIddict.Server.Internal
var descriptor = new OpenIddictTokenDescriptor
{
AuthorizationId = ticket.GetProperty(OpenIddictConstants.Properties.InternalAuthorizationId),
AuthorizationId = ticket.GetInternalAuthorizationId(),
CreationDate = ticket.Properties.IssuedUtc,
ExpirationDate = ticket.Properties.ExpiresUtc,
Principal = ticket.Principal,
@ -216,8 +216,8 @@ namespace OpenIddict.Server.Internal
ticket.Properties.ExpiresUtc = descriptor.ExpirationDate;
// Restore the token/authorization identifiers using the identifiers attached with the database entry.
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, identifier)
.SetProperty(OpenIddictConstants.Properties.InternalAuthorizationId, descriptor.AuthorizationId);
ticket.SetInternalAuthorizationId(descriptor.AuthorizationId)
.SetInternalTokenId(identifier);
if (options.UseReferenceTokens)
{
@ -325,7 +325,7 @@ namespace OpenIddict.Server.Internal
return null;
}
identifier = ticket.GetProperty(OpenIddictConstants.Properties.InternalTokenId);
identifier = ticket.GetInternalTokenId();
if (string.IsNullOrEmpty(identifier))
{
logger.LogWarning("The identifier associated with the received token cannot be retrieved. " +
@ -353,9 +353,8 @@ namespace OpenIddict.Server.Internal
ticket.Properties.ExpiresUtc = await tokenManager.GetExpirationDateAsync(token);
// Restore the token/authorization identifiers using the identifiers attached with the database entry.
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, identifier);
ticket.SetProperty(OpenIddictConstants.Properties.InternalAuthorizationId,
await tokenManager.GetAuthorizationIdAsync(token));
ticket.SetInternalAuthorizationId(await tokenManager.GetAuthorizationIdAsync(token))
.SetInternalTokenId(identifier);
logger.LogTrace("The token '{Identifier}' was successfully decrypted and " +
"retrieved from the database: {Claims} ; {Properties}.",
@ -372,7 +371,7 @@ namespace OpenIddict.Server.Internal
// Note: if the authorization identifier or the authorization itself
// cannot be found, return true as the authorization doesn't need
// to be revoked if it doesn't exist or is already invalid.
var identifier = ticket.GetProperty(OpenIddictConstants.Properties.InternalAuthorizationId);
var identifier = ticket.GetInternalAuthorizationId();
if (string.IsNullOrEmpty(identifier))
{
return true;
@ -451,7 +450,7 @@ namespace OpenIddict.Server.Internal
var tokenManager = GetTokenManager(context.RequestServices);
// Note: if the authorization identifier is null, return true as no tokens need to be revoked.
var identifier = ticket.GetProperty(OpenIddictConstants.Properties.InternalAuthorizationId);
var identifier = ticket.GetInternalAuthorizationId();
if (string.IsNullOrEmpty(identifier))
{
return true;
@ -462,7 +461,7 @@ namespace OpenIddict.Server.Internal
foreach (var token in await tokenManager.FindByAuthorizationIdAsync(identifier))
{
// Don't change the status of the token used in the token request.
if (string.Equals(ticket.GetProperty(OpenIddictConstants.Properties.InternalTokenId),
if (string.Equals(ticket.GetInternalTokenId(),
await tokenManager.GetIdAsync(token), StringComparison.Ordinal))
{
continue;
@ -515,7 +514,7 @@ namespace OpenIddict.Server.Internal
var logger = GetLogger(context.RequestServices);
var tokenManager = GetTokenManager(context.RequestServices);
var identifier = ticket.GetProperty(OpenIddictConstants.Properties.InternalTokenId);
var identifier = ticket.GetInternalTokenId();
Debug.Assert(!string.IsNullOrEmpty(identifier), "The token identifier shouldn't be null or empty.");
try

9
src/OpenIddict.Server/Internal/OpenIddictServerProvider.Introspection.cs

@ -117,7 +117,7 @@ namespace OpenIddict.Server.Internal
Debug.Assert(context.Ticket != null, "The authentication ticket shouldn't be null.");
Debug.Assert(!string.IsNullOrEmpty(context.Request.ClientId), "The client_id parameter shouldn't be null.");
var identifier = context.Ticket.GetProperty(OpenIddictConstants.Properties.InternalTokenId);
var identifier = context.Ticket.GetInternalTokenId();
Debug.Assert(!string.IsNullOrEmpty(identifier), "The authentication ticket should contain a token identifier.");
if (!context.Ticket.IsAccessToken())
@ -155,12 +155,9 @@ namespace OpenIddict.Server.Internal
}
// If an authorization was attached to the access token, ensure it is still valid.
if (!options.DisableAuthorizationStorage &&
context.Ticket.HasProperty(OpenIddictConstants.Properties.InternalAuthorizationId))
if (!options.DisableAuthorizationStorage && !string.IsNullOrEmpty(context.Ticket.GetInternalAuthorizationId()))
{
var authorization = await authorizationManager.FindByIdAsync(
context.Ticket.GetProperty(OpenIddictConstants.Properties.InternalAuthorizationId));
var authorization = await authorizationManager.FindByIdAsync(context.Ticket.GetInternalAuthorizationId());
if (authorization == null || !await authorizationManager.IsValidAsync(authorization))
{
logger.LogError("The token '{Identifier}' was declared as inactive because " +

2
src/OpenIddict.Server/Internal/OpenIddictServerProvider.Revocation.cs

@ -208,7 +208,7 @@ namespace OpenIddict.Server.Internal
}
// Extract the token identifier from the authentication ticket.
var identifier = context.Ticket.GetProperty(OpenIddictConstants.Properties.InternalTokenId);
var identifier = context.Ticket.GetInternalTokenId();
Debug.Assert(!string.IsNullOrEmpty(identifier), "The authentication ticket should contain a token identifier.");
var token = await tokenManager.FindByIdAsync(identifier);

6
src/OpenIddict.Server/Internal/OpenIddictServerProvider.cs

@ -80,7 +80,7 @@ namespace OpenIddict.Server.Internal
// This scenario is deliberately not supported in OpenIddict and all the tickets
// must be linked. To ensure the properties are flowed from the authorization code
// or the refresh token to the new ticket, they are manually restored if necessary.
if (!context.Ticket.Properties.HasProperty(OpenIddictConstants.Properties.InternalTokenId))
if (string.IsNullOrEmpty(context.Ticket.GetInternalTokenId()))
{
// Retrieve the original authentication ticket from the request properties.
var ticket = context.Request.GetProperty<AuthenticationTicket>(
@ -122,7 +122,7 @@ namespace OpenIddict.Server.Internal
// If token revocation was explicitly disabled, none of the following security routines apply.
if (!options.DisableTokenStorage)
{
var token = await tokenManager.FindByIdAsync(context.Ticket.GetProperty(OpenIddictConstants.Properties.InternalTokenId));
var token = await tokenManager.FindByIdAsync(context.Ticket.GetInternalTokenId());
if (token == null)
{
context.Reject(
@ -181,7 +181,7 @@ namespace OpenIddict.Server.Internal
// create an ad hoc authorization if an authorization code or a refresh token
// is going to be returned to the client application as part of the response.
if (!options.DisableAuthorizationStorage &&
!context.Ticket.HasProperty(OpenIddictConstants.Properties.InternalAuthorizationId) &&
string.IsNullOrEmpty(context.Ticket.GetInternalAuthorizationId()) &&
(context.IncludeAuthorizationCode || context.IncludeRefreshToken))
{
await CreateAuthorizationAsync(context.Ticket, options, context.HttpContext, context.Request);

89
src/OpenIddict.Server/OpenIddictServerHelpers.cs

@ -0,0 +1,89 @@
/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://github.com/openiddict/openiddict-core for more information concerning
* the license and the contributors participating to this project.
*/
using System;
using AspNet.Security.OpenIdConnect.Extensions;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Authentication;
using OpenIddict.Abstractions;
namespace OpenIddict.Server
{
/// <summary>
/// Exposes extensions allowing to store and retrieve
/// OpenIddict-specific properties in authentication tickets.
/// </summary>
public static class OpenIddictServerHelpers
{
/// <summary>
/// Gets the internal authorization identifier associated with the authentication ticket.
/// Note: this identifier can be used to retrieve the authorization from the database.
/// </summary>
/// <param name="ticket">The authentication ticket.</param>
/// <returns>The authorization identifier or <c>null</c> if it cannot be found.</returns>
public static string GetInternalAuthorizationId([NotNull] this AuthenticationTicket ticket)
{
if (ticket == null)
{
throw new ArgumentNullException(nameof(ticket));
}
return ticket.GetProperty(OpenIddictConstants.Properties.InternalAuthorizationId);
}
/// <summary>
/// Gets the internal token identifier associated with the authentication ticket.
/// Note: this identifier can be used to retrieve the token from the database.
/// </summary>
/// <param name="ticket">The authentication ticket.</param>
/// <returns>The token identifier or <c>null</c> if it cannot be found.</returns>
public static string GetInternalTokenId([NotNull] this AuthenticationTicket ticket)
{
if (ticket == null)
{
throw new ArgumentNullException(nameof(ticket));
}
return ticket.GetProperty(OpenIddictConstants.Properties.InternalTokenId);
}
/// <summary>
/// Sets the internal authorization identifier associated with the authentication ticket.
/// Note: the identifier MUST correspond to a valid authorization entry in the database.
/// </summary>
/// <param name="ticket">The authentication ticket.</param>
/// <param name="identifier">The internal authorization identifier.</param>
/// <returns>The authentication ticket.</returns>
public static AuthenticationTicket SetInternalAuthorizationId(
[NotNull] this AuthenticationTicket ticket, [CanBeNull] string identifier)
{
if (ticket == null)
{
throw new ArgumentNullException(nameof(ticket));
}
return ticket.SetProperty(OpenIddictConstants.Properties.InternalAuthorizationId, identifier);
}
/// <summary>
/// Sets the internal token identifier associated with the authentication ticket.
/// Note: the identifier MUST correspond to a valid token entry in the database.
/// </summary>
/// <param name="ticket">The authentication ticket.</param>
/// <param name="identifier">The internal token identifier.</param>
/// <returns>The authentication ticket.</returns>
public static AuthenticationTicket SetInternalTokenId(
[NotNull] this AuthenticationTicket ticket, [CanBeNull] string identifier)
{
if (ticket == null)
{
throw new ArgumentNullException(nameof(ticket));
}
return ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, identifier);
}
}
}

56
test/OpenIddict.EntityFrameworkCore.Tests/OpenIddictEntityFrameworkCoreExtensionsTests.cs

@ -5,12 +5,9 @@
*/
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Moq;
using OpenIddict.Abstractions;
using OpenIddict.Core;
using OpenIddict.EntityFrameworkCore.Models;
@ -101,58 +98,5 @@ namespace OpenIddict.EntityFrameworkCore.Tests
// Assert
Assert.Contains(services, service => service.ServiceType == type && service.ImplementationType == type);
}
[Fact]
public void UseOpenIddict_RegistersDefaultEntityConfigurations()
{
// Arrange
var builder = new ModelBuilder(new ConventionSet());
// Act
builder.UseOpenIddict();
// Assert
Assert.NotNull(builder.Model.FindEntityType(typeof(OpenIddictApplication)));
Assert.NotNull(builder.Model.FindEntityType(typeof(OpenIddictAuthorization)));
Assert.NotNull(builder.Model.FindEntityType(typeof(OpenIddictScope)));
Assert.NotNull(builder.Model.FindEntityType(typeof(OpenIddictToken)));
}
[Fact]
public void UseOpenIddict_RegistersDefaultEntityConfigurationsWithCustomKeyType()
{
// Arrange
var builder = new ModelBuilder(new ConventionSet());
// Act
builder.UseOpenIddict<long>();
// Assert
Assert.NotNull(builder.Model.FindEntityType(typeof(OpenIddictApplication<long>)));
Assert.NotNull(builder.Model.FindEntityType(typeof(OpenIddictAuthorization<long>)));
Assert.NotNull(builder.Model.FindEntityType(typeof(OpenIddictScope<long>)));
Assert.NotNull(builder.Model.FindEntityType(typeof(OpenIddictToken<long>)));
}
[Fact]
public void UseOpenIddict_RegistersCustomEntityConfigurations()
{
// Arrange
var builder = new ModelBuilder(new ConventionSet());
// Act
builder.UseOpenIddict<CustomApplication, CustomAuthorization, CustomScope, CustomToken, Guid>();
// Assert
Assert.NotNull(builder.Model.FindEntityType(typeof(CustomApplication)));
Assert.NotNull(builder.Model.FindEntityType(typeof(CustomAuthorization)));
Assert.NotNull(builder.Model.FindEntityType(typeof(CustomScope)));
Assert.NotNull(builder.Model.FindEntityType(typeof(CustomToken)));
}
public class CustomApplication : OpenIddictApplication<Guid, CustomAuthorization, CustomToken> { }
public class CustomAuthorization : OpenIddictAuthorization<Guid, CustomApplication, CustomToken> { }
public class CustomScope : OpenIddictScope<Guid> { }
public class CustomToken : OpenIddictToken<Guid, CustomApplication, CustomAuthorization> { }
}
}

70
test/OpenIddict.EntityFrameworkCore.Tests/OpenIddictEntityFrameworkCoreHelpersTests.cs

@ -0,0 +1,70 @@
/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://github.com/openiddict/openiddict-core for more information concerning
* the license and the contributors participating to this project.
*/
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
using OpenIddict.EntityFrameworkCore.Models;
using Xunit;
namespace OpenIddict.EntityFrameworkCore.Tests
{
public class OpenIddictEntityFrameworkCoreHelpersTests
{
[Fact]
public void UseOpenIddict_RegistersDefaultEntityConfigurations()
{
// Arrange
var builder = new ModelBuilder(new ConventionSet());
// Act
builder.UseOpenIddict();
// Assert
Assert.NotNull(builder.Model.FindEntityType(typeof(OpenIddictApplication)));
Assert.NotNull(builder.Model.FindEntityType(typeof(OpenIddictAuthorization)));
Assert.NotNull(builder.Model.FindEntityType(typeof(OpenIddictScope)));
Assert.NotNull(builder.Model.FindEntityType(typeof(OpenIddictToken)));
}
[Fact]
public void UseOpenIddict_RegistersDefaultEntityConfigurationsWithCustomKeyType()
{
// Arrange
var builder = new ModelBuilder(new ConventionSet());
// Act
builder.UseOpenIddict<long>();
// Assert
Assert.NotNull(builder.Model.FindEntityType(typeof(OpenIddictApplication<long>)));
Assert.NotNull(builder.Model.FindEntityType(typeof(OpenIddictAuthorization<long>)));
Assert.NotNull(builder.Model.FindEntityType(typeof(OpenIddictScope<long>)));
Assert.NotNull(builder.Model.FindEntityType(typeof(OpenIddictToken<long>)));
}
[Fact]
public void UseOpenIddict_RegistersCustomEntityConfigurations()
{
// Arrange
var builder = new ModelBuilder(new ConventionSet());
// Act
builder.UseOpenIddict<CustomApplication, CustomAuthorization, CustomScope, CustomToken, Guid>();
// Assert
Assert.NotNull(builder.Model.FindEntityType(typeof(CustomApplication)));
Assert.NotNull(builder.Model.FindEntityType(typeof(CustomAuthorization)));
Assert.NotNull(builder.Model.FindEntityType(typeof(CustomScope)));
Assert.NotNull(builder.Model.FindEntityType(typeof(CustomToken)));
}
public class CustomApplication : OpenIddictApplication<Guid, CustomAuthorization, CustomToken> { }
public class CustomAuthorization : OpenIddictAuthorization<Guid, CustomApplication, CustomToken> { }
public class CustomScope : OpenIddictScope<Guid> { }
public class CustomToken : OpenIddictToken<Guid, CustomApplication, CustomAuthorization> { }
}
}

50
test/OpenIddict.Server.Tests/Internal/OpenIddictServerProviderTests.Exchange.cs

@ -717,7 +717,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetPresenters("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AuthorizationCode);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -769,7 +769,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -820,7 +820,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetPresenters("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AuthorizationCode);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -879,7 +879,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetInternalTokenId("60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -937,7 +937,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetPresenters("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AuthorizationCode);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -1005,7 +1005,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetInternalTokenId("60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -1072,9 +1072,9 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetPresenters("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AuthorizationCode);
ticket.SetProperty(OpenIddictConstants.Properties.InternalAuthorizationId, "18D15F73-BE2B-6867-DC01-B3C1E8AFDED0");
ticket.SetInternalAuthorizationId("18D15F73-BE2B-6867-DC01-B3C1E8AFDED0");
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -1155,9 +1155,9 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
ticket.SetProperty(OpenIddictConstants.Properties.InternalAuthorizationId, "18D15F73-BE2B-6867-DC01-B3C1E8AFDED0");
ticket.SetInternalAuthorizationId("18D15F73-BE2B-6867-DC01-B3C1E8AFDED0");
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -1237,9 +1237,9 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetPresenters("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AuthorizationCode);
ticket.SetProperty(OpenIddictConstants.Properties.InternalAuthorizationId, "18D15F73-BE2B-6867-DC01-B3C1E8AFDED0");
ticket.SetInternalAuthorizationId("18D15F73-BE2B-6867-DC01-B3C1E8AFDED0");
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -1332,9 +1332,9 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
ticket.SetProperty(OpenIddictConstants.Properties.InternalAuthorizationId, "18D15F73-BE2B-6867-DC01-B3C1E8AFDED0");
ticket.SetInternalAuthorizationId("18D15F73-BE2B-6867-DC01-B3C1E8AFDED0");
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -1426,7 +1426,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetPresenters("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AuthorizationCode);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -1498,7 +1498,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetInternalTokenId("60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -1568,7 +1568,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetPresenters("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AuthorizationCode);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -1649,7 +1649,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetPresenters("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AuthorizationCode);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -1732,7 +1732,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetPresenters("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AuthorizationCode);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -1812,7 +1812,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetPresenters("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AuthorizationCode);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -1897,8 +1897,8 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetProperty(OpenIddictConstants.Properties.InternalAuthorizationId, "18D15F73-BE2B-6867-DC01-B3C1E8AFDED0");
ticket.SetInternalTokenId("60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetInternalAuthorizationId("18D15F73-BE2B-6867-DC01-B3C1E8AFDED0");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -1975,8 +1975,8 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetProperty(OpenIddictConstants.Properties.InternalAuthorizationId, "18D15F73-BE2B-6867-DC01-B3C1E8AFDED0");
ticket.SetInternalTokenId("60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetInternalAuthorizationId("18D15F73-BE2B-6867-DC01-B3C1E8AFDED0");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -2067,7 +2067,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetInternalTokenId("60FFF7EA-F98E-437B-937E-5073CC313103");
switch (flow)
{

14
test/OpenIddict.Server.Tests/Internal/OpenIddictServerProviderTests.Introspection.cs

@ -213,7 +213,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(type);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -267,7 +267,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AccessToken);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -322,7 +322,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetAudiences("Contoso");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AccessToken);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -429,7 +429,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetAudiences("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AccessToken);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -523,7 +523,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetAudiences("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AccessToken);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -616,7 +616,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetAudiences("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AccessToken);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -715,7 +715,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetAudiences("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AccessToken);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();

8
test/OpenIddict.Server.Tests/Internal/OpenIddictServerProviderTests.Revocation.cs

@ -314,7 +314,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AccessToken);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -395,7 +395,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -439,7 +439,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -488,7 +488,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();

14
test/OpenIddict.Server.Tests/Internal/OpenIddictServerProviderTests.Serialization.cs

@ -86,7 +86,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetAudiences("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AccessToken);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -456,7 +456,7 @@ namespace OpenIddict.Server.Internal.Tests
ticket.SetAudiences("Fabrikam");
ticket.SetTokenId("070AAEDE-38BF-41BE-870C-4E5A73E54566");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -606,7 +606,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetPresenters("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -1180,7 +1180,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetPresenters("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -1312,7 +1312,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -1730,7 +1730,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -2301,7 +2301,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetInternalTokenId("60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetScopes(OpenIddictConstants.Scopes.OpenId, OpenIddictConstants.Scopes.OfflineAccess);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();

32
test/OpenIddict.Server.Tests/Internal/OpenIddictServerProviderTests.cs

@ -155,7 +155,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetInternalTokenId("60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
ticket.SetScopes(OpenIddictConstants.Scopes.OpenId, OpenIddictConstants.Scopes.OfflineAccess);
ticket.SetProperty("custom_property_in_original_ticket", "original_value");
@ -227,7 +227,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetPresenters("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AuthorizationCode);
ticket.SetScopes(OpenIddictConstants.Scopes.OpenId, OpenIddictConstants.Scopes.OfflineAccess);
@ -300,7 +300,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetInternalTokenId("60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
ticket.SetScopes(OpenIddictConstants.Scopes.OpenId, OpenIddictConstants.Scopes.OfflineAccess);
@ -363,7 +363,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
ticket.SetScopes(OpenIddictConstants.Scopes.OpenId, OpenIddictConstants.Scopes.OfflineAccess);
@ -422,7 +422,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetPresenters("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AuthorizationCode);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -491,7 +491,7 @@ namespace OpenIddict.Server.Internal.Tests
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetPresenters("Fabrikam");
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetInternalTokenId("3E228451-1555-46F7-A471-951EFBA23A56");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AuthorizationCode);
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -565,7 +565,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetInternalTokenId("60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
ticket.SetScopes(OpenIddictConstants.Scopes.OpenId, OpenIddictConstants.Scopes.OfflineAccess);
@ -631,7 +631,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetInternalTokenId("60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
ticket.SetScopes(OpenIddictConstants.Scopes.OpenId, OpenIddictConstants.Scopes.OfflineAccess);
@ -701,7 +701,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetInternalTokenId("60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
ticket.SetScopes(OpenIddictConstants.Scopes.OpenId, OpenIddictConstants.Scopes.OfflineAccess);
@ -759,7 +759,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetInternalTokenId("60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
ticket.SetScopes(OpenIddictConstants.Scopes.OpenId, OpenIddictConstants.Scopes.OfflineAccess);
@ -853,10 +853,10 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetInternalTokenId("60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
ticket.SetScopes(OpenIddictConstants.Scopes.OpenId, OpenIddictConstants.Scopes.OfflineAccess);
ticket.SetProperty(OpenIddictConstants.Properties.InternalAuthorizationId, "18D15F73-BE2B-6867-DC01-B3C1E8AFDED0");
ticket.SetInternalAuthorizationId("18D15F73-BE2B-6867-DC01-B3C1E8AFDED0");
var format = new Mock<ISecureDataFormat<AuthenticationTicket>>();
@ -938,7 +938,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetInternalTokenId("60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
ticket.SetScopes(OpenIddictConstants.Scopes.OpenId, OpenIddictConstants.Scopes.OfflineAccess);
@ -1006,7 +1006,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetInternalTokenId("60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
ticket.SetScopes(OpenIddictConstants.Scopes.OpenId, OpenIddictConstants.Scopes.OfflineAccess);
@ -1073,7 +1073,7 @@ namespace OpenIddict.Server.Internal.Tests
new AuthenticationProperties(),
OpenIddictServerDefaults.AuthenticationScheme);
ticket.SetProperty(OpenIddictConstants.Properties.InternalTokenId, "60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetInternalTokenId("60FFF7EA-F98E-437B-937E-5073CC313103");
ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);
ticket.SetScopes(OpenIddictConstants.Scopes.OpenId, OpenIddictConstants.Scopes.OfflineAccess);
@ -1515,7 +1515,7 @@ namespace OpenIddict.Server.Internal.Tests
if (request.HasParameter("attach-authorization"))
{
ticket.SetProperty(OpenIddictConstants.Properties.InternalAuthorizationId, "1AF06AB2-A0FC-4E3D-86AF-E04DA8C7BE70");
ticket.SetInternalAuthorizationId("1AF06AB2-A0FC-4E3D-86AF-E04DA8C7BE70");
}
if (request.HasParameter("attach-public-parameters"))

Loading…
Cancel
Save