ngx-sp-auth 4.22.6 → 4.22.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/ngx-sp-auth.mjs +256 -196
- package/fesm2022/ngx-sp-auth.mjs.map +1 -1
- package/lib/auth.service.d.ts +2 -3
- package/lib/interceptors/auth-aplic.interceptor.d.ts +6 -8
- package/lib/interceptors/auth-infra.interceptor.d.ts +3 -5
- package/lib/services/pesquisa-telas-global.service.d.ts +4 -4
- package/lib/storage/auth-storage.service.d.ts +13 -2
- package/lib/utils/auth-utils.service.d.ts +5 -5
- package/package.json +1 -1
package/fesm2022/ngx-sp-auth.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { importProvidersFrom, NgModule, InjectionToken, Inject, Injectable, Component, EventEmitter, Output, Input, TemplateRef, ContentChild,
|
|
2
|
+
import { importProvidersFrom, NgModule, InjectionToken, Inject, Injectable, ViewContainerRef, ViewChild, Component, EventEmitter, Output, Input, TemplateRef, ContentChild, inject } from '@angular/core';
|
|
3
3
|
import * as i1 from '@angular/common/http';
|
|
4
|
-
import { HTTP_INTERCEPTORS,
|
|
4
|
+
import { HTTP_INTERCEPTORS, HttpHeaders, HttpClient, HttpParams, HttpResponse } from '@angular/common/http';
|
|
5
5
|
import * as i1$2 from '@azure/msal-angular';
|
|
6
6
|
import { MsalInterceptor, MsalGuard, MsalModule, MSAL_GUARD_CONFIG } from '@azure/msal-angular';
|
|
7
7
|
import { LogLevel, PublicClientApplication, InteractionType } from '@azure/msal-browser';
|
|
8
8
|
import { take as take$1, tap as tap$1, map, switchMap as switchMap$1 } from 'rxjs/operators';
|
|
9
9
|
import * as i1$1 from '@angular/router';
|
|
10
10
|
import { RouterLink, NavigationEnd, RouterOutlet } from '@angular/router';
|
|
11
|
-
import { BehaviorSubject, take, tap, Subject,
|
|
11
|
+
import { BehaviorSubject, firstValueFrom, take, tap, Subject, Subscription, debounceTime, distinctUntilChanged, filter, switchMap, timer, map as map$1, of, lastValueFrom, from, catchError, throwError } from 'rxjs';
|
|
12
12
|
import * as i3 from 'ngx-sp-infra';
|
|
13
13
|
import { Utils, SearchInputComponent, InfraModule, FormUtils, Usuario, RetPasswordPolicy, RetCheckPassword, CheckPasswordRecord, PasswordPolicyComponent, LibIconsComponent, ContentContainerComponent } from 'ngx-sp-infra';
|
|
14
14
|
import { openDB, deleteDB } from 'idb';
|
|
@@ -512,13 +512,85 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
512
512
|
}]
|
|
513
513
|
}], ctorParameters: () => [{ type: LibCustomEnvironmentService }] });
|
|
514
514
|
|
|
515
|
+
class LibCustomLoginService {
|
|
516
|
+
constructor(_customLoginService) {
|
|
517
|
+
this._customLoginService = _customLoginService;
|
|
518
|
+
}
|
|
519
|
+
// #region Propriedade Customizadas para o Componente login.component.ts
|
|
520
|
+
get loginTitle() {
|
|
521
|
+
return this._customLoginService.loginTitle;
|
|
522
|
+
}
|
|
523
|
+
get loginSubtitle() {
|
|
524
|
+
return this._customLoginService.loginSubtitle;
|
|
525
|
+
}
|
|
526
|
+
get loginBackground() {
|
|
527
|
+
return this._customLoginService.loginBackground;
|
|
528
|
+
}
|
|
529
|
+
get loginLogotipo() {
|
|
530
|
+
return this._customLoginService.loginLogotipo;
|
|
531
|
+
}
|
|
532
|
+
get loginAltLogotipo() {
|
|
533
|
+
return this._customLoginService.loginAltLogotipo;
|
|
534
|
+
}
|
|
535
|
+
get loginPageTitle() {
|
|
536
|
+
return this._customLoginService.loginPageTitle;
|
|
537
|
+
}
|
|
538
|
+
get loginDesenvDomain() {
|
|
539
|
+
return this._customLoginService.loginDesenvDomain;
|
|
540
|
+
}
|
|
541
|
+
get loginDesenvUser() {
|
|
542
|
+
return this._customLoginService.loginDesenvUser;
|
|
543
|
+
}
|
|
544
|
+
get loginDesenvPassword() {
|
|
545
|
+
return this._customLoginService.loginDesenvPassword;
|
|
546
|
+
}
|
|
547
|
+
// #endregion Propriedade Customizadas para o Componente login.component.ts
|
|
548
|
+
// #region Métodos Customizadas para o Componente auth.service.ts
|
|
549
|
+
/**
|
|
550
|
+
* Método executado no auth.service.ts - método: login ()
|
|
551
|
+
* Utilizado para inicializações diversas
|
|
552
|
+
*/
|
|
553
|
+
authLogin() {
|
|
554
|
+
this._customLoginService.authLogin();
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Método executado no auth.service.ts - método: logout ()
|
|
558
|
+
* Utilizado para inicializações diversas
|
|
559
|
+
*/
|
|
560
|
+
authLogout() {
|
|
561
|
+
this._customLoginService.authLogout();
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Método executado no auth.service.ts - método: login ()
|
|
565
|
+
* Utilizado para informar o redirecionamento para a tela inicial após o login ok
|
|
566
|
+
*
|
|
567
|
+
* @param router Objeto de Router que será utilizado
|
|
568
|
+
*/
|
|
569
|
+
authNavigateToPage(router) {
|
|
570
|
+
this._customLoginService.authNavigateToPage(router);
|
|
571
|
+
}
|
|
572
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: LibCustomLoginService, deps: [{ token: LIB_CUSTOM_LOGIN_SERVICE }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
573
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: LibCustomLoginService, providedIn: 'root' }); }
|
|
574
|
+
}
|
|
575
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: LibCustomLoginService, decorators: [{
|
|
576
|
+
type: Injectable,
|
|
577
|
+
args: [{ providedIn: 'root' }]
|
|
578
|
+
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
579
|
+
type: Inject,
|
|
580
|
+
args: [LIB_CUSTOM_LOGIN_SERVICE]
|
|
581
|
+
}] }] });
|
|
582
|
+
|
|
515
583
|
class AuthStorageService {
|
|
516
|
-
constructor(_httpBackend, _customStorageService, _indexedDBService, _customEnvironmentService) {
|
|
584
|
+
constructor(_httpBackend, _customStorageService, _indexedDBService, _customEnvironmentService, _customLoginService, _router) {
|
|
517
585
|
this._httpBackend = _httpBackend;
|
|
518
586
|
this._customStorageService = _customStorageService;
|
|
519
587
|
this._indexedDBService = _indexedDBService;
|
|
520
588
|
this._customEnvironmentService = _customEnvironmentService;
|
|
521
|
-
this.
|
|
589
|
+
this._customLoginService = _customLoginService;
|
|
590
|
+
this._router = _router;
|
|
591
|
+
this._BASE_URL = ''; // SpInfra2LoginWS
|
|
592
|
+
this._LOGOUT_BASE_URL = ''; // SpInfra2LoginWS
|
|
593
|
+
this._HTTP_HEADERS = new HttpHeaders().set('Content-Type', 'application/json');
|
|
522
594
|
this.__local_key = 'user_auth_v6';
|
|
523
595
|
// indica se objeto já está marcado para salvar os dados no local storage.
|
|
524
596
|
this.__isSaving = false;
|
|
@@ -565,8 +637,10 @@ class AuthStorageService {
|
|
|
565
637
|
// azureClientId
|
|
566
638
|
this.__azureClientId = "";
|
|
567
639
|
this._httpClient = new HttpClient(_httpBackend);
|
|
568
|
-
this._BASE_URL = `${_customEnvironmentService.SpInfra2LoginWS}/LoginSisproERP`; //
|
|
569
|
-
this._BASE_URL = !_customEnvironmentService.production ? this._BASE_URL : `${_customEnvironmentService.SpInfra2LoginWS}/LoginSisproERP`;
|
|
640
|
+
this._BASE_URL = `${_customEnvironmentService.SpInfra2LoginWS}/LoginSisproERP`; // SpInfra2LoginWS
|
|
641
|
+
this._BASE_URL = !_customEnvironmentService.production ? this._BASE_URL : `${_customEnvironmentService.SpInfra2LoginWS}/LoginSisproERP`; // SpInfra2LoginWS
|
|
642
|
+
this._LOGOUT_BASE_URL = `${_customEnvironmentService.SpInfra2LoginWS}/LogoutSisproErp`; // SpInfra2LoginWS
|
|
643
|
+
this._BASE_URL = !_customEnvironmentService.production ? this._BASE_URL : `${_customEnvironmentService.SpInfra2LoginWS}/LogoutSisproErp`; // SpInfra2LoginWS
|
|
570
644
|
// Método com customizações para inicializações da storage
|
|
571
645
|
this._customStorageService.storageConstructor();
|
|
572
646
|
const expectedLocalAuthStorage = localStorage.getItem(this.__local_key);
|
|
@@ -839,36 +913,33 @@ class AuthStorageService {
|
|
|
839
913
|
// Chama a si próprio depois de um tempo igual ao tempo restante para o vencimento do token, para renovar o token ou deslogar o usuário.
|
|
840
914
|
setTimeout(this.reCheckLogin.bind(this, true), leftTime * 1000);
|
|
841
915
|
}
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
this.
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
.catch((err) => console.warn('logout() => falha ao limpar conexão', err));
|
|
870
|
-
// Método com customizações para finalizações da storage
|
|
871
|
-
this._customStorageService.storageLogout();
|
|
916
|
+
/**
|
|
917
|
+
* Realiza o logout do sistema, consumindo o endpoint de logout para remover os cookies e limpando as informações de autenticação armazenadas no localStorage.
|
|
918
|
+
* @returns Promise<boolean> indicando navegação para a tela de login após o logout.
|
|
919
|
+
*/
|
|
920
|
+
async logout() {
|
|
921
|
+
// Consumo de endpoint de logout
|
|
922
|
+
const url = `${this._LOGOUT_BASE_URL}`;
|
|
923
|
+
console.log('1. URL:', url);
|
|
924
|
+
await firstValueFrom(this._httpClient.post(url, null, { 'headers': this._HTTP_HEADERS, withCredentials: true })).then((res) => {
|
|
925
|
+
console.log('2. res:', res);
|
|
926
|
+
})
|
|
927
|
+
.catch((err) => {
|
|
928
|
+
console.log('2.1. teste se aparece aqui no erro do endpoint de logout:', err);
|
|
929
|
+
})
|
|
930
|
+
.then(() => {
|
|
931
|
+
// Independente de sucesso ou erro, realiza a limpeza do localStorage após o endpoint ser chamado
|
|
932
|
+
console.log('3. Removendo variáveis de configuração do usuário e senha do localStorage');
|
|
933
|
+
localStorage.removeItem('configServerUser');
|
|
934
|
+
localStorage.removeItem('configServerPassword');
|
|
935
|
+
console.log('4. Chamando método onLogout() para limpar variáveis de autenticação e redirecionar para a tela de login');
|
|
936
|
+
this.onLogout();
|
|
937
|
+
// Método com customizações para inicializações do Logout
|
|
938
|
+
console.log('5. Chamando método authLogout() do serviço de customização para realizar ações de logout específicas');
|
|
939
|
+
this._customLoginService.authLogout();
|
|
940
|
+
});
|
|
941
|
+
console.log('6. Navegando para rota de login');
|
|
942
|
+
return this._router.navigate(["/auth/login"]);
|
|
872
943
|
}
|
|
873
944
|
getNewTokenBack() {
|
|
874
945
|
let token = {
|
|
@@ -881,15 +952,14 @@ class AuthStorageService {
|
|
|
881
952
|
};
|
|
882
953
|
const url = `${this._BASE_URL}/GetNewToken`;
|
|
883
954
|
const headers = new HttpHeaders()
|
|
884
|
-
.set('Content-Type', 'application/json')
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
}
|
|
892
|
-
}));
|
|
955
|
+
.set('Content-Type', 'application/json');
|
|
956
|
+
// Remover/comentar o header abaixo pois o token será enviado via Cookie HttpOnly, e não mais via header Authorization
|
|
957
|
+
// .set('Authorization',
|
|
958
|
+
// `Basic ${btoa(`${localStorage.getItem('configServerUser')}:${localStorage.getItem('configServerPassword')}`)}`
|
|
959
|
+
// );
|
|
960
|
+
return this._httpClient.post(url, token, { 'headers': headers, withCredentials: true })
|
|
961
|
+
.pipe(take(1), tap((response) => { if (response.Error)
|
|
962
|
+
throw Error(response.ErrorMessage); }));
|
|
893
963
|
}
|
|
894
964
|
getNewToken() {
|
|
895
965
|
return new Promise((resolve, reject) => {
|
|
@@ -926,6 +996,39 @@ class AuthStorageService {
|
|
|
926
996
|
}
|
|
927
997
|
}
|
|
928
998
|
}
|
|
999
|
+
onLogout() {
|
|
1000
|
+
console.log('4.1. Iniciando onLogout() para limpar variáveis de autenticação e redirecionar para a tela de login');
|
|
1001
|
+
this.__isCheckingAuth = false;
|
|
1002
|
+
this.isLoggedInSub.next(false);
|
|
1003
|
+
this.__UrlRedirect = "/";
|
|
1004
|
+
this.__ip = "";
|
|
1005
|
+
this.__tenantId = 0;
|
|
1006
|
+
this.__infraUsuarioId = "";
|
|
1007
|
+
this.__infraEstabId = "";
|
|
1008
|
+
this.__infraEstabNome = "";
|
|
1009
|
+
this.__infraEmpresaId = "";
|
|
1010
|
+
this.__infraEmpresaNome = "";
|
|
1011
|
+
this.__user = "";
|
|
1012
|
+
this.__userName = "";
|
|
1013
|
+
this.__authToken = "";
|
|
1014
|
+
this.__dominio = "";
|
|
1015
|
+
this.__tokenPayload = {};
|
|
1016
|
+
this.__isExternalLogin = false;
|
|
1017
|
+
this.__infraInAuthTypeId = 0;
|
|
1018
|
+
this.__infraIn2FaTypeId = null;
|
|
1019
|
+
this.__is2FaEnabled = false;
|
|
1020
|
+
this.__azureTenantId = "";
|
|
1021
|
+
this.__azureClientId = "";
|
|
1022
|
+
console.log('4.2. __localKey:', this.__local_key);
|
|
1023
|
+
localStorage.removeItem(this.__local_key);
|
|
1024
|
+
// Limpa o armazenamento local do navegador que contém os filtros de um produto específico
|
|
1025
|
+
// Fecha a conexão local (se houver) antes de excluir a database para evitar o callback 'blocking'
|
|
1026
|
+
this._indexedDBService.closeOpenConnection()
|
|
1027
|
+
.then(() => this._indexedDBService.deleteDatabase())
|
|
1028
|
+
.catch((err) => console.warn('logout() => falha ao limpar conexão', err));
|
|
1029
|
+
// Método com customizações para finalizações da storage
|
|
1030
|
+
this._customStorageService.storageLogout();
|
|
1031
|
+
}
|
|
929
1032
|
isPrePortal() {
|
|
930
1033
|
// Identifica se a origem é PrePortal
|
|
931
1034
|
var url = new URL(window.location.href);
|
|
@@ -942,114 +1045,46 @@ class AuthStorageService {
|
|
|
942
1045
|
return false;
|
|
943
1046
|
}
|
|
944
1047
|
}
|
|
945
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthStorageService, deps: [{ token: i1.HttpBackend }, { token: LibCustomStorageService }, { token: IndexedDBService }, { token: LibCustomEnvironmentService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1048
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthStorageService, deps: [{ token: i1.HttpBackend }, { token: LibCustomStorageService }, { token: IndexedDBService }, { token: LibCustomEnvironmentService }, { token: LibCustomLoginService }, { token: i1$1.Router }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
946
1049
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthStorageService, providedIn: 'root' }); }
|
|
947
1050
|
}
|
|
948
1051
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthStorageService, decorators: [{
|
|
949
1052
|
type: Injectable,
|
|
950
1053
|
args: [{ providedIn: 'root' }]
|
|
951
|
-
}], ctorParameters: () => [{ type: i1.HttpBackend }, { type: LibCustomStorageService }, { type: IndexedDBService }, { type: LibCustomEnvironmentService }] });
|
|
952
|
-
|
|
953
|
-
class LibCustomLoginService {
|
|
954
|
-
constructor(_customLoginService) {
|
|
955
|
-
this._customLoginService = _customLoginService;
|
|
956
|
-
}
|
|
957
|
-
// #region Propriedade Customizadas para o Componente login.component.ts
|
|
958
|
-
get loginTitle() {
|
|
959
|
-
return this._customLoginService.loginTitle;
|
|
960
|
-
}
|
|
961
|
-
get loginSubtitle() {
|
|
962
|
-
return this._customLoginService.loginSubtitle;
|
|
963
|
-
}
|
|
964
|
-
get loginBackground() {
|
|
965
|
-
return this._customLoginService.loginBackground;
|
|
966
|
-
}
|
|
967
|
-
get loginLogotipo() {
|
|
968
|
-
return this._customLoginService.loginLogotipo;
|
|
969
|
-
}
|
|
970
|
-
get loginAltLogotipo() {
|
|
971
|
-
return this._customLoginService.loginAltLogotipo;
|
|
972
|
-
}
|
|
973
|
-
get loginPageTitle() {
|
|
974
|
-
return this._customLoginService.loginPageTitle;
|
|
975
|
-
}
|
|
976
|
-
get loginDesenvDomain() {
|
|
977
|
-
return this._customLoginService.loginDesenvDomain;
|
|
978
|
-
}
|
|
979
|
-
get loginDesenvUser() {
|
|
980
|
-
return this._customLoginService.loginDesenvUser;
|
|
981
|
-
}
|
|
982
|
-
get loginDesenvPassword() {
|
|
983
|
-
return this._customLoginService.loginDesenvPassword;
|
|
984
|
-
}
|
|
985
|
-
// #endregion Propriedade Customizadas para o Componente login.component.ts
|
|
986
|
-
// #region Métodos Customizadas para o Componente auth.service.ts
|
|
987
|
-
/**
|
|
988
|
-
* Método executado no auth.service.ts - método: login ()
|
|
989
|
-
* Utilizado para inicializações diversas
|
|
990
|
-
*/
|
|
991
|
-
authLogin() {
|
|
992
|
-
this._customLoginService.authLogin();
|
|
993
|
-
}
|
|
994
|
-
/**
|
|
995
|
-
* Método executado no auth.service.ts - método: logout ()
|
|
996
|
-
* Utilizado para inicializações diversas
|
|
997
|
-
*/
|
|
998
|
-
authLogout() {
|
|
999
|
-
this._customLoginService.authLogout();
|
|
1000
|
-
}
|
|
1001
|
-
/**
|
|
1002
|
-
* Método executado no auth.service.ts - método: login ()
|
|
1003
|
-
* Utilizado para informar o redirecionamento para a tela inicial após o login ok
|
|
1004
|
-
*
|
|
1005
|
-
* @param router Objeto de Router que será utilizado
|
|
1006
|
-
*/
|
|
1007
|
-
authNavigateToPage(router) {
|
|
1008
|
-
this._customLoginService.authNavigateToPage(router);
|
|
1009
|
-
}
|
|
1010
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: LibCustomLoginService, deps: [{ token: LIB_CUSTOM_LOGIN_SERVICE }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1011
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: LibCustomLoginService, providedIn: 'root' }); }
|
|
1012
|
-
}
|
|
1013
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: LibCustomLoginService, decorators: [{
|
|
1014
|
-
type: Injectable,
|
|
1015
|
-
args: [{ providedIn: 'root' }]
|
|
1016
|
-
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
1017
|
-
type: Inject,
|
|
1018
|
-
args: [LIB_CUSTOM_LOGIN_SERVICE]
|
|
1019
|
-
}] }] });
|
|
1054
|
+
}], ctorParameters: () => [{ type: i1.HttpBackend }, { type: LibCustomStorageService }, { type: IndexedDBService }, { type: LibCustomEnvironmentService }, { type: LibCustomLoginService }, { type: i1$1.Router }] });
|
|
1020
1055
|
|
|
1021
1056
|
class AuthUtilService {
|
|
1022
|
-
constructor(
|
|
1023
|
-
this.
|
|
1024
|
-
this.
|
|
1025
|
-
this.checkUrlAndMethodService = checkUrlAndMethodService;
|
|
1026
|
-
this.messageService = messageService;
|
|
1057
|
+
constructor(_authStorageService, _checkUrlAndMethodService, _customEnvironmentService, _message, _router) {
|
|
1058
|
+
this._authStorageService = _authStorageService;
|
|
1059
|
+
this._checkUrlAndMethodService = _checkUrlAndMethodService;
|
|
1027
1060
|
this._customEnvironmentService = _customEnvironmentService;
|
|
1061
|
+
this._message = _message;
|
|
1062
|
+
this._router = _router;
|
|
1028
1063
|
}
|
|
1029
1064
|
// Exibe a mensagem de erro de uma requisição http
|
|
1030
1065
|
showHttpError(error) {
|
|
1031
1066
|
if (error.error instanceof ErrorEvent) {
|
|
1032
1067
|
// Erro ocorreu no lado do cliente
|
|
1033
|
-
this.
|
|
1068
|
+
this._message.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1034
1069
|
}
|
|
1035
1070
|
else {
|
|
1036
1071
|
// Erro ocorreu no lado do servidor
|
|
1037
1072
|
let isUnauthorizedAccess = error.status === 401;
|
|
1038
1073
|
if (isUnauthorizedAccess) {
|
|
1039
|
-
let isFromAplic = this.
|
|
1074
|
+
let isFromAplic = this._checkUrlAndMethodService.needsAuthRequest(error.url, "*", this._customEnvironmentService.needsAuthAplic);
|
|
1040
1075
|
if (isFromAplic) {
|
|
1076
|
+
// Comentado pois neste projeto esta alteração de valores não realizava o logout como deveria corretamente...
|
|
1077
|
+
// this.authStorageService.isLoggedInSub.next(false);
|
|
1078
|
+
// this.authStorageService.urlRedirect = "/";
|
|
1041
1079
|
// Remove a autenticação do usuário.
|
|
1042
|
-
this.
|
|
1043
|
-
this.authStorageService.urlRedirect = "/";
|
|
1044
|
-
let promise = this.router.navigate(["/auth/login"]);
|
|
1045
|
-
promise.then(this.showExpiredAccess.bind(this));
|
|
1080
|
+
this._authStorageService.logout().then(this.showExpiredAccess.bind(this));
|
|
1046
1081
|
}
|
|
1047
1082
|
else {
|
|
1048
|
-
this.
|
|
1083
|
+
this._message.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1049
1084
|
}
|
|
1050
1085
|
}
|
|
1051
1086
|
else {
|
|
1052
|
-
this.
|
|
1087
|
+
this._message.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1053
1088
|
}
|
|
1054
1089
|
}
|
|
1055
1090
|
}
|
|
@@ -1057,32 +1092,33 @@ class AuthUtilService {
|
|
|
1057
1092
|
showHTTPErrorOS(error) {
|
|
1058
1093
|
if (error.error instanceof ErrorEvent) {
|
|
1059
1094
|
// Erro ocorreu no lado do cliente
|
|
1060
|
-
this.
|
|
1061
|
-
this.
|
|
1095
|
+
this._router.navigate(["/auth/login"]).then(e => {
|
|
1096
|
+
this._message.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1062
1097
|
});
|
|
1063
1098
|
}
|
|
1064
1099
|
else {
|
|
1065
1100
|
// Erro ocorreu no lado do servidor
|
|
1066
1101
|
let isUnauthorizedAccess = error.status === 401;
|
|
1067
1102
|
if (isUnauthorizedAccess) {
|
|
1068
|
-
let isFromAplic = this.
|
|
1103
|
+
let isFromAplic = this._checkUrlAndMethodService.needsAuthRequest(error.url, "*", this._customEnvironmentService.needsAuthAplic);
|
|
1069
1104
|
if (isFromAplic) {
|
|
1105
|
+
// Comentado pois neste projeto esta alteração de valores não realizava o logout como deveria corretamente...
|
|
1106
|
+
// this.authStorageService.isLoggedInSub.next(false);
|
|
1107
|
+
// this.authStorageService.urlRedirect = "/";
|
|
1070
1108
|
// Remove a autenticação do usuário.
|
|
1071
|
-
this.
|
|
1072
|
-
|
|
1073
|
-
this.router.navigate(["/auth/login"]).then(e => {
|
|
1074
|
-
this.messageService.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1109
|
+
this._authStorageService.logout().then(() => {
|
|
1110
|
+
this._message.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1075
1111
|
});
|
|
1076
1112
|
}
|
|
1077
1113
|
else {
|
|
1078
|
-
this.
|
|
1079
|
-
this.
|
|
1114
|
+
this._router.navigate(["/auth/login"]).then(e => {
|
|
1115
|
+
this._message.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1080
1116
|
});
|
|
1081
1117
|
}
|
|
1082
1118
|
}
|
|
1083
1119
|
else {
|
|
1084
|
-
this.
|
|
1085
|
-
this.
|
|
1120
|
+
this._router.navigate(["/auth/login"]).then(e => {
|
|
1121
|
+
this._message.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1086
1122
|
});
|
|
1087
1123
|
}
|
|
1088
1124
|
}
|
|
@@ -1090,14 +1126,14 @@ class AuthUtilService {
|
|
|
1090
1126
|
// Mostra uma mensagem de sessão expirada.
|
|
1091
1127
|
showExpiredAccess(navigationResult) {
|
|
1092
1128
|
if (navigationResult) {
|
|
1093
|
-
this.
|
|
1129
|
+
this._message.showAlertWarning("Sessão expirada, logue-se novamente.");
|
|
1094
1130
|
}
|
|
1095
1131
|
}
|
|
1096
1132
|
// Obtém o hostName
|
|
1097
1133
|
getHostName() {
|
|
1098
1134
|
return this._customEnvironmentService.hostName;
|
|
1099
1135
|
}
|
|
1100
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthUtilService, deps: [{ token:
|
|
1136
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthUtilService, deps: [{ token: AuthStorageService }, { token: i3.CheckUrlAndMethodService }, { token: LibCustomEnvironmentService }, { token: i3.MessageService }, { token: i1$1.Router }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1101
1137
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthUtilService, providedIn: 'root' }); }
|
|
1102
1138
|
}
|
|
1103
1139
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthUtilService, decorators: [{
|
|
@@ -1105,7 +1141,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
1105
1141
|
args: [{
|
|
1106
1142
|
providedIn: 'root'
|
|
1107
1143
|
}]
|
|
1108
|
-
}], ctorParameters: () => [{ type:
|
|
1144
|
+
}], ctorParameters: () => [{ type: AuthStorageService }, { type: i3.CheckUrlAndMethodService }, { type: LibCustomEnvironmentService }, { type: i3.MessageService }, { type: i1$1.Router }] });
|
|
1109
1145
|
|
|
1110
1146
|
class AuthService {
|
|
1111
1147
|
// #endregion PRIVATE
|
|
@@ -1122,20 +1158,23 @@ class AuthService {
|
|
|
1122
1158
|
// #region ==========> PROPERTIES <==========
|
|
1123
1159
|
// #region PRIVATE
|
|
1124
1160
|
this._pendingWarning = null;
|
|
1125
|
-
this._BASE_URL = ''; // SpInfra2WS
|
|
1126
1161
|
this._AUTH_BASE_URL = ''; // SpInfra2AuthWS
|
|
1162
|
+
this._BASE_URL = ''; // SpInfra2WS
|
|
1127
1163
|
this._BASE_OS_URL = ''; // SpInfra2LoginWS
|
|
1164
|
+
this._LOGOUT_BASE_URL = ''; // SpInfra2LoginWS
|
|
1128
1165
|
this._HTTP_HEADERS = new HttpHeaders().set('Content-Type', 'application/json');
|
|
1129
1166
|
this.ip = "undefined";
|
|
1130
1167
|
this.city = "undefined";
|
|
1131
1168
|
this.state = "undefined";
|
|
1132
1169
|
this.country = "undefined";
|
|
1133
|
-
this._BASE_URL = `${this._customEnvironmentService.SpInfra2LoginWS}/LoginSisproERP`; // SpInfra2WS
|
|
1134
1170
|
this._AUTH_BASE_URL = `${this._customEnvironmentService.SpInfra2AuthWS}/Auth`; // SpInfra2AuthWS
|
|
1171
|
+
this._BASE_URL = `${this._customEnvironmentService.SpInfra2LoginWS}/LoginSisproERP`; // SpInfra2LoginWS
|
|
1135
1172
|
this._BASE_OS_URL = `${this._customEnvironmentService.SpInfra2LoginWS}/LoginIntegradoOS`; // SpInfra2LoginWS
|
|
1136
|
-
this.
|
|
1173
|
+
this._LOGOUT_BASE_URL = `${this._customEnvironmentService.SpInfra2LoginWS}/LogoutSisproErp`; // SpInfra2LoginWS
|
|
1137
1174
|
this._AUTH_BASE_URL = !this._customEnvironmentService.production ? this._AUTH_BASE_URL : `${this._customEnvironmentService.SpInfra2AuthWS}/Auth`;
|
|
1175
|
+
this._BASE_URL = !this._customEnvironmentService.production ? this._BASE_URL : `${this._customEnvironmentService.SpInfra2LoginWS}/LoginSisproERP`;
|
|
1138
1176
|
this._BASE_OS_URL = !this._customEnvironmentService.production ? this._BASE_OS_URL : `${this._customEnvironmentService.SpInfra2LoginWS}/LoginIntegradoOS`;
|
|
1177
|
+
this._LOGOUT_BASE_URL = !this._customEnvironmentService.production ? this._LOGOUT_BASE_URL : `${this._customEnvironmentService.SpInfra2LoginWS}/LogoutSisproErp`;
|
|
1139
1178
|
this.getParms();
|
|
1140
1179
|
}
|
|
1141
1180
|
// #region ==========> SERVICE METHODS <==========
|
|
@@ -1193,6 +1232,8 @@ class AuthService {
|
|
|
1193
1232
|
if (response.Error) {
|
|
1194
1233
|
throw Error(response.ErrorMessage);
|
|
1195
1234
|
}
|
|
1235
|
+
// Comentadas pois não serão mais armazenadas desta forma, o webservice gerará um Cookie com o valor já formatado para Base64
|
|
1236
|
+
// E o mesmo será enviada nas requisições subsequentes via párâmetro `withCredentials: true`, e não mais via header Authorization
|
|
1196
1237
|
localStorage.setItem('configServerUser', response.User);
|
|
1197
1238
|
localStorage.setItem('configServerPassword', response.Password);
|
|
1198
1239
|
this._authStorageService.tenantId = response.TenantId;
|
|
@@ -1438,15 +1479,6 @@ class AuthService {
|
|
|
1438
1479
|
}
|
|
1439
1480
|
}));
|
|
1440
1481
|
}
|
|
1441
|
-
/** Realiza o logout do sistema, removendo tokens do localStorage e limpando cache */
|
|
1442
|
-
logout() {
|
|
1443
|
-
this._authStorageService.logout();
|
|
1444
|
-
localStorage.removeItem('configsServerUser');
|
|
1445
|
-
localStorage.removeItem('configsServerPassword');
|
|
1446
|
-
// Método com customizações para inicializações do Logout
|
|
1447
|
-
this._customLoginService.authLogout();
|
|
1448
|
-
this._router.navigate(["/auth/login"]);
|
|
1449
|
-
}
|
|
1450
1482
|
validateAuthentication2Fa(code) {
|
|
1451
1483
|
let Code2Fa = {
|
|
1452
1484
|
infraUsuarioId: this._authStorageService.infraUsuarioId,
|
|
@@ -1564,6 +1596,7 @@ class AuthService {
|
|
|
1564
1596
|
}
|
|
1565
1597
|
}));
|
|
1566
1598
|
}
|
|
1599
|
+
// TODO: Criar método de logout aqui que usa os métodos de limpeza de storage do `auth-storage.service.ts`...
|
|
1567
1600
|
// #endregion POST
|
|
1568
1601
|
// #endregion ==========> SERVICE METHODS <==========
|
|
1569
1602
|
// #region ==========> UTILS <==========
|
|
@@ -1994,16 +2027,12 @@ class PesquisaTelasGlobalService {
|
|
|
1994
2027
|
// #region PUBLIC
|
|
1995
2028
|
// #endregion PUBLIC
|
|
1996
2029
|
// #endregion ==========> PROPERTIES <==========
|
|
1997
|
-
constructor(
|
|
1998
|
-
this._componentFactoryResolver = _componentFactoryResolver;
|
|
2030
|
+
constructor(_appRef, _injector, _httpClient, _customEnvironmentService, _authUtils) {
|
|
1999
2031
|
this._appRef = _appRef;
|
|
2000
2032
|
this._injector = _injector;
|
|
2001
2033
|
this._httpClient = _httpClient;
|
|
2002
2034
|
this._customEnvironmentService = _customEnvironmentService;
|
|
2003
2035
|
this._authUtils = _authUtils;
|
|
2004
|
-
// #region ==========> PROPERTIES <==========
|
|
2005
|
-
// #region PRIVATE
|
|
2006
|
-
// #region GERENCIAMENTO DINÂMICO DO COMPONENTE
|
|
2007
2036
|
/**
|
|
2008
2037
|
* Referência ao componente dinâmico criado.
|
|
2009
2038
|
* Usado para gerenciar o ciclo de vida e estado do componente.
|
|
@@ -2125,7 +2154,7 @@ class PesquisaTelasGlobalService {
|
|
|
2125
2154
|
*
|
|
2126
2155
|
* Este método utiliza a API baixo nível do Angular para criar um componente dinamicamente e anexá-lo ao DOM. O processo envolve:
|
|
2127
2156
|
*
|
|
2128
|
-
* 1. Criar o componente via
|
|
2157
|
+
* 1. Criar o componente via `container.createComponent()`
|
|
2129
2158
|
* 2. Configurar suas propriedades iniciais
|
|
2130
2159
|
* 3. Registrá-lo no mecanismo de detecção de mudanças do Angular
|
|
2131
2160
|
* 4. Anexá-lo ao DOM (fora da hierarquia normal de componentes)
|
|
@@ -2141,24 +2170,18 @@ class PesquisaTelasGlobalService {
|
|
|
2141
2170
|
if (this._componentRef) {
|
|
2142
2171
|
return;
|
|
2143
2172
|
}
|
|
2144
|
-
// 1.
|
|
2145
|
-
|
|
2146
|
-
//
|
|
2147
|
-
const componentFactory = this._componentFactoryResolver.resolveComponentFactory(SearchInputComponent);
|
|
2148
|
-
// 2. Cria uma nova instância do componente usando o injector raiz
|
|
2149
|
-
// Isso garante que o componente tenha acesso aos mesmos serviços
|
|
2150
|
-
// que componentes criados normalmente via template
|
|
2151
|
-
this._componentRef = componentFactory.create(this._injector);
|
|
2152
|
-
// 3. Registra a view do componente no ApplicationRef
|
|
2173
|
+
// 1. Cria uma nova instância do componente
|
|
2174
|
+
this._componentRef = this._container.createComponent(SearchInputComponent);
|
|
2175
|
+
// 2. Registra a view do componente no ApplicationRef
|
|
2153
2176
|
// Isso é CRÍTICO: sem este passo, o componente não participaria
|
|
2154
2177
|
// do ciclo de detecção de mudanças do Angular
|
|
2155
2178
|
this._appRef.attachView(this._componentRef.hostView);
|
|
2156
|
-
//
|
|
2179
|
+
// 3. Obtém o elemento DOM raiz do componente e o anexa ao body
|
|
2157
2180
|
// Como este componente é criado fora da hierarquia normal,
|
|
2158
2181
|
// precisamos anexá-lo manualmente ao DOM
|
|
2159
2182
|
const domElem = this._componentRef.hostView.rootNodes[0];
|
|
2160
2183
|
document.body.appendChild(domElem);
|
|
2161
|
-
//
|
|
2184
|
+
// 4. Configura os listeners dos eventos do componente
|
|
2162
2185
|
// Em vez de tratar o hide() diretamente aqui, encaminhamos o evento para o Subject _onClose$ e guardamos a subscription para poder removê-la quando escondermos o componente.
|
|
2163
2186
|
this._componentCloseSub = this._componentRef.instance.onClose.subscribe(() => this._onClose$.next());
|
|
2164
2187
|
// Em vez de tratar o getTelas() diretamente aqui, encaminhamos o evento para o Subject _onSearch$ e guardamos a subscription para poder removê-la quando escondermos o componente.
|
|
@@ -2202,13 +2225,16 @@ class PesquisaTelasGlobalService {
|
|
|
2202
2225
|
// #endregion GERENCIAMENTO DO COMPONENTE
|
|
2203
2226
|
showErrorMessage(response) { if (response.Error)
|
|
2204
2227
|
throw Error(response.ErrorMessage); }
|
|
2205
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: PesquisaTelasGlobalService, deps: [{ token: i0.
|
|
2228
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: PesquisaTelasGlobalService, deps: [{ token: i0.ApplicationRef }, { token: i0.Injector }, { token: i1.HttpClient }, { token: LibCustomEnvironmentService }, { token: AuthUtilService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2206
2229
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: PesquisaTelasGlobalService, providedIn: 'root' }); }
|
|
2207
2230
|
}
|
|
2208
2231
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: PesquisaTelasGlobalService, decorators: [{
|
|
2209
2232
|
type: Injectable,
|
|
2210
2233
|
args: [{ providedIn: 'root' }]
|
|
2211
|
-
}], ctorParameters: () => [{ type: i0.
|
|
2234
|
+
}], ctorParameters: () => [{ type: i0.ApplicationRef }, { type: i0.Injector }, { type: i1.HttpClient }, { type: LibCustomEnvironmentService }, { type: AuthUtilService }], propDecorators: { _container: [{
|
|
2235
|
+
type: ViewChild,
|
|
2236
|
+
args: ['container', { read: ViewContainerRef, static: true }]
|
|
2237
|
+
}] } });
|
|
2212
2238
|
|
|
2213
2239
|
class ErrorMenuNotAllowed {
|
|
2214
2240
|
constructor(router, authStorageService) {
|
|
@@ -3683,7 +3709,7 @@ class MenuLateralComponent {
|
|
|
3683
3709
|
postLogoutRedirectUri: hostAuthLogin
|
|
3684
3710
|
});
|
|
3685
3711
|
}
|
|
3686
|
-
this.
|
|
3712
|
+
this._authStorageService.logout();
|
|
3687
3713
|
}
|
|
3688
3714
|
getExternalUrl(url, isOutroModulo) {
|
|
3689
3715
|
if (url.includes('https://'))
|
|
@@ -4682,15 +4708,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
4682
4708
|
;
|
|
4683
4709
|
|
|
4684
4710
|
/**
|
|
4685
|
-
*
|
|
4686
|
-
* com o login para uso da API.
|
|
4687
|
-
*
|
|
4711
|
+
* Intercepta uma chamada HTTP para inserir o usuário logado nos cookies (e header, para compatibilidade) em conjunto com o login para uso da API.
|
|
4688
4712
|
* Depende do serviço de autenticação.
|
|
4689
|
-
|
|
4713
|
+
*/
|
|
4690
4714
|
class AuthAplicInterceptor {
|
|
4691
|
-
constructor(
|
|
4692
|
-
this.
|
|
4693
|
-
this.
|
|
4715
|
+
constructor(_authCheckService, _authStorage, _customEnvironmentService) {
|
|
4716
|
+
this._authCheckService = _authCheckService;
|
|
4717
|
+
this._authStorage = _authStorage;
|
|
4694
4718
|
this._customEnvironmentService = _customEnvironmentService;
|
|
4695
4719
|
}
|
|
4696
4720
|
intercept(req, next) {
|
|
@@ -4699,14 +4723,31 @@ class AuthAplicInterceptor {
|
|
|
4699
4723
|
}
|
|
4700
4724
|
async handle(req, next) {
|
|
4701
4725
|
let changedReq = req;
|
|
4702
|
-
if (this.
|
|
4726
|
+
if (this._authCheckService.needsAuthRequest(req.url, req.method, this._customEnvironmentService.needsAuthAplic)) {
|
|
4703
4727
|
// Verifica se o Token precisa ser renovado
|
|
4704
|
-
await this.
|
|
4728
|
+
await this._authStorage.renewToken();
|
|
4705
4729
|
// Adiciona as autenticações necessárias ao servidor.
|
|
4706
|
-
|
|
4707
|
-
|
|
4730
|
+
// Daqui alguns dias este trecho será removido e os tokens serão enviados exclusivamente pelos Cookies, mas por enquanto, para manter compatibilidade com o que já existe, o token será enviado no header
|
|
4731
|
+
let headers = req.headers.set('Authorization', `Bearer ${this._authStorage.authToken}`);
|
|
4732
|
+
changedReq = req.clone({
|
|
4733
|
+
headers: headers,
|
|
4734
|
+
//withCredentials: true // Parâmetro necessário para utilização dos Cookies HttpOnly
|
|
4735
|
+
});
|
|
4708
4736
|
}
|
|
4709
|
-
return await lastValueFrom(next.handle(changedReq));
|
|
4737
|
+
// return await lastValueFrom(next.handle(changedReq));
|
|
4738
|
+
// Exemplo de leitura de resposta via interceptor abaixo:
|
|
4739
|
+
return await lastValueFrom(next.handle(changedReq)
|
|
4740
|
+
// INTERCEPTAR RESPOSTA
|
|
4741
|
+
.pipe(tap(event => {
|
|
4742
|
+
if (event instanceof HttpResponse) {
|
|
4743
|
+
// console.log("Resposta HTTP interceptada:", event);
|
|
4744
|
+
}
|
|
4745
|
+
}),
|
|
4746
|
+
// INTERCEPTAR ERRO
|
|
4747
|
+
catchError(error => {
|
|
4748
|
+
// console.error("Erro HTTP interceptado:", error);
|
|
4749
|
+
return throwError(() => error);
|
|
4750
|
+
})));
|
|
4710
4751
|
}
|
|
4711
4752
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthAplicInterceptor, deps: [{ token: i3.CheckUrlAndMethodService }, { token: AuthStorageService }, { token: LibCustomEnvironmentService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
4712
4753
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthAplicInterceptor, providedIn: 'root' }); }
|
|
@@ -4716,23 +4757,42 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
4716
4757
|
args: [{ providedIn: 'root' }]
|
|
4717
4758
|
}], ctorParameters: () => [{ type: i3.CheckUrlAndMethodService }, { type: AuthStorageService }, { type: LibCustomEnvironmentService }] });
|
|
4718
4759
|
|
|
4719
|
-
/**
|
|
4720
|
-
* \brief Intercepta uma chamada HTTP para inserir a autenticação da Sispro.
|
|
4721
|
-
*/
|
|
4760
|
+
/** Intercepta uma chamada HTTP para inserir a autenticação da básica das APIs nos Cookies (e no header, para compatibilidade) */
|
|
4722
4761
|
class AuthInfraInterceptor {
|
|
4723
|
-
constructor(
|
|
4724
|
-
this.
|
|
4762
|
+
constructor(_authCheckService, _customEnvironmentService) {
|
|
4763
|
+
this._authCheckService = _authCheckService;
|
|
4725
4764
|
this._customEnvironmentService = _customEnvironmentService;
|
|
4726
4765
|
}
|
|
4727
4766
|
intercept(req, next) {
|
|
4728
4767
|
let changedReq = req;
|
|
4729
|
-
if (this.
|
|
4768
|
+
if (this._authCheckService.needsAuthRequest(req.url, req.method, this._customEnvironmentService.needsAuthInfra)) {
|
|
4769
|
+
// Instanciado inicialmente com os headers da requisição original, para não perder nenhum header que já tenha sido adicionado
|
|
4770
|
+
let headers = req.headers;
|
|
4730
4771
|
// Adiciona as autenticações necessárias ao servidor. Autenticação básica.
|
|
4731
|
-
|
|
4772
|
+
// Daqui alguns dias este trecho será removido e os tokens serão enviados exclusivamente pelos Cookies, mas por enquanto, para manter compatibilidade com o que já existe, o token será enviado no header
|
|
4773
|
+
if (localStorage.getItem('configServerUser') && localStorage.getItem('configServerPassword')) {
|
|
4774
|
+
headers = req.headers.set("Authorization", `Basic ${btoa(`${localStorage.getItem('configServerUser')}:${localStorage.getItem('configServerPassword')}`)}
|
|
4732
4775
|
`);
|
|
4733
|
-
|
|
4776
|
+
}
|
|
4777
|
+
changedReq = req.clone({
|
|
4778
|
+
headers: headers,
|
|
4779
|
+
//withCredentials: true // Parâmetro necessário para utilização dos Cookies HttpOnly
|
|
4780
|
+
});
|
|
4734
4781
|
}
|
|
4735
|
-
return next.handle(changedReq);
|
|
4782
|
+
// return next.handle(changedReq);
|
|
4783
|
+
// Exemplo de leitura de resposta via interceptor abaixo:
|
|
4784
|
+
return next.handle(changedReq)
|
|
4785
|
+
// INTERCEPTAR RESPOSTA
|
|
4786
|
+
.pipe(tap(event => {
|
|
4787
|
+
if (event instanceof HttpResponse) {
|
|
4788
|
+
console.log("Resposta HTTP interceptada:", event);
|
|
4789
|
+
}
|
|
4790
|
+
}),
|
|
4791
|
+
// INTERCEPTAR ERRO
|
|
4792
|
+
catchError(error => {
|
|
4793
|
+
console.error("Erro HTTP interceptado:", error);
|
|
4794
|
+
return throwError(() => error);
|
|
4795
|
+
}));
|
|
4736
4796
|
}
|
|
4737
4797
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthInfraInterceptor, deps: [{ token: i3.CheckUrlAndMethodService }, { token: LibCustomEnvironmentService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
4738
4798
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthInfraInterceptor, providedIn: 'root' }); }
|