From f669cd5b265bcde1bcfb66f4277a5ace9ba7a6c3 Mon Sep 17 00:00:00 2001 From: OpenIddict Bot <32257313+openiddict-bot@users.noreply.github.com> Date: Tue, 29 Jun 2021 17:26:33 +0000 Subject: [PATCH] Update the documentation pages --- .../encryption-and-signing-credentials.html | 4 +- configuration/mongodb-integration.html | 229 ++++++++++++++++++ configuration/toc.html | 3 + manifest.json | 18 +- 4 files changed, 249 insertions(+), 5 deletions(-) create mode 100644 configuration/mongodb-integration.html diff --git a/configuration/encryption-and-signing-credentials.html b/configuration/encryption-and-signing-credentials.html index 20ab062..63dcc3e 100644 --- a/configuration/encryption-and-signing-credentials.html +++ b/configuration/encryption-and-signing-credentials.html @@ -76,7 +76,7 @@
Note

Tokens generated using the opt-in ASP.NET Core Data Protection integration rely on their own key ring, distinct from the credentials discussed in this documentation. For more information about Data Protection, visit ASP.NET Core Data Protection.

-

Registering credentials in the server options

+

Registering credentials in the authorization server options

OpenIddict allows registering one or multiple keys (raw keys or embedded in X.509 certificates).

Note

When multiple keys/certificates are registered (which can be useful to implement keys rotation), OpenIddict chooses the most appropriate key based on the following algorithm:

    @@ -161,7 +161,7 @@ var data = certificate.Export(X509ContentType.Pfx, string.Empty);
  • On Azure, certificates can be uploaded and exposed to Azure App Services applications using the special WEBSITE_LOAD_CERTIFICATES flag. For more information, visit https://docs.microsoft.com/en-us/azure/app-service/configure-ssl-certificate-in-code
-

Importing credentials in the validation options

+

Importing credentials in the API/resource validation options

Using the options.UseLocalServer() integration

When the API and the authorization server are part of the same project, both the signing and encryption credentials can be easily imported by calling options.UseLocalServer():

diff --git a/configuration/mongodb-integration.html b/configuration/mongodb-integration.html new file mode 100644 index 0000000..74da94b --- /dev/null +++ b/configuration/mongodb-integration.html @@ -0,0 +1,229 @@ + + + + + + + + MongoDB integration + + + + + + + + + + + + + + + +
+
+ +
+
+
+ + + + +
+
+
+
+ +
+
+
+
+
+ +
+
+
    +
  • +
+
+
+
+
+ +
+ Show / Hide Table of Contents +
+
+
+
+
+
+
+

MongoDB integration

+ +

To configure OpenIddict to use MongoDB as the database for applications, authorizations, scopes and tokens, you'll need to:

+
    +
  • Reference the OpenIddict.MongoDb package:

    +
    <PackageReference Include="OpenIddict.MongoDb" Version="3.0.5" />
    +
  • +
  • Configure OpenIddict to use the MongoDB stores:

    +
    services.AddOpenIddict()
    +    .AddCore(options =>
    +    {
    +        // Note: to use a remote server, call the MongoClient constructor overload
    +        // that accepts a connection string or an instance of MongoClientSettings.
    +        options.UseMongoDb()
    +               .UseDatabase(new MongoClient().GetDatabase("openiddict"));
    +    })
    +
  • +
  • Create indexes to improve performance (recommended): for that, you can use the following script to +initialize the database and create the indexes used by the OpenIddict entities:

    +
    using System.Threading;
    +using Microsoft.Extensions.DependencyInjection;
    +using Microsoft.Extensions.Options;
    +using MongoDB.Driver;
    +using OpenIddict.MongoDb;
    +using OpenIddict.MongoDb.Models;
    +
    +var services = new ServiceCollection();
    +services.AddOpenIddict()
    +    .AddCore(options => options.UseMongoDb());
    +
    +services.AddSingleton(new MongoClient("mongodb://localhost:27017").GetDatabase("openiddict"));
    +
    +var provider = services.BuildServiceProvider();
    +var context = provider.GetRequiredService<IOpenIddictMongoDbContext>();
    +var options = provider.GetRequiredService<IOptionsMonitor<OpenIddictMongoDbOptions>>().CurrentValue;
    +var database = await context.GetDatabaseAsync(CancellationToken.None);
    +
    +var applications = database.GetCollection<OpenIddictMongoDbApplication>(
    +    options.ApplicationsCollectionName);
    +
    +await applications.Indexes.CreateManyAsync(new[]
    +{
    +    new CreateIndexModel<OpenIddictMongoDbApplication>(
    +        Builders<OpenIddictMongoDbApplication>.IndexKeys.Ascending(
    +            application => application.ClientId),
    +        new CreateIndexOptions
    +        {
    +            Unique = true
    +        }),
    +
    +    new CreateIndexModel<OpenIddictMongoDbApplication>(
    +        Builders<OpenIddictMongoDbApplication>.IndexKeys.Ascending(
    +            application => application.PostLogoutRedirectUris),
    +        new CreateIndexOptions
    +        {
    +            Background = true
    +        }),
    +
    +    new CreateIndexModel<OpenIddictMongoDbApplication>(
    +        Builders<OpenIddictMongoDbApplication>.IndexKeys.Ascending(
    +            application => application.RedirectUris),
    +        new CreateIndexOptions
    +        {
    +            Background = true
    +        })
    +});
    +
    +var authorizations = database.GetCollection<OpenIddictMongoDbAuthorization>(
    +    options.AuthorizationsCollectionName);
    +
    +await authorizations.Indexes.CreateOneAsync(new CreateIndexModel<OpenIddictMongoDbAuthorization>(
    +    Builders<OpenIddictMongoDbAuthorization>.IndexKeys
    +        .Ascending(authorization => authorization.ApplicationId)
    +        .Ascending(authorization => authorization.Scopes)
    +        .Ascending(authorization => authorization.Status)
    +        .Ascending(authorization => authorization.Subject)
    +        .Ascending(authorization => authorization.Type),
    +    new CreateIndexOptions
    +    {
    +        Background = true
    +    }));
    +
    +var scopes = database.GetCollection<OpenIddictMongoDbScope>(
    +    options.ScopesCollectionName);
    +
    +await scopes.Indexes.CreateOneAsync(new CreateIndexModel<OpenIddictMongoDbScope>(
    +    Builders<OpenIddictMongoDbScope>.IndexKeys.Ascending(scope => scope.Name),
    +    new CreateIndexOptions
    +    {
    +        Unique = true
    +    }));
    +
    +var tokens = database.GetCollection<OpenIddictMongoDbToken>(
    +    options.TokensCollectionName);
    +
    +await tokens.Indexes.CreateManyAsync(new[]
    +{
    +    new CreateIndexModel<OpenIddictMongoDbToken>(
    +        Builders<OpenIddictMongoDbToken>.IndexKeys.Ascending(token => token.ReferenceId),
    +        new CreateIndexOptions<OpenIddictMongoDbToken>
    +        {
    +            // Note: partial filter expressions are not supported on Azure Cosmos DB.
    +            // As a workaround, the expression and the unique constraint can be removed.
    +            PartialFilterExpression =
    +                Builders<OpenIddictMongoDbToken>.Filter.Exists(token => token.ReferenceId),
    +            Unique = true
    +        }),
    +
    +    new CreateIndexModel<OpenIddictMongoDbToken>(
    +        Builders<OpenIddictMongoDbToken>.IndexKeys
    +            .Ascending(token => token.ApplicationId)
    +            .Ascending(token => token.Status)
    +            .Ascending(token => token.Subject)
    +            .Ascending(token => token.Type),
    +        new CreateIndexOptions
    +        {
    +            Background = true
    +        })
    +});
    +
  • +
+
+
+ +
+
+
+
    +
  • + Improve this Doc +
  • +
+
+
+
In This Article
+
+
+
+
+
+
+ +
+
+
+
+ + Back to top + + + Generated by DocFX +
+
+
+
+ + + + + + diff --git a/configuration/toc.html b/configuration/toc.html index 6945c49..85a516a 100644 --- a/configuration/toc.html +++ b/configuration/toc.html @@ -27,6 +27,9 @@
  • Encryption and signing credentials
  • +
  • + MongoDB integration +
  • Proof Key for Code Exchange
  • diff --git a/manifest.json b/manifest.json index d501d41..3792d89 100644 --- a/manifest.json +++ b/manifest.json @@ -5637,7 +5637,7 @@ "output": { ".html": { "relative_path": "configuration/encryption-and-signing-credentials.html", - "hash": "lvfp+KasSL8PFb2HTzMYhQ==" + "hash": "iFuVtyllFrW9BzppnmPRig==" } }, "is_incremental": false, @@ -5655,6 +5655,18 @@ "is_incremental": false, "version": "" }, + { + "type": "Conceptual", + "source_relative_path": "configuration/mongodb-integration.md", + "output": { + ".html": { + "relative_path": "configuration/mongodb-integration.html", + "hash": "OBbgaaZ+b0E3MY4vEl7/kw==" + } + }, + "is_incremental": false, + "version": "" + }, { "type": "Conceptual", "source_relative_path": "configuration/proof-key-for-code-exchange.md", @@ -5673,7 +5685,7 @@ "output": { ".html": { "relative_path": "configuration/toc.html", - "hash": "OsKSxgt/kroRjpQlAjf8PA==" + "hash": "v0DMuwk5yrDID+1ORgzjDQ==" } }, "is_incremental": false, @@ -7977,7 +7989,7 @@ "ConceptualDocumentProcessor": { "can_incremental": false, "incrementalPhase": "build", - "total_file_count": 131, + "total_file_count": 132, "skipped_file_count": 0 }, "ManagedReferenceDocumentProcessor": {