From bb011685e905d33ba7df8128781e7b8d09455efe Mon Sep 17 00:00:00 2001 From: Mahmut Gundogdu Date: Fri, 29 Sep 2023 15:26:40 +0000 Subject: [PATCH 1/5] Add Openiddict settings in MultiTenancy --- docs/en/Multi-Tenancy.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/en/Multi-Tenancy.md b/docs/en/Multi-Tenancy.md index 19cf8fa443..5bb34b1eb9 100644 --- a/docs/en/Multi-Tenancy.md +++ b/docs/en/Multi-Tenancy.md @@ -288,6 +288,17 @@ Configure(options => * Add this code to the `ConfigureServices` method of your [module](Module-Development-Basics.md). * This should be done in the *Web/API Layer* since the URL is a web related stuff. +Openiddict is default Auth Server in ABP (since v6.0). When you use OpenIddict, you must add the code on PreConfigure section +```csharp +// using Volo.Abp.OpenIddict.WildcardDomains + +PreConfigure(options=>{ + options.EnableWildcardDomainSupport = true; + options.WildcardDomainsFormat.Add("https://{0}.mydomain.com"); + }); +``` + + > There is an [example](https://github.com/abpframework/abp-samples/tree/master/DomainTenantResolver) that uses the subdomain to determining the current tenant. ##### Custom Tenant Resolvers From af569f75eddfe1dbf06e81ebf864fe8bc86c532f Mon Sep 17 00:00:00 2001 From: Mahmut Gundogdu Date: Mon, 2 Oct 2023 16:26:49 +0300 Subject: [PATCH 2/5] Update Multi-tenancy for domain-based multi tenancy + openiddict --- docs/en/Multi-Tenancy.md | 44 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/docs/en/Multi-Tenancy.md b/docs/en/Multi-Tenancy.md index 5bb34b1eb9..4d8769090c 100644 --- a/docs/en/Multi-Tenancy.md +++ b/docs/en/Multi-Tenancy.md @@ -288,7 +288,7 @@ Configure(options => * Add this code to the `ConfigureServices` method of your [module](Module-Development-Basics.md). * This should be done in the *Web/API Layer* since the URL is a web related stuff. -Openiddict is default Auth Server in ABP (since v6.0). When you use OpenIddict, you must add the code on PreConfigure section +Openiddict is default Auth Server in ABP (since v6.0). When you use OpenIddict, you must add the code on PreConfigure section. ```csharp // using Volo.Abp.OpenIddict.WildcardDomains @@ -298,9 +298,51 @@ PreConfigure(options=>{ }); ``` +You must add the code on Configure section + +```csharp +// using Volo.Abp.MultiTenancy; + +Configure(options=>{ + options.AddDomainTenantResolver("{0}.mydomain.com"); + }); + +``` > There is an [example](https://github.com/abpframework/abp-samples/tree/master/DomainTenantResolver) that uses the subdomain to determining the current tenant. +If you use sepereted Auth server, you must install `Owl.TokenWildcardIssuerValidator` on HTTPApi.Host project +```bash +dotnet add package Owl.TokenWildcardIssuerValidator +``` +Then go to inside block of `.AddJwtBearer` and add the code + +```csharp +// using using Owl.TokenWildcardIssuerValidator; + { + context.Services + .AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddJwtBearer(options => + { + options.Authority = configuration["AuthServer:Authority"]; + options.RequireHttpsMetadata = Convert.ToBoolean( + configuration["AuthServer:RequireHttpsMetadata"] + ); + options.Audience = "ExampleProjectName"; + + // start of added block + options.TokenValidationParameters.IssuerValidator = + TokenWildcardIssuerValidator.IssuerValidator; + options.TokenValidationParameters.ValidIssuers = new[] + { + "https://{0}.mydomain.com:44349/" //the port may different + }; + // end of added block + }); + } + +``` + ##### Custom Tenant Resolvers You can add implement your custom tenant resolver and configure the `AbpTenantResolveOptions` in your module's `ConfigureServices` method as like below: From e034d8c9cfdb3b095669c067ff4a464d675a20a9 Mon Sep 17 00:00:00 2001 From: Hamza Albreem <94292623+braim23@users.noreply.github.com> Date: Mon, 2 Oct 2023 16:53:38 +0300 Subject: [PATCH 3/5] Update Multi-Tenancy.md --- docs/en/Multi-Tenancy.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/en/Multi-Tenancy.md b/docs/en/Multi-Tenancy.md index 4d8769090c..1a4a94ec1e 100644 --- a/docs/en/Multi-Tenancy.md +++ b/docs/en/Multi-Tenancy.md @@ -273,7 +273,7 @@ Configure(options => ##### Domain/Subdomain Tenant Resolver -In a real application, most of times you will want to determine current tenant either by subdomain (like mytenant1.mydomain.com) or by the whole domain (like mytenant.com). If so, you can configure the `AbpTenantResolveOptions` to add the domain tenant resolver. +In a real application, most of times you will want to determine the current tenant either by subdomain (like mytenant1.mydomain.com) or by the whole domain (like mytenant.com). If so, you can configure the `AbpTenantResolveOptions` to add the domain tenant resolver. **Example: Add a subdomain resolver** @@ -284,11 +284,11 @@ Configure(options => }); ```` -* `{0}` is the placeholder to determine current tenant's unique name. +* `{0}` is the placeholder to determine the current tenant's unique name. * Add this code to the `ConfigureServices` method of your [module](Module-Development-Basics.md). * This should be done in the *Web/API Layer* since the URL is a web related stuff. -Openiddict is default Auth Server in ABP (since v6.0). When you use OpenIddict, you must add the code on PreConfigure section. +Openiddict is the default Auth Server in ABP (since v6.0). When you use OpenIddict, you must add this code to the `PreConfigure` method as well. ```csharp // using Volo.Abp.OpenIddict.WildcardDomains @@ -298,7 +298,7 @@ PreConfigure(options=>{ }); ``` -You must add the code on Configure section +You must add this code to the Configure method as well. ```csharp // using Volo.Abp.MultiTenancy; @@ -309,13 +309,13 @@ Configure(options=>{ ``` -> There is an [example](https://github.com/abpframework/abp-samples/tree/master/DomainTenantResolver) that uses the subdomain to determining the current tenant. +> There is an [example](https://github.com/abpframework/abp-samples/tree/master/DomainTenantResolver) that uses the subdomain to determine the current tenant. -If you use sepereted Auth server, you must install `Owl.TokenWildcardIssuerValidator` on HTTPApi.Host project +If you use a sepereted Auth server, you must install `Owl.TokenWildcardIssuerValidator` on the HTTPApi.Host project ```bash dotnet add package Owl.TokenWildcardIssuerValidator ``` -Then go to inside block of `.AddJwtBearer` and add the code +Then fix the options of the `.AddJwtBearer` block ```csharp // using using Owl.TokenWildcardIssuerValidator; From ca8324fc5c91fff7b9271a648934962bd4f8f3b6 Mon Sep 17 00:00:00 2001 From: Hamza Albreem <94292623+braim23@users.noreply.github.com> Date: Mon, 2 Oct 2023 16:54:48 +0300 Subject: [PATCH 4/5] Update Multi-Tenancy.md --- docs/en/Multi-Tenancy.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/Multi-Tenancy.md b/docs/en/Multi-Tenancy.md index 1a4a94ec1e..4b8e938a98 100644 --- a/docs/en/Multi-Tenancy.md +++ b/docs/en/Multi-Tenancy.md @@ -298,7 +298,7 @@ PreConfigure(options=>{ }); ``` -You must add this code to the Configure method as well. +You must add this code to the `Configure` method as well. ```csharp // using Volo.Abp.MultiTenancy; From 03fa59c8ff051fb84f7bb8632596bff71b171b8a Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 2 Oct 2023 20:19:56 -0500 Subject: [PATCH 5/5] Format the c# code. --- docs/en/Multi-Tenancy.md | 51 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/docs/en/Multi-Tenancy.md b/docs/en/Multi-Tenancy.md index 4b8e938a98..661d99da16 100644 --- a/docs/en/Multi-Tenancy.md +++ b/docs/en/Multi-Tenancy.md @@ -289,13 +289,15 @@ Configure(options => * This should be done in the *Web/API Layer* since the URL is a web related stuff. Openiddict is the default Auth Server in ABP (since v6.0). When you use OpenIddict, you must add this code to the `PreConfigure` method as well. + ```csharp // using Volo.Abp.OpenIddict.WildcardDomains -PreConfigure(options=>{ +PreConfigure(options => +{ options.EnableWildcardDomainSupport = true; options.WildcardDomainsFormat.Add("https://{0}.mydomain.com"); - }); +}); ``` You must add this code to the `Configure` method as well. @@ -303,43 +305,42 @@ You must add this code to the `Configure` method as well. ```csharp // using Volo.Abp.MultiTenancy; -Configure(options=>{ +Configure(options => +{ options.AddDomainTenantResolver("{0}.mydomain.com"); - }); +}); ``` > There is an [example](https://github.com/abpframework/abp-samples/tree/master/DomainTenantResolver) that uses the subdomain to determine the current tenant. -If you use a sepereted Auth server, you must install `Owl.TokenWildcardIssuerValidator` on the HTTPApi.Host project +If you use a sepereted Auth server, you must install `[Owl.TokenWildcardIssuerValidator](https://www.nuget.org/packages/Owl.TokenWildcardIssuerValidator)` on the `HTTPApi.Host` project + ```bash dotnet add package Owl.TokenWildcardIssuerValidator ``` + Then fix the options of the `.AddJwtBearer` block ```csharp // using using Owl.TokenWildcardIssuerValidator; + +context.Services + .AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddJwtBearer(options => { - context.Services - .AddAuthentication(JwtBearerDefaults.AuthenticationScheme) - .AddJwtBearer(options => - { - options.Authority = configuration["AuthServer:Authority"]; - options.RequireHttpsMetadata = Convert.ToBoolean( - configuration["AuthServer:RequireHttpsMetadata"] - ); - options.Audience = "ExampleProjectName"; - - // start of added block - options.TokenValidationParameters.IssuerValidator = - TokenWildcardIssuerValidator.IssuerValidator; - options.TokenValidationParameters.ValidIssuers = new[] - { - "https://{0}.mydomain.com:44349/" //the port may different - }; - // end of added block - }); - } + options.Authority = configuration["AuthServer:Authority"]; + options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]); + options.Audience = "ExampleProjectName"; + + // start of added block + options.TokenValidationParameters.IssuerValidator = TokenWildcardIssuerValidator.IssuerValidator; + options.TokenValidationParameters.ValidIssuers = new[] + { + "https://{0}.mydomain.com:44349/" //the port may different + }; + // end of added block + }); ```