From 4a9f0ba8ae0fe77c999f7ed2fb8f0fa09cec6508 Mon Sep 17 00:00:00 2001 From: Mahmut Gundogdu Date: Mon, 23 Jan 2023 17:54:11 +0300 Subject: [PATCH 01/11] Add HttpContext variable and skip it http interceptor logic when it is true --- .../core/src/lib/clients/http.client.ts | 30 +++++++++++++++++++ .../packages/core/src/lib/clients/index.ts | 1 + .../src/lib/interceptors/api.interceptor.ts | 4 +++ .../core/src/lib/tokens/http-context.token.ts | 3 ++ npm/ng-packs/packages/core/src/public-api.ts | 1 + 5 files changed, 39 insertions(+) create mode 100644 npm/ng-packs/packages/core/src/lib/clients/http.client.ts create mode 100644 npm/ng-packs/packages/core/src/lib/clients/index.ts create mode 100644 npm/ng-packs/packages/core/src/lib/tokens/http-context.token.ts diff --git a/npm/ng-packs/packages/core/src/lib/clients/http.client.ts b/npm/ng-packs/packages/core/src/lib/clients/http.client.ts new file mode 100644 index 0000000000..c6e9017be7 --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/clients/http.client.ts @@ -0,0 +1,30 @@ +import { HttpClient, HttpContext, HttpRequest } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { IS_EXTERNAL_REQUEST } from '../tokens/http-context.token'; + +// source : https://github.com/armanozak/demo-angular-server-specific-interceptors +@Injectable({ + providedIn: 'root', +}) +export class ExternalHttpClient extends HttpClient { + override request( + first: string | HttpRequest, + url?: string, + options: RequestOptions = {}, + ): Observable { + if (typeof first === 'string') { + this.#setPlaceholderContext(options); + return super.request(first, url, options); + } + + this.#setPlaceholderContext(first); + return super.request(first); + } + #setPlaceholderContext(optionsOrRequest: { context?: HttpContext }) { + optionsOrRequest.context ??= new HttpContext(); + optionsOrRequest.context.set(IS_EXTERNAL_REQUEST, true); + } +} + +type RequestOptions = Parameters[2]; diff --git a/npm/ng-packs/packages/core/src/lib/clients/index.ts b/npm/ng-packs/packages/core/src/lib/clients/index.ts new file mode 100644 index 0000000000..c9aba4d030 --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/clients/index.ts @@ -0,0 +1 @@ +export * from './http.client'; diff --git a/npm/ng-packs/packages/core/src/lib/interceptors/api.interceptor.ts b/npm/ng-packs/packages/core/src/lib/interceptors/api.interceptor.ts index d3dbe19ec0..aef5b9e706 100644 --- a/npm/ng-packs/packages/core/src/lib/interceptors/api.interceptor.ts +++ b/npm/ng-packs/packages/core/src/lib/interceptors/api.interceptor.ts @@ -5,6 +5,7 @@ import { finalize } from 'rxjs/operators'; import { SessionStateService } from '../services/session-state.service'; import { HttpWaitService } from '../services/http-wait.service'; import { TENANT_KEY } from '../tokens/tenant-key.token'; +import { IS_EXTERNAL_REQUEST } from '../tokens/http-context.token'; @Injectable({ providedIn: 'root', @@ -18,6 +19,9 @@ export class ApiInterceptor implements HttpInterceptor { ) {} intercept(request: HttpRequest, next: HttpHandler) { + if (request.context?.get(IS_EXTERNAL_REQUEST)) { + return next.handle(request); + } this.httpWaitService.addRequest(request); return next .handle( diff --git a/npm/ng-packs/packages/core/src/lib/tokens/http-context.token.ts b/npm/ng-packs/packages/core/src/lib/tokens/http-context.token.ts new file mode 100644 index 0000000000..e935232b08 --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/tokens/http-context.token.ts @@ -0,0 +1,3 @@ +import { HttpContextToken } from '@angular/common/http'; + +export const IS_EXTERNAL_REQUEST = new HttpContextToken(() => false); diff --git a/npm/ng-packs/packages/core/src/public-api.ts b/npm/ng-packs/packages/core/src/public-api.ts index a5cbd78e4e..e740b4c4df 100644 --- a/npm/ng-packs/packages/core/src/public-api.ts +++ b/npm/ng-packs/packages/core/src/public-api.ts @@ -23,3 +23,4 @@ export * from './lib/strategies'; export * from './lib/tokens'; export * from './lib/utils'; export * from './lib/validators'; +export * from './lib/clients'; From 395369f968a329e0a49e3b0b69ed2ee59d3d4c31 Mon Sep 17 00:00:00 2001 From: Mahmut Gundogdu Date: Mon, 23 Jan 2023 19:06:27 +0300 Subject: [PATCH 02/11] HttpWait service always must call. with or without `IS_EXTERNAL_REQUEST`. --- .../core/src/lib/interceptors/api.interceptor.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/npm/ng-packs/packages/core/src/lib/interceptors/api.interceptor.ts b/npm/ng-packs/packages/core/src/lib/interceptors/api.interceptor.ts index aef5b9e706..e09bb6292e 100644 --- a/npm/ng-packs/packages/core/src/lib/interceptors/api.interceptor.ts +++ b/npm/ng-packs/packages/core/src/lib/interceptors/api.interceptor.ts @@ -19,16 +19,15 @@ export class ApiInterceptor implements HttpInterceptor { ) {} intercept(request: HttpRequest, next: HttpHandler) { - if (request.context?.get(IS_EXTERNAL_REQUEST)) { - return next.handle(request); - } this.httpWaitService.addRequest(request); - return next - .handle( - request.clone({ + const isExternalRequest = request.context?.get(IS_EXTERNAL_REQUEST); + const newRequest = isExternalRequest + ? request + : request.clone({ setHeaders: this.getAdditionalHeaders(request.headers), - }), - ) + }); + return next + .handle(newRequest) .pipe(finalize(() => this.httpWaitService.deleteRequest(request))); } From d361802de2b4512ae80ca8168aab23a6ba86d665 Mon Sep 17 00:00:00 2001 From: Mahmut Gundogdu Date: Mon, 23 Jan 2023 19:08:05 +0300 Subject: [PATCH 03/11] Add documentation --- .../How-To-Skip-ABP-Headers-And-Interceptors.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 docs/en/UI/Angular/How-To-Skip-ABP-Headers-And-Interceptors.md diff --git a/docs/en/UI/Angular/How-To-Skip-ABP-Headers-And-Interceptors.md b/docs/en/UI/Angular/How-To-Skip-ABP-Headers-And-Interceptors.md new file mode 100644 index 0000000000..b52f72b27c --- /dev/null +++ b/docs/en/UI/Angular/How-To-Skip-ABP-Headers-And-Interceptors.md @@ -0,0 +1,10 @@ +# How to Skip HTTP interceptors and ABP headers + +The ABP Framework adds several HTTP headers to the HttpClient, such as the "Auth token" or "tenant Id." +ABP Server must possess the information but the ABP user may not want to send this informations to a external server. +ExternalHttpClient and IS EXTERNAL REQUEST HttpContext Token were added in V6.0.4. +THe ABP Http interceptors check value of `` token. Adding headers is skipped by the interceptor if it is present and its value is true. +The `ExternalHttpClient` extends from `HTTPClient` and set `IS_EXTERNAL_REQUEST` Context token to true. +When you are using `ExternalHttpClient` as HttpClient in your components, it does not add ABP-specific headers. + +Note: With `IS_EXTERNAL_REQUEST` or without, ABP loading service work. From 8c2f37bd3da4fb3f07f995d22e2dba4caf83b0a3 Mon Sep 17 00:00:00 2001 From: Mahmut Gundogdu Date: Tue, 24 Jan 2023 09:54:47 +0300 Subject: [PATCH 04/11] Update doc --- docs/en/UI/Angular/How-To-Skip-ABP-Headers-And-Interceptors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/UI/Angular/How-To-Skip-ABP-Headers-And-Interceptors.md b/docs/en/UI/Angular/How-To-Skip-ABP-Headers-And-Interceptors.md index b52f72b27c..2f3d51643b 100644 --- a/docs/en/UI/Angular/How-To-Skip-ABP-Headers-And-Interceptors.md +++ b/docs/en/UI/Angular/How-To-Skip-ABP-Headers-And-Interceptors.md @@ -3,7 +3,7 @@ The ABP Framework adds several HTTP headers to the HttpClient, such as the "Auth token" or "tenant Id." ABP Server must possess the information but the ABP user may not want to send this informations to a external server. ExternalHttpClient and IS EXTERNAL REQUEST HttpContext Token were added in V6.0.4. -THe ABP Http interceptors check value of `` token. Adding headers is skipped by the interceptor if it is present and its value is true. +THe ABP Http interceptors check value of `IS_EXTERNAL_REQUEST` token. When the token is True, ABP-specific headers don't add to Http Request. The `ExternalHttpClient` extends from `HTTPClient` and set `IS_EXTERNAL_REQUEST` Context token to true. When you are using `ExternalHttpClient` as HttpClient in your components, it does not add ABP-specific headers. From 857626a52324bb2568da64bb227f40568f4a058f Mon Sep 17 00:00:00 2001 From: Hamza Albreem <94292623+braim23@users.noreply.github.com> Date: Tue, 24 Jan 2023 10:00:48 +0300 Subject: [PATCH 05/11] quick fix for the How-To-Skip-ABP-Headers-And-Interceptors doc --- .../How-To-Skip-ABP-Headers-And-Interceptors.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/en/UI/Angular/How-To-Skip-ABP-Headers-And-Interceptors.md b/docs/en/UI/Angular/How-To-Skip-ABP-Headers-And-Interceptors.md index 2f3d51643b..4c8a09f136 100644 --- a/docs/en/UI/Angular/How-To-Skip-ABP-Headers-And-Interceptors.md +++ b/docs/en/UI/Angular/How-To-Skip-ABP-Headers-And-Interceptors.md @@ -1,10 +1,10 @@ # How to Skip HTTP interceptors and ABP headers -The ABP Framework adds several HTTP headers to the HttpClient, such as the "Auth token" or "tenant Id." -ABP Server must possess the information but the ABP user may not want to send this informations to a external server. +The ABP Framework adds several HTTP headers to the HttpClient, such as the "Auth token" or "tenant Id". +The ABP Server must possess the information but the ABP user may not want to send this informations to an external server. ExternalHttpClient and IS EXTERNAL REQUEST HttpContext Token were added in V6.0.4. -THe ABP Http interceptors check value of `IS_EXTERNAL_REQUEST` token. When the token is True, ABP-specific headers don't add to Http Request. -The `ExternalHttpClient` extends from `HTTPClient` and set `IS_EXTERNAL_REQUEST` Context token to true. +The ABP Http interceptors check the value of the `IS_EXTERNAL_REQUEST` token. If the token is True then ABP-specific headers won't be added to Http Request. +The `ExternalHttpClient` extends from `HTTPClient` and sets the `IS_EXTERNAL_REQUEST` context token to true. When you are using `ExternalHttpClient` as HttpClient in your components, it does not add ABP-specific headers. -Note: With `IS_EXTERNAL_REQUEST` or without, ABP loading service work. +Note: With `IS_EXTERNAL_REQUEST` or without it, ABP loading service works. From 4a0704566a528460f1b89d068e7f92fcbabdf820 Mon Sep 17 00:00:00 2001 From: Mahmut Gundogdu Date: Tue, 24 Jan 2023 10:51:16 +0300 Subject: [PATCH 06/11] add token index.ts, move doc HTTP Requests file --- docs/en/UI/Angular/HTTP-Requests.md | 12 ++++++++++++ .../How-To-Skip-ABP-Headers-And-Interceptors.md | 10 ---------- npm/ng-packs/packages/core/src/lib/tokens/index.ts | 1 + 3 files changed, 13 insertions(+), 10 deletions(-) delete mode 100644 docs/en/UI/Angular/How-To-Skip-ABP-Headers-And-Interceptors.md diff --git a/docs/en/UI/Angular/HTTP-Requests.md b/docs/en/UI/Angular/HTTP-Requests.md index 57a058ef36..a0e53df9c9 100644 --- a/docs/en/UI/Angular/HTTP-Requests.md +++ b/docs/en/UI/Angular/HTTP-Requests.md @@ -298,3 +298,15 @@ export function handleHttpErrors(injector: Injector, httpError: HttpErrorRespons return throwError(httpError) } ``` + + +### How to Skip HTTP interceptors and ABP headers + +The ABP Framework adds several HTTP headers to the HttpClient, such as the "Auth token" or "tenant Id". +The ABP Server must possess the information but the ABP user may not want to send this informations to an external server. +ExternalHttpClient and IS EXTERNAL REQUEST HttpContext Token were added in V6.0.4. +The ABP Http interceptors check the value of the `IS_EXTERNAL_REQUEST` token. If the token is True then ABP-specific headers won't be added to Http Request. +The `ExternalHttpClient` extends from `HTTPClient` and sets the `IS_EXTERNAL_REQUEST` context token to true. +When you are using `ExternalHttpClient` as HttpClient in your components, it does not add ABP-specific headers. + +Note: With `IS_EXTERNAL_REQUEST` or without it, ABP loading service works. diff --git a/docs/en/UI/Angular/How-To-Skip-ABP-Headers-And-Interceptors.md b/docs/en/UI/Angular/How-To-Skip-ABP-Headers-And-Interceptors.md deleted file mode 100644 index 4c8a09f136..0000000000 --- a/docs/en/UI/Angular/How-To-Skip-ABP-Headers-And-Interceptors.md +++ /dev/null @@ -1,10 +0,0 @@ -# How to Skip HTTP interceptors and ABP headers - -The ABP Framework adds several HTTP headers to the HttpClient, such as the "Auth token" or "tenant Id". -The ABP Server must possess the information but the ABP user may not want to send this informations to an external server. -ExternalHttpClient and IS EXTERNAL REQUEST HttpContext Token were added in V6.0.4. -The ABP Http interceptors check the value of the `IS_EXTERNAL_REQUEST` token. If the token is True then ABP-specific headers won't be added to Http Request. -The `ExternalHttpClient` extends from `HTTPClient` and sets the `IS_EXTERNAL_REQUEST` context token to true. -When you are using `ExternalHttpClient` as HttpClient in your components, it does not add ABP-specific headers. - -Note: With `IS_EXTERNAL_REQUEST` or without it, ABP loading service works. diff --git a/npm/ng-packs/packages/core/src/lib/tokens/index.ts b/npm/ng-packs/packages/core/src/lib/tokens/index.ts index 98985107f3..e0116e007a 100644 --- a/npm/ng-packs/packages/core/src/lib/tokens/index.ts +++ b/npm/ng-packs/packages/core/src/lib/tokens/index.ts @@ -7,3 +7,4 @@ export * from './manage-profile.token'; export * from './options.token'; export * from './queue.token'; export * from './tenant-key.token'; +export * from './http-context.token'; From 4d086f4ed39f751ba521bc7b6892de697501912c Mon Sep 17 00:00:00 2001 From: Idrees Haddad Date: Fri, 27 Jan 2023 08:15:16 +0300 Subject: [PATCH 07/11] Update Modal.md Fixed a typo isModelOpen should be isModalOpen --- docs/en/UI/Angular/Modal.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/UI/Angular/Modal.md b/docs/en/UI/Angular/Modal.md index 144f38e842..903e98f1fd 100644 --- a/docs/en/UI/Angular/Modal.md +++ b/docs/en/UI/Angular/Modal.md @@ -57,7 +57,7 @@ You can add the `abp-modal` to your component very quickly. See an example: @Component(/* component metadata */) export class SampleComponent { - isModelOpen = false + isModalOpen = false } ``` From ec742e9d24edfa04139babbffca3eb105212f6e6 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Mon, 30 Jan 2023 15:24:07 +0300 Subject: [PATCH 08/11] Cli: Fix wrong import when module added to angular project --- .../Abp/Cli/ProjectModification/AngularSourceCodeAdder.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/AngularSourceCodeAdder.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/AngularSourceCodeAdder.cs index c8d3aeb75b..74a45ba7e1 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/AngularSourceCodeAdder.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/AngularSourceCodeAdder.cs @@ -267,11 +267,11 @@ public class AngularSourceCodeAdder : ITransientDependency var fileContent = File.ReadAllText(filePath); - fileContent = "import { "+moduleName.Split(".").Last()+"Module } from '@"+moduleName.Split(".").Last().ToKebabCase()+"/config';" + Environment.NewLine + fileContent; + fileContent = "import { "+moduleName.Split(".").Last()+"ConfigModule } from '@"+moduleName.Split(".").Last().ToKebabCase()+"/config';" + Environment.NewLine + fileContent; fileContent = Regex.Replace(fileContent, "imports\\s*:\\s*\\[", "imports: ["+ Environment.NewLine + - " " + moduleName.Split(".").Last() + "Module.forRoot(),"); + " " + moduleName.Split(".").Last() + "ConfigModule.forRoot(),"); File.WriteAllText(filePath, fileContent); } From f3bce4b18b37704fad50e7c47bda9a47fcfe04ed Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 1 Feb 2023 21:13:17 +0800 Subject: [PATCH 09/11] Fix openiddict cache problem. --- .../OpenIddict/AbpOpenIddictDomainModule.cs | 3 ++ .../AbpOpenIddictIdentifierConverter.cs | 17 ++++++++ .../Abp/OpenIddict/AbpOpenIddictStoreBase.cs | 10 +++-- .../Applications/AbpApplicationManager.cs | 19 ++++++++- .../AbpOpenIddictApplicationCache.cs | 16 ++++---- .../AbpOpenIddictApplicationStore.cs | 5 ++- .../Authorizations/AbpAuthorizationManager.cs | 39 +++++++++++++++++++ .../AbpOpenIddictAuthorizationCache.cs | 16 ++++---- .../AbpOpenIddictAuthorizationStore.cs | 5 ++- .../Scopes/AbpOpenIddictScopeCache.cs | 8 ++-- .../Scopes/AbpOpenIddictScopeStore.cs | 5 ++- .../Abp/OpenIddict/Scopes/AbpScopeManager.cs | 39 +++++++++++++++++++ .../Tokens/AbpOpenIddictTokenStore.cs | 9 +++-- .../Abp/OpenIddict/Tokens/AbpTokenManager.cs | 39 +++++++++++++++++++ 14 files changed, 195 insertions(+), 35 deletions(-) create mode 100644 modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictIdentifierConverter.cs create mode 100644 modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpAuthorizationManager.cs create mode 100644 modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Scopes/AbpScopeManager.cs create mode 100644 modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/AbpTokenManager.cs diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictDomainModule.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictDomainModule.cs index 428f5a7062..c9ec33780e 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictDomainModule.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictDomainModule.cs @@ -71,6 +71,9 @@ public class AbpOpenIddictDomainModule : AbpModule .AddTokenStore(); builder.ReplaceApplicationManager(typeof(AbpApplicationManager)); + builder.ReplaceAuthorizationManager(typeof(AbpAuthorizationManager)); + builder.ReplaceScopeManager(typeof(AbpScopeManager)); + builder.ReplaceTokenManager(typeof(AbpTokenManager)); builder.Services.TryAddScoped(provider => (IAbpApplicationManager)provider.GetRequiredService()); diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictIdentifierConverter.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictIdentifierConverter.cs new file mode 100644 index 0000000000..3d55a89ad8 --- /dev/null +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictIdentifierConverter.cs @@ -0,0 +1,17 @@ +using System; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.OpenIddict; + +public class AbpOpenIddictIdentifierConverter : ITransientDependency +{ + public virtual Guid FromString(string identifier) + { + return string.IsNullOrEmpty(identifier) ? default : Guid.Parse(identifier); + } + + public virtual string ToString(Guid identifier) + { + return identifier.ToString("D"); + } +} diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictStoreBase.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictStoreBase.cs index 4c90c3a083..29254b8a00 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictStoreBase.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictStoreBase.cs @@ -20,26 +20,28 @@ public abstract class AbpOpenIddictStoreBase protected TRepository Repository { get; } protected IUnitOfWorkManager UnitOfWorkManager { get; } protected IGuidGenerator GuidGenerator { get; } + protected AbpOpenIddictIdentifierConverter IdentifierConverter { get; } - protected AbpOpenIddictStoreBase(TRepository repository, IUnitOfWorkManager unitOfWorkManager, IGuidGenerator guidGenerator) + protected AbpOpenIddictStoreBase(TRepository repository, IUnitOfWorkManager unitOfWorkManager, IGuidGenerator guidGenerator, AbpOpenIddictIdentifierConverter identifierConverter) { Repository = repository; UnitOfWorkManager = unitOfWorkManager; GuidGenerator = guidGenerator; + IdentifierConverter = identifierConverter; Logger = NullLogger>.Instance; } protected virtual Guid ConvertIdentifierFromString(string identifier) { - return string.IsNullOrEmpty(identifier) ? default : Guid.Parse(identifier); + return IdentifierConverter.FromString(identifier); } protected virtual string ConvertIdentifierToString(Guid identifier) { - return identifier.ToString("D"); + return IdentifierConverter.ToString(identifier); } - + protected virtual string WriteStream(Action action) { using (var stream = new MemoryStream()) diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/AbpApplicationManager.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/AbpApplicationManager.cs index b205f60be2..5b90574e59 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/AbpApplicationManager.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/AbpApplicationManager.cs @@ -11,14 +11,31 @@ namespace Volo.Abp.OpenIddict.Applications; public class AbpApplicationManager : OpenIddictApplicationManager, IAbpApplicationManager { + protected AbpOpenIddictIdentifierConverter IdentifierConverter { get; } + public AbpApplicationManager( [NotNull] IOpenIddictApplicationCache cache, [NotNull] ILogger logger, [NotNull] IOptionsMonitor options, - [NotNull] IOpenIddictApplicationStoreResolver resolver) + [NotNull] IOpenIddictApplicationStoreResolver resolver, + AbpOpenIddictIdentifierConverter identifierConverter) : base(cache, logger, options, resolver) { + IdentifierConverter = identifierConverter; + } + + public async override ValueTask UpdateAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken = default) + { + if (!Options.CurrentValue.DisableEntityCaching) + { + var entity = await Store.FindByIdAsync(IdentifierConverter.ToString(application.Id), cancellationToken); + if (entity != null) + { + await Cache.RemoveAsync(entity, cancellationToken); + } + } + await base.UpdateAsync(application, cancellationToken); } public async override ValueTask PopulateAsync(OpenIddictApplicationDescriptor descriptor, OpenIddictApplicationModel application, CancellationToken cancellationToken = default) diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/AbpOpenIddictApplicationCache.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/AbpOpenIddictApplicationCache.cs index 2a1e49f4f7..877109e26c 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/AbpOpenIddictApplicationCache.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/AbpOpenIddictApplicationCache.cs @@ -34,13 +34,13 @@ public class AbpOpenIddictApplicationCache : AbpOpenIddictCacheBase FindByClientIdAsync(string identifier, CancellationToken cancellationToken) + public virtual async ValueTask FindByClientIdAsync(string clientId, CancellationToken cancellationToken) { - Check.NotNullOrEmpty(identifier, nameof(identifier)); + Check.NotNullOrEmpty(clientId, nameof(clientId)); - return await Cache.GetOrAddAsync($"{nameof(FindByClientIdAsync)}_{identifier}", async () => + return await Cache.GetOrAddAsync($"{nameof(FindByClientIdAsync)}_{clientId}", async () => { - var application = await Store.FindByClientIdAsync(identifier, cancellationToken); + var application = await Store.FindByClientIdAsync(clientId, cancellationToken); if (application != null) { await AddAsync(application, cancellationToken); @@ -49,13 +49,13 @@ public class AbpOpenIddictApplicationCache : AbpOpenIddictCacheBase FindByIdAsync(string identifier, CancellationToken cancellationToken) + public virtual async ValueTask FindByIdAsync(string id, CancellationToken cancellationToken) { - Check.NotNullOrEmpty(identifier, nameof(identifier)); + Check.NotNullOrEmpty(id, nameof(id)); - return await Cache.GetOrAddAsync($"{nameof(FindByIdAsync)}_{identifier}", async () => + return await Cache.GetOrAddAsync($"{nameof(FindByIdAsync)}_{id}", async () => { - var application = await Store.FindByIdAsync(identifier, cancellationToken); + var application = await Store.FindByIdAsync(id, cancellationToken); if (application != null) { await AddAsync(application, cancellationToken); diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/AbpOpenIddictApplicationStore.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/AbpOpenIddictApplicationStore.cs index 1f740ecfcd..480b8b52ee 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/AbpOpenIddictApplicationStore.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/AbpOpenIddictApplicationStore.cs @@ -22,8 +22,9 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase +{ + protected AbpOpenIddictIdentifierConverter IdentifierConverter { get; } + + public AbpAuthorizationManager( + [NotNull] [ItemNotNull] IOpenIddictAuthorizationCache cache, + [NotNull] [ItemNotNull] ILogger> logger, + [NotNull] [ItemNotNull] IOptionsMonitor options, + [NotNull] IOpenIddictAuthorizationStoreResolver resolver, + AbpOpenIddictIdentifierConverter identifierConverter) + : base(cache, logger, options, resolver) + { + IdentifierConverter = identifierConverter; + } + + public async override ValueTask UpdateAsync(OpenIddictAuthorizationModel authorization, CancellationToken cancellationToken = default) + { + if (!Options.CurrentValue.DisableEntityCaching) + { + var entity = await Store.FindByIdAsync(IdentifierConverter.ToString(authorization.Id), cancellationToken); + if (entity != null) + { + await Cache.RemoveAsync(entity, cancellationToken); + } + } + + await base.UpdateAsync(authorization, cancellationToken); + } +} diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationCache.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationCache.cs index 9079a57acc..95c1a59526 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationCache.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationCache.cs @@ -114,14 +114,14 @@ public class AbpOpenIddictAuthorizationCache : AbpOpenIddictCacheBase FindByApplicationIdAsync(string identifier, [EnumeratorCancellation] CancellationToken cancellationToken) + public async IAsyncEnumerable FindByApplicationIdAsync(string applicationId, [EnumeratorCancellation] CancellationToken cancellationToken) { - Check.NotNullOrEmpty(identifier, nameof(identifier)); + Check.NotNullOrEmpty(applicationId, nameof(applicationId)); - var authorizations = await ArrayCache.GetOrAddAsync($"{nameof(FindByApplicationIdAsync)}_{identifier}", async () => + var authorizations = await ArrayCache.GetOrAddAsync($"{nameof(FindByApplicationIdAsync)}_{applicationId}", async () => { var applications = new List(); - await foreach (var authorization in Store.FindByApplicationIdAsync(identifier, cancellationToken)) + await foreach (var authorization in Store.FindByApplicationIdAsync(applicationId, cancellationToken)) { applications.Add(authorization); await AddAsync(authorization, cancellationToken); @@ -135,12 +135,12 @@ public class AbpOpenIddictAuthorizationCache : AbpOpenIddictCacheBase FindByIdAsync(string identifier, CancellationToken cancellationToken) + public async ValueTask FindByIdAsync(string id, CancellationToken cancellationToken) { - Check.NotNullOrEmpty(identifier, nameof(identifier)); + Check.NotNullOrEmpty(id, nameof(id)); - return await Cache.GetOrAddAsync($"{nameof(FindByIdAsync)}_{identifier}", - async () => await Store.FindByIdAsync(identifier, cancellationToken), token: cancellationToken); + return await Cache.GetOrAddAsync($"{nameof(FindByIdAsync)}_{id}", + async () => await Store.FindByIdAsync(id, cancellationToken), token: cancellationToken); } public async IAsyncEnumerable FindBySubjectAsync(string subject, [EnumeratorCancellation] CancellationToken cancellationToken) diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationStore.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationStore.cs index 6e6582e047..1637288125 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationStore.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationStore.cs @@ -25,8 +25,9 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase FindByIdAsync(string identifier, CancellationToken cancellationToken) + public virtual async ValueTask FindByIdAsync(string id, CancellationToken cancellationToken) { - Check.NotNullOrEmpty(identifier, nameof(identifier)); + Check.NotNullOrEmpty(id, nameof(id)); - return await Cache.GetOrAddAsync($"{nameof(FindByIdAsync)}_{identifier}", async () => + return await Cache.GetOrAddAsync($"{nameof(FindByIdAsync)}_{id}", async () => { - var scope = await Store.FindByIdAsync(identifier, cancellationToken); + var scope = await Store.FindByIdAsync(id, cancellationToken); if (scope != null) { await AddAsync(scope, cancellationToken); diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Scopes/AbpOpenIddictScopeStore.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Scopes/AbpOpenIddictScopeStore.cs index aedfe83c26..d10065e1dd 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Scopes/AbpOpenIddictScopeStore.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Scopes/AbpOpenIddictScopeStore.cs @@ -18,8 +18,9 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase +{ + protected AbpOpenIddictIdentifierConverter IdentifierConverter { get; } + + public AbpScopeManager( + [NotNull] [ItemNotNull] IOpenIddictScopeCache cache, + [NotNull] [ItemNotNull] ILogger> logger, + [NotNull] [ItemNotNull] IOptionsMonitor options, + [NotNull] IOpenIddictScopeStoreResolver resolver, + AbpOpenIddictIdentifierConverter identifierConverter) + : base(cache, logger, options, resolver) + { + IdentifierConverter = identifierConverter; + } + + public async override ValueTask UpdateAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken = default) + { + if (!Options.CurrentValue.DisableEntityCaching) + { + var entity = await Store.FindByIdAsync(IdentifierConverter.ToString(scope.Id), cancellationToken); + if (entity != null) + { + await Cache.RemoveAsync(entity, cancellationToken); + } + } + + await base.UpdateAsync(scope, cancellationToken); + } +} diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/AbpOpenIddictTokenStore.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/AbpOpenIddictTokenStore.cs index c8b80831a9..29b07d032d 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/AbpOpenIddictTokenStore.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/AbpOpenIddictTokenStore.cs @@ -25,8 +25,9 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase +{ + protected AbpOpenIddictIdentifierConverter IdentifierConverter { get; } + + public AbpTokenManager( + [NotNull] [ItemNotNull] IOpenIddictTokenCache cache, + [NotNull] [ItemNotNull] ILogger> logger, + [NotNull] [ItemNotNull] IOptionsMonitor options, + [NotNull] IOpenIddictTokenStoreResolver resolver, + AbpOpenIddictIdentifierConverter identifierConverter) + : base(cache, logger, options, resolver) + { + IdentifierConverter = identifierConverter; + } + + public async override ValueTask UpdateAsync(OpenIddictTokenModel token, CancellationToken cancellationToken = default) + { + if (!Options.CurrentValue.DisableEntityCaching) + { + var entity = await Store.FindByIdAsync(IdentifierConverter.ToString(token.Id), cancellationToken); + if (entity != null) + { + await Cache.RemoveAsync(entity, cancellationToken); + } + } + + await base.UpdateAsync(token, cancellationToken); + } +} From 3ac8e34df945fdc37d3a501bbeb57e6ac19bfaac Mon Sep 17 00:00:00 2001 From: muhammedaltug Date: Mon, 6 Feb 2023 16:28:47 +0300 Subject: [PATCH 10/11] wrap defaultValue with quotes when type is string --- npm/ng-packs/packages/schematics/src/models/model.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/npm/ng-packs/packages/schematics/src/models/model.ts b/npm/ng-packs/packages/schematics/src/models/model.ts index 048c08a1b0..142d4da75c 100644 --- a/npm/ng-packs/packages/schematics/src/models/model.ts +++ b/npm/ng-packs/packages/schematics/src/models/model.ts @@ -45,9 +45,13 @@ abstract class TypeRef { get default() { return this._default; } - set default(value: string) { + set default(value: any) { if (!value) return; - this._default = ` = ${value}`; + if (typeof value === 'string') { + this._default = ` = "${value}"`; + } else { + this._default = ` = ${value}`; + } } constructor(options: TypeRefOptions) { From d04d0c4d2f3f3a437c6a9d85efab590347014b03 Mon Sep 17 00:00:00 2001 From: Mahmut Gundogdu Date: Tue, 7 Feb 2023 09:55:54 +0300 Subject: [PATCH 11/11] Move Is_External logic to OAuth pack --- .../src/lib/interceptors/api.interceptor.ts | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/npm/ng-packs/packages/oauth/src/lib/interceptors/api.interceptor.ts b/npm/ng-packs/packages/oauth/src/lib/interceptors/api.interceptor.ts index e807133c0d..f36f966559 100644 --- a/npm/ng-packs/packages/oauth/src/lib/interceptors/api.interceptor.ts +++ b/npm/ng-packs/packages/oauth/src/lib/interceptors/api.interceptor.ts @@ -2,7 +2,13 @@ import { HttpHandler, HttpHeaders, HttpRequest } from '@angular/common/http'; import { Inject, Injectable } from '@angular/core'; import { OAuthService } from 'angular-oauth2-oidc'; import { finalize } from 'rxjs/operators'; -import { SessionStateService, HttpWaitService, TENANT_KEY, IApiInterceptor } from '@abp/ng.core'; +import { + SessionStateService, + HttpWaitService, + TENANT_KEY, + IApiInterceptor, + IS_EXTERNAL_REQUEST, +} from '@abp/ng.core'; @Injectable({ providedIn: 'root', @@ -17,12 +23,15 @@ export class OAuthApiInterceptor implements IApiInterceptor { intercept(request: HttpRequest, next: HttpHandler) { this.httpWaitService.addRequest(request); - return next - .handle( - request.clone({ + const isExternalRequest = request.context?.get(IS_EXTERNAL_REQUEST); + const newRequest = isExternalRequest + ? request + : request.clone({ setHeaders: this.getAdditionalHeaders(request.headers), - }), - ) + }); + + return next + .handle(newRequest) .pipe(finalize(() => this.httpWaitService.deleteRequest(request))); }