From 41479619715673999f0b3c5dfaf879999d97eb04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Fri, 30 Dec 2016 17:13:42 +0100 Subject: [PATCH] Update README.md --- README.md | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index c62d68ba..d2d9cf80 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,8 @@ public void ConfigureServices(IServiceCollection services) { .AddDefaultTokenProviders(); // Register the OpenIddict services. + // Note: use the generic overload if you need + // to replace the default OpenIddict entities. services.AddOpenIddict() // Register the Entity Framework stores. .AddEntityFrameworkCoreStores() @@ -174,6 +176,8 @@ The **Mvc.Server sample comes with an [`AuthorizationController` that supports b ```csharp public void ConfigureServices(IServiceCollection services) { // Register the OpenIddict services. + // Note: use the generic overload if you need + // to replace the default OpenIddict entities. services.AddOpenIddict() // Register the Entity Framework stores. .AddEntityFrameworkCoreStores() @@ -203,33 +207,21 @@ public void ConfigureServices(IServiceCollection services) { - **Register your client application**: ```csharp -using (var context = new ApplicationDbContext( - app.ApplicationServices.GetRequiredService>())) { - context.Database.EnsureCreated(); - - var applications = context.Set(); - - if (!applications.Any()) { - applications.Add(new OpenIddictApplication { - // Assign a unique identifier to your client app: - Id = "48BF1BC3-CE01-4787-BBF2-0426EAD21342", - - // Assign a display named used in the consent form page: - DisplayName = "MVC Core client application", - - // Register the appropriate redirect_uri and post_logout_redirect_uri: - RedirectUri = "http://localhost:53507/signin-oidc", - LogoutRedirectUri = "http://localhost:53507/", - - // Generate a new derived key from the client secret: - Secret = Crypto.HashPassword("secret_secret_secret"), - - // Note: use "public" for JS/mobile/desktop applications - // and "confidential" for server-side applications. - Type = OpenIddictConstants.ClientTypes.Confidential - }); - - context.SaveChanges(); +// Create a new service scope to ensure the database context is correctly disposed when this methods returns. +using (var scope = app.ApplicationServices.GetRequiredService().CreateScope()) { + var context = scope.ServiceProvider.GetRequiredService(); + await context.Database.EnsureCreatedAsync(); + + // Note: when using a custom entity or a custom key type, replace OpenIddictApplication by the appropriate type. + var manager = scope.ServiceProvider.GetRequiredService>(); + + if (await manager.FindByClientIdAsync("[client identifier]", cancellationToken) == null) { + var application = new OpenIddictApplication { + ClientId = "[client identifier]", + RedirectUri = "[redirect uri]" + }; + + await manager.CreateAsync(application, "[client secret]", cancellationToken); } } ```