Browse Source

Update OpenIddictServerExtensions to throw an exception when the core services are not registered

pull/619/head
Kévin Chalet 8 years ago
parent
commit
2bc86ea255
  1. 2
      src/OpenIddict.EntityFramework/Resolvers/OpenIddictApplicationStoreResolver.cs
  2. 2
      src/OpenIddict.EntityFramework/Resolvers/OpenIddictAuthorizationStoreResolver.cs
  3. 2
      src/OpenIddict.EntityFramework/Resolvers/OpenIddictScopeStoreResolver.cs
  4. 2
      src/OpenIddict.EntityFramework/Resolvers/OpenIddictTokenStoreResolver.cs
  5. 2
      src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictApplicationStoreResolver.cs
  6. 2
      src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictAuthorizationStoreResolver.cs
  7. 2
      src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictScopeStoreResolver.cs
  8. 2
      src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictTokenStoreResolver.cs
  9. 19
      src/OpenIddict.Server/OpenIddictServerExtensions.cs

2
src/OpenIddict.EntityFramework/Resolvers/OpenIddictApplicationStoreResolver.cs

@ -66,7 +66,7 @@ namespace OpenIddict.EntityFramework
throw new InvalidOperationException(new StringBuilder() throw new InvalidOperationException(new StringBuilder()
.AppendLine("No Entity Framework 6.x context was specified in the OpenIddict options.") .AppendLine("No Entity Framework 6.x context was specified in the OpenIddict options.")
.Append("To configure the OpenIddict Entity Framework 6.x stores to use a specific 'DbContext', ") .Append("To configure the OpenIddict Entity Framework 6.x stores to use a specific 'DbContext', ")
.Append("use 'options.AddEntityFrameworkStores().UseContext<TContext>()'.") .Append("use 'options.UseEntityFramework().UseDbContext<TContext>()'.")
.ToString()); .ToString());
} }

2
src/OpenIddict.EntityFramework/Resolvers/OpenIddictAuthorizationStoreResolver.cs

@ -66,7 +66,7 @@ namespace OpenIddict.EntityFramework
throw new InvalidOperationException(new StringBuilder() throw new InvalidOperationException(new StringBuilder()
.AppendLine("No Entity Framework 6.x context was specified in the OpenIddict options.") .AppendLine("No Entity Framework 6.x context was specified in the OpenIddict options.")
.Append("To configure the OpenIddict Entity Framework 6.x stores to use a specific 'DbContext', ") .Append("To configure the OpenIddict Entity Framework 6.x stores to use a specific 'DbContext', ")
.Append("use 'options.AddEntityFrameworkStores().UseContext<TContext>()'.") .Append("use 'options.UseEntityFramework().UseDbContext<TContext>()'.")
.ToString()); .ToString());
} }

2
src/OpenIddict.EntityFramework/Resolvers/OpenIddictScopeStoreResolver.cs

@ -66,7 +66,7 @@ namespace OpenIddict.EntityFramework
throw new InvalidOperationException(new StringBuilder() throw new InvalidOperationException(new StringBuilder()
.AppendLine("No Entity Framework 6.x context was specified in the OpenIddict options.") .AppendLine("No Entity Framework 6.x context was specified in the OpenIddict options.")
.Append("To configure the OpenIddict Entity Framework 6.x stores to use a specific 'DbContext', ") .Append("To configure the OpenIddict Entity Framework 6.x stores to use a specific 'DbContext', ")
.Append("use 'options.AddEntityFrameworkStores().UseContext<TContext>()'.") .Append("use 'options.UseEntityFramework().UseDbContext<TContext>()'.")
.ToString()); .ToString());
} }

2
src/OpenIddict.EntityFramework/Resolvers/OpenIddictTokenStoreResolver.cs

@ -66,7 +66,7 @@ namespace OpenIddict.EntityFramework
throw new InvalidOperationException(new StringBuilder() throw new InvalidOperationException(new StringBuilder()
.AppendLine("No Entity Framework 6.x context was specified in the OpenIddict options.") .AppendLine("No Entity Framework 6.x context was specified in the OpenIddict options.")
.Append("To configure the OpenIddict Entity Framework 6.x stores to use a specific 'DbContext', ") .Append("To configure the OpenIddict Entity Framework 6.x stores to use a specific 'DbContext', ")
.Append("use 'options.AddEntityFrameworkStores().UseContext<TContext>()'.") .Append("use 'options.UseEntityFramework().UseDbContext<TContext>()'.")
.ToString()); .ToString());
} }

2
src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictApplicationStoreResolver.cs

@ -66,7 +66,7 @@ namespace OpenIddict.EntityFrameworkCore
throw new InvalidOperationException(new StringBuilder() throw new InvalidOperationException(new StringBuilder()
.AppendLine("No Entity Framework Core context was specified in the OpenIddict options.") .AppendLine("No Entity Framework Core context was specified in the OpenIddict options.")
.Append("To configure the OpenIddict Entity Framework Core stores to use a specific 'DbContext', ") .Append("To configure the OpenIddict Entity Framework Core stores to use a specific 'DbContext', ")
.Append("use 'options.AddEntityFrameworkCoreStores().UseContext<TContext>()'.") .Append("use 'options.UseEntityFrameworkCore().UseDbContext<TContext>()'.")
.ToString()); .ToString());
} }

2
src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictAuthorizationStoreResolver.cs

@ -67,7 +67,7 @@ namespace OpenIddict.EntityFrameworkCore
throw new InvalidOperationException(new StringBuilder() throw new InvalidOperationException(new StringBuilder()
.AppendLine("No Entity Framework Core context was specified in the OpenIddict options.") .AppendLine("No Entity Framework Core context was specified in the OpenIddict options.")
.Append("To configure the OpenIddict Entity Framework Core stores to use a specific 'DbContext', ") .Append("To configure the OpenIddict Entity Framework Core stores to use a specific 'DbContext', ")
.Append("use 'options.AddEntityFrameworkCoreStores().UseContext<TContext>()'.") .Append("use 'options.UseEntityFrameworkCore().UseDbContext<TContext>()'.")
.ToString()); .ToString());
} }

2
src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictScopeStoreResolver.cs

@ -66,7 +66,7 @@ namespace OpenIddict.EntityFrameworkCore
throw new InvalidOperationException(new StringBuilder() throw new InvalidOperationException(new StringBuilder()
.AppendLine("No Entity Framework Core context was specified in the OpenIddict options.") .AppendLine("No Entity Framework Core context was specified in the OpenIddict options.")
.Append("To configure the OpenIddict Entity Framework Core stores to use a specific 'DbContext', ") .Append("To configure the OpenIddict Entity Framework Core stores to use a specific 'DbContext', ")
.Append("use 'options.AddEntityFrameworkCoreStores().UseContext<TContext>()'.") .Append("use 'options.UseEntityFrameworkCore().UseDbContext<TContext>()'.")
.ToString()); .ToString());
} }

2
src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictTokenStoreResolver.cs

@ -66,7 +66,7 @@ namespace OpenIddict.EntityFrameworkCore
throw new InvalidOperationException(new StringBuilder() throw new InvalidOperationException(new StringBuilder()
.AppendLine("No Entity Framework Core context was specified in the OpenIddict options.") .AppendLine("No Entity Framework Core context was specified in the OpenIddict options.")
.Append("To configure the OpenIddict Entity Framework Core stores to use a specific 'DbContext', ") .Append("To configure the OpenIddict Entity Framework Core stores to use a specific 'DbContext', ")
.Append("use 'options.AddEntityFrameworkCoreStores().UseContext<TContext>()'.") .Append("use 'options.UseEntityFrameworkCore().UseDbContext<TContext>()'.")
.ToString()); .ToString());
} }

19
src/OpenIddict.Server/OpenIddictServerExtensions.cs

@ -5,11 +5,14 @@
*/ */
using System; using System;
using System.Text;
using AspNet.Security.OpenIdConnect.Server; using AspNet.Security.OpenIdConnect.Server;
using JetBrains.Annotations; using JetBrains.Annotations;
using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication;
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using OpenIddict.Abstractions;
using OpenIddict.Server; using OpenIddict.Server;
namespace Microsoft.Extensions.DependencyInjection namespace Microsoft.Extensions.DependencyInjection
@ -32,7 +35,21 @@ namespace Microsoft.Extensions.DependencyInjection
builder.Services.AddAuthentication(); builder.Services.AddAuthentication();
builder.Services.TryAddScoped<OpenIddictServerHandler>(); builder.Services.TryAddScoped<OpenIddictServerHandler>();
builder.Services.TryAddScoped<OpenIddictServerProvider>(); builder.Services.TryAddScoped(provider =>
{
InvalidOperationException CreateException()
=> new InvalidOperationException(new StringBuilder()
.AppendLine("The core services must be registered when enabling the server handler.")
.Append("To register the OpenIddict core services, use 'services.AddOpenIddict().AddCore()'.")
.ToString());
return new OpenIddictServerProvider(
provider.GetRequiredService<ILogger<OpenIddictServerProvider>>(),
provider.GetService<IOpenIddictApplicationManager>() ?? throw CreateException(),
provider.GetService<IOpenIddictAuthorizationManager>() ?? throw CreateException(),
provider.GetService<IOpenIddictScopeManager>() ?? throw CreateException(),
provider.GetService<IOpenIddictTokenManager>() ?? throw CreateException());
});
// Register the options initializers used by the OpenID Connect server handler and OpenIddict. // Register the options initializers used by the OpenID Connect server handler and OpenIddict.
// Note: TryAddEnumerable() is used here to ensure the initializers are only registered once. // Note: TryAddEnumerable() is used here to ensure the initializers are only registered once.

Loading…
Cancel
Save