ngx-sp-auth 4.21.0 → 4.21.1
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 +229 -192
- package/fesm2022/ngx-sp-auth.mjs.map +1 -1
- package/lib/auth.service.d.ts +7 -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 } 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
|
+
import { BehaviorSubject, firstValueFrom, take, tap, Subject, Subscription, debounceTime, distinctUntilChanged, filter, switchMap, timer, map as map$1, of, lastValueFrom, from } from 'rxjs';
|
|
8
9
|
import { take as take$1, tap as tap$1, map, switchMap as switchMap$1 } from 'rxjs/operators';
|
|
9
10
|
import * as i1$1 from '@angular/router';
|
|
10
11
|
import { RouterLink, NavigationEnd, RouterOutlet } from '@angular/router';
|
|
11
|
-
import { BehaviorSubject, take, tap, Subject, Subscription, debounceTime, distinctUntilChanged, filter, switchMap, timer, map as map$1, firstValueFrom, of, lastValueFrom, from } 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,22 @@ 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
|
}
|
|
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
|
+
*/
|
|
842
920
|
logout() {
|
|
843
|
-
|
|
844
|
-
this.
|
|
845
|
-
this.
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
this.
|
|
854
|
-
this.__userName = "";
|
|
855
|
-
this.__authToken = "";
|
|
856
|
-
this.__dominio = "";
|
|
857
|
-
this.__tokenPayload = {};
|
|
858
|
-
this.__isExternalLogin = false;
|
|
859
|
-
this.__infraInAuthTypeId = 0;
|
|
860
|
-
this.__infraIn2FaTypeId = null;
|
|
861
|
-
this.__is2FaEnabled = false;
|
|
862
|
-
this.__azureTenantId = "";
|
|
863
|
-
this.__azureClientId = "";
|
|
864
|
-
localStorage.removeItem(this.__local_key);
|
|
865
|
-
// Limpa o armazenamento local do navegador que contém os filtros de um produto específico
|
|
866
|
-
// Fecha a conexão local (se houver) antes de excluir a database para evitar o callback 'blocking'
|
|
867
|
-
this._indexedDBService.closeOpenConnection()
|
|
868
|
-
.then(() => this._indexedDBService.deleteDatabase())
|
|
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();
|
|
921
|
+
// Consumo de endpoint de logout
|
|
922
|
+
const url = `${this._LOGOUT_BASE_URL}`;
|
|
923
|
+
firstValueFrom(this._httpClient.post(url, null, { 'headers': this._HTTP_HEADERS })).then(res => {
|
|
924
|
+
console.log(res);
|
|
925
|
+
this.onLogout();
|
|
926
|
+
localStorage.removeItem('configServerUser');
|
|
927
|
+
localStorage.removeItem('configServerPassword');
|
|
928
|
+
// Método com customizações para inicializações do Logout
|
|
929
|
+
this._customLoginService.authLogout();
|
|
930
|
+
});
|
|
931
|
+
return this._router.navigate(["/auth/login"]);
|
|
872
932
|
}
|
|
873
933
|
getNewTokenBack() {
|
|
874
934
|
let token = {
|
|
@@ -881,15 +941,14 @@ class AuthStorageService {
|
|
|
881
941
|
};
|
|
882
942
|
const url = `${this._BASE_URL}/GetNewToken`;
|
|
883
943
|
const headers = new HttpHeaders()
|
|
884
|
-
.set('Content-Type', 'application/json')
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
}
|
|
892
|
-
}));
|
|
944
|
+
.set('Content-Type', 'application/json');
|
|
945
|
+
// Remover/comentar o header abaixo pois o token será enviado via Cookie HttpOnly, e não mais via header Authorization
|
|
946
|
+
// .set('Authorization',
|
|
947
|
+
// `Basic ${btoa(`${localStorage.getItem('configServerUser')}:${localStorage.getItem('configServerPassword')}`)}`
|
|
948
|
+
// );
|
|
949
|
+
return this._httpClient.post(url, token, { 'headers': headers, withCredentials: true })
|
|
950
|
+
.pipe(take(1), tap((response) => { if (response.Error)
|
|
951
|
+
throw Error(response.ErrorMessage); }));
|
|
893
952
|
}
|
|
894
953
|
getNewToken() {
|
|
895
954
|
return new Promise((resolve, reject) => {
|
|
@@ -926,6 +985,37 @@ class AuthStorageService {
|
|
|
926
985
|
}
|
|
927
986
|
}
|
|
928
987
|
}
|
|
988
|
+
onLogout() {
|
|
989
|
+
this.__isCheckingAuth = false;
|
|
990
|
+
this.isLoggedInSub.next(false);
|
|
991
|
+
this.__UrlRedirect = "/";
|
|
992
|
+
this.__ip = "";
|
|
993
|
+
this.__tenantId = 0;
|
|
994
|
+
this.__infraUsuarioId = "";
|
|
995
|
+
this.__infraEstabId = "";
|
|
996
|
+
this.__infraEstabNome = "";
|
|
997
|
+
this.__infraEmpresaId = "";
|
|
998
|
+
this.__infraEmpresaNome = "";
|
|
999
|
+
this.__user = "";
|
|
1000
|
+
this.__userName = "";
|
|
1001
|
+
this.__authToken = "";
|
|
1002
|
+
this.__dominio = "";
|
|
1003
|
+
this.__tokenPayload = {};
|
|
1004
|
+
this.__isExternalLogin = false;
|
|
1005
|
+
this.__infraInAuthTypeId = 0;
|
|
1006
|
+
this.__infraIn2FaTypeId = null;
|
|
1007
|
+
this.__is2FaEnabled = false;
|
|
1008
|
+
this.__azureTenantId = "";
|
|
1009
|
+
this.__azureClientId = "";
|
|
1010
|
+
localStorage.removeItem(this.__local_key);
|
|
1011
|
+
// Limpa o armazenamento local do navegador que contém os filtros de um produto específico
|
|
1012
|
+
// Fecha a conexão local (se houver) antes de excluir a database para evitar o callback 'blocking'
|
|
1013
|
+
this._indexedDBService.closeOpenConnection()
|
|
1014
|
+
.then(() => this._indexedDBService.deleteDatabase())
|
|
1015
|
+
.catch((err) => console.warn('logout() => falha ao limpar conexão', err));
|
|
1016
|
+
// Método com customizações para finalizações da storage
|
|
1017
|
+
this._customStorageService.storageLogout();
|
|
1018
|
+
}
|
|
929
1019
|
isPrePortal() {
|
|
930
1020
|
// Identifica se a origem é PrePortal
|
|
931
1021
|
var url = new URL(window.location.href);
|
|
@@ -942,114 +1032,46 @@ class AuthStorageService {
|
|
|
942
1032
|
return false;
|
|
943
1033
|
}
|
|
944
1034
|
}
|
|
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 }); }
|
|
1035
|
+
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
1036
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthStorageService, providedIn: 'root' }); }
|
|
947
1037
|
}
|
|
948
1038
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthStorageService, decorators: [{
|
|
949
1039
|
type: Injectable,
|
|
950
1040
|
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
|
-
}] }] });
|
|
1041
|
+
}], ctorParameters: () => [{ type: i1.HttpBackend }, { type: LibCustomStorageService }, { type: IndexedDBService }, { type: LibCustomEnvironmentService }, { type: LibCustomLoginService }, { type: i1$1.Router }] });
|
|
1020
1042
|
|
|
1021
1043
|
class AuthUtilService {
|
|
1022
|
-
constructor(
|
|
1023
|
-
this.
|
|
1024
|
-
this.
|
|
1025
|
-
this.checkUrlAndMethodService = checkUrlAndMethodService;
|
|
1026
|
-
this.messageService = messageService;
|
|
1044
|
+
constructor(_authStorageService, _checkUrlAndMethodService, _customEnvironmentService, _message, _router) {
|
|
1045
|
+
this._authStorageService = _authStorageService;
|
|
1046
|
+
this._checkUrlAndMethodService = _checkUrlAndMethodService;
|
|
1027
1047
|
this._customEnvironmentService = _customEnvironmentService;
|
|
1048
|
+
this._message = _message;
|
|
1049
|
+
this._router = _router;
|
|
1028
1050
|
}
|
|
1029
1051
|
// Exibe a mensagem de erro de uma requisição http
|
|
1030
1052
|
showHttpError(error) {
|
|
1031
1053
|
if (error.error instanceof ErrorEvent) {
|
|
1032
1054
|
// Erro ocorreu no lado do cliente
|
|
1033
|
-
this.
|
|
1055
|
+
this._message.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1034
1056
|
}
|
|
1035
1057
|
else {
|
|
1036
1058
|
// Erro ocorreu no lado do servidor
|
|
1037
1059
|
let isUnauthorizedAccess = error.status === 401;
|
|
1038
1060
|
if (isUnauthorizedAccess) {
|
|
1039
|
-
let isFromAplic = this.
|
|
1061
|
+
let isFromAplic = this._checkUrlAndMethodService.needsAuthRequest(error.url, "*", this._customEnvironmentService.needsAuthAplic);
|
|
1040
1062
|
if (isFromAplic) {
|
|
1063
|
+
// Comentado pois neste projeto esta alteração de valores não realizava o logout como deveria corretamente...
|
|
1064
|
+
// this.authStorageService.isLoggedInSub.next(false);
|
|
1065
|
+
// this.authStorageService.urlRedirect = "/";
|
|
1041
1066
|
// 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));
|
|
1067
|
+
this._authStorageService.logout().then(this.showExpiredAccess.bind(this));
|
|
1046
1068
|
}
|
|
1047
1069
|
else {
|
|
1048
|
-
this.
|
|
1070
|
+
this._message.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1049
1071
|
}
|
|
1050
1072
|
}
|
|
1051
1073
|
else {
|
|
1052
|
-
this.
|
|
1074
|
+
this._message.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1053
1075
|
}
|
|
1054
1076
|
}
|
|
1055
1077
|
}
|
|
@@ -1057,32 +1079,33 @@ class AuthUtilService {
|
|
|
1057
1079
|
showHTTPErrorOS(error) {
|
|
1058
1080
|
if (error.error instanceof ErrorEvent) {
|
|
1059
1081
|
// Erro ocorreu no lado do cliente
|
|
1060
|
-
this.
|
|
1061
|
-
this.
|
|
1082
|
+
this._router.navigate(["/auth/login"]).then(e => {
|
|
1083
|
+
this._message.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1062
1084
|
});
|
|
1063
1085
|
}
|
|
1064
1086
|
else {
|
|
1065
1087
|
// Erro ocorreu no lado do servidor
|
|
1066
1088
|
let isUnauthorizedAccess = error.status === 401;
|
|
1067
1089
|
if (isUnauthorizedAccess) {
|
|
1068
|
-
let isFromAplic = this.
|
|
1090
|
+
let isFromAplic = this._checkUrlAndMethodService.needsAuthRequest(error.url, "*", this._customEnvironmentService.needsAuthAplic);
|
|
1069
1091
|
if (isFromAplic) {
|
|
1092
|
+
// Comentado pois neste projeto esta alteração de valores não realizava o logout como deveria corretamente...
|
|
1093
|
+
// this.authStorageService.isLoggedInSub.next(false);
|
|
1094
|
+
// this.authStorageService.urlRedirect = "/";
|
|
1070
1095
|
// 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));
|
|
1096
|
+
this._authStorageService.logout().then(() => {
|
|
1097
|
+
this._message.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1075
1098
|
});
|
|
1076
1099
|
}
|
|
1077
1100
|
else {
|
|
1078
|
-
this.
|
|
1079
|
-
this.
|
|
1101
|
+
this._router.navigate(["/auth/login"]).then(e => {
|
|
1102
|
+
this._message.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1080
1103
|
});
|
|
1081
1104
|
}
|
|
1082
1105
|
}
|
|
1083
1106
|
else {
|
|
1084
|
-
this.
|
|
1085
|
-
this.
|
|
1107
|
+
this._router.navigate(["/auth/login"]).then(e => {
|
|
1108
|
+
this._message.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1086
1109
|
});
|
|
1087
1110
|
}
|
|
1088
1111
|
}
|
|
@@ -1090,14 +1113,14 @@ class AuthUtilService {
|
|
|
1090
1113
|
// Mostra uma mensagem de sessão expirada.
|
|
1091
1114
|
showExpiredAccess(navigationResult) {
|
|
1092
1115
|
if (navigationResult) {
|
|
1093
|
-
this.
|
|
1116
|
+
this._message.showAlertWarning("Sessão expirada, logue-se novamente.");
|
|
1094
1117
|
}
|
|
1095
1118
|
}
|
|
1096
1119
|
// Obtém o hostName
|
|
1097
1120
|
getHostName() {
|
|
1098
1121
|
return this._customEnvironmentService.hostName;
|
|
1099
1122
|
}
|
|
1100
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthUtilService, deps: [{ token:
|
|
1123
|
+
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
1124
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthUtilService, providedIn: 'root' }); }
|
|
1102
1125
|
}
|
|
1103
1126
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthUtilService, decorators: [{
|
|
@@ -1105,7 +1128,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
1105
1128
|
args: [{
|
|
1106
1129
|
providedIn: 'root'
|
|
1107
1130
|
}]
|
|
1108
|
-
}], ctorParameters: () => [{ type:
|
|
1131
|
+
}], ctorParameters: () => [{ type: AuthStorageService }, { type: i3.CheckUrlAndMethodService }, { type: LibCustomEnvironmentService }, { type: i3.MessageService }, { type: i1$1.Router }] });
|
|
1109
1132
|
|
|
1110
1133
|
class AuthService {
|
|
1111
1134
|
// #endregion PRIVATE
|
|
@@ -1122,20 +1145,23 @@ class AuthService {
|
|
|
1122
1145
|
// #region ==========> PROPERTIES <==========
|
|
1123
1146
|
// #region PRIVATE
|
|
1124
1147
|
this._pendingWarning = null;
|
|
1125
|
-
this._BASE_URL = ''; // SpInfra2WS
|
|
1126
1148
|
this._AUTH_BASE_URL = ''; // SpInfra2AuthWS
|
|
1149
|
+
this._BASE_URL = ''; // SpInfra2WS
|
|
1127
1150
|
this._BASE_OS_URL = ''; // SpInfra2LoginWS
|
|
1151
|
+
this._LOGOUT_BASE_URL = ''; // SpInfra2LoginWS
|
|
1128
1152
|
this._HTTP_HEADERS = new HttpHeaders().set('Content-Type', 'application/json');
|
|
1129
1153
|
this.ip = "undefined";
|
|
1130
1154
|
this.city = "undefined";
|
|
1131
1155
|
this.state = "undefined";
|
|
1132
1156
|
this.country = "undefined";
|
|
1133
|
-
this._BASE_URL = `${this._customEnvironmentService.SpInfra2LoginWS}/LoginSisproERP`; // SpInfra2WS
|
|
1134
1157
|
this._AUTH_BASE_URL = `${this._customEnvironmentService.SpInfra2AuthWS}/Auth`; // SpInfra2AuthWS
|
|
1158
|
+
this._BASE_URL = `${this._customEnvironmentService.SpInfra2LoginWS}/LoginSisproERP`; // SpInfra2LoginWS
|
|
1135
1159
|
this._BASE_OS_URL = `${this._customEnvironmentService.SpInfra2LoginWS}/LoginIntegradoOS`; // SpInfra2LoginWS
|
|
1136
|
-
this.
|
|
1160
|
+
this._LOGOUT_BASE_URL = `${this._customEnvironmentService.SpInfra2LoginWS}/LogoutSisproErp`; // SpInfra2LoginWS
|
|
1137
1161
|
this._AUTH_BASE_URL = !this._customEnvironmentService.production ? this._AUTH_BASE_URL : `${this._customEnvironmentService.SpInfra2AuthWS}/Auth`;
|
|
1162
|
+
this._BASE_URL = !this._customEnvironmentService.production ? this._BASE_URL : `${this._customEnvironmentService.SpInfra2LoginWS}/LoginSisproERP`;
|
|
1138
1163
|
this._BASE_OS_URL = !this._customEnvironmentService.production ? this._BASE_OS_URL : `${this._customEnvironmentService.SpInfra2LoginWS}/LoginIntegradoOS`;
|
|
1164
|
+
this._LOGOUT_BASE_URL = !this._customEnvironmentService.production ? this._LOGOUT_BASE_URL : `${this._customEnvironmentService.SpInfra2LoginWS}/LogoutSisproErp`;
|
|
1139
1165
|
this.getParms();
|
|
1140
1166
|
}
|
|
1141
1167
|
// #region ==========> SERVICE METHODS <==========
|
|
@@ -1193,8 +1219,10 @@ class AuthService {
|
|
|
1193
1219
|
if (response.Error) {
|
|
1194
1220
|
throw Error(response.ErrorMessage);
|
|
1195
1221
|
}
|
|
1196
|
-
|
|
1197
|
-
|
|
1222
|
+
// Comentadas pois não serão mais armazenadas desta forma, o webservice gerará um Cookie com o valor já formatado para Base64
|
|
1223
|
+
// E o mesmo será enviada nas requisições subsequentes via párâmetro `withCredentials: true`, e não mais via header Authorization
|
|
1224
|
+
// localStorage.setItem('configServerUser', response.User);
|
|
1225
|
+
// localStorage.setItem('configServerPassword', response.Password);
|
|
1198
1226
|
this._authStorageService.tenantId = response.TenantId;
|
|
1199
1227
|
this._authStorageService.dominio = response.Domain;
|
|
1200
1228
|
this._authStorageService.infraInAuthTypeId = response.InfraInAuthTypeId;
|
|
@@ -1438,14 +1466,22 @@ class AuthService {
|
|
|
1438
1466
|
}
|
|
1439
1467
|
}));
|
|
1440
1468
|
}
|
|
1441
|
-
/**
|
|
1469
|
+
/**
|
|
1470
|
+
* 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.
|
|
1471
|
+
* @returns Promise<boolean> indicando navegação para a tela de login após o logout.
|
|
1472
|
+
*/
|
|
1442
1473
|
logout() {
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1474
|
+
// Consumo de endpoint de logout
|
|
1475
|
+
const url = `${this._LOGOUT_BASE_URL}`;
|
|
1476
|
+
firstValueFrom(this._httpClient.post(url, null, { 'headers': this._HTTP_HEADERS })).then(res => {
|
|
1477
|
+
console.log(res);
|
|
1478
|
+
this._authStorageService.logout();
|
|
1479
|
+
localStorage.removeItem('configServerUser');
|
|
1480
|
+
localStorage.removeItem('configServerPassword');
|
|
1481
|
+
// Método com customizações para inicializações do Logout
|
|
1482
|
+
this._customLoginService.authLogout();
|
|
1483
|
+
});
|
|
1484
|
+
return this._router.navigate(["/auth/login"]);
|
|
1449
1485
|
}
|
|
1450
1486
|
validateAuthentication2Fa(code) {
|
|
1451
1487
|
let Code2Fa = {
|
|
@@ -1972,16 +2008,12 @@ class PesquisaTelasGlobalService {
|
|
|
1972
2008
|
// #region PUBLIC
|
|
1973
2009
|
// #endregion PUBLIC
|
|
1974
2010
|
// #endregion ==========> PROPERTIES <==========
|
|
1975
|
-
constructor(
|
|
1976
|
-
this._componentFactoryResolver = _componentFactoryResolver;
|
|
2011
|
+
constructor(_appRef, _injector, _httpClient, _customEnvironmentService, _authUtils) {
|
|
1977
2012
|
this._appRef = _appRef;
|
|
1978
2013
|
this._injector = _injector;
|
|
1979
2014
|
this._httpClient = _httpClient;
|
|
1980
2015
|
this._customEnvironmentService = _customEnvironmentService;
|
|
1981
2016
|
this._authUtils = _authUtils;
|
|
1982
|
-
// #region ==========> PROPERTIES <==========
|
|
1983
|
-
// #region PRIVATE
|
|
1984
|
-
// #region GERENCIAMENTO DINÂMICO DO COMPONENTE
|
|
1985
2017
|
/**
|
|
1986
2018
|
* Referência ao componente dinâmico criado.
|
|
1987
2019
|
* Usado para gerenciar o ciclo de vida e estado do componente.
|
|
@@ -2103,7 +2135,7 @@ class PesquisaTelasGlobalService {
|
|
|
2103
2135
|
*
|
|
2104
2136
|
* Este método utiliza a API baixo nível do Angular para criar um componente dinamicamente e anexá-lo ao DOM. O processo envolve:
|
|
2105
2137
|
*
|
|
2106
|
-
* 1. Criar o componente via
|
|
2138
|
+
* 1. Criar o componente via `container.createComponent()`
|
|
2107
2139
|
* 2. Configurar suas propriedades iniciais
|
|
2108
2140
|
* 3. Registrá-lo no mecanismo de detecção de mudanças do Angular
|
|
2109
2141
|
* 4. Anexá-lo ao DOM (fora da hierarquia normal de componentes)
|
|
@@ -2119,24 +2151,18 @@ class PesquisaTelasGlobalService {
|
|
|
2119
2151
|
if (this._componentRef) {
|
|
2120
2152
|
return;
|
|
2121
2153
|
}
|
|
2122
|
-
// 1.
|
|
2123
|
-
|
|
2124
|
-
//
|
|
2125
|
-
const componentFactory = this._componentFactoryResolver.resolveComponentFactory(SearchInputComponent);
|
|
2126
|
-
// 2. Cria uma nova instância do componente usando o injector raiz
|
|
2127
|
-
// Isso garante que o componente tenha acesso aos mesmos serviços
|
|
2128
|
-
// que componentes criados normalmente via template
|
|
2129
|
-
this._componentRef = componentFactory.create(this._injector);
|
|
2130
|
-
// 3. Registra a view do componente no ApplicationRef
|
|
2154
|
+
// 1. Cria uma nova instância do componente
|
|
2155
|
+
this._componentRef = this._container.createComponent(SearchInputComponent);
|
|
2156
|
+
// 2. Registra a view do componente no ApplicationRef
|
|
2131
2157
|
// Isso é CRÍTICO: sem este passo, o componente não participaria
|
|
2132
2158
|
// do ciclo de detecção de mudanças do Angular
|
|
2133
2159
|
this._appRef.attachView(this._componentRef.hostView);
|
|
2134
|
-
//
|
|
2160
|
+
// 3. Obtém o elemento DOM raiz do componente e o anexa ao body
|
|
2135
2161
|
// Como este componente é criado fora da hierarquia normal,
|
|
2136
2162
|
// precisamos anexá-lo manualmente ao DOM
|
|
2137
2163
|
const domElem = this._componentRef.hostView.rootNodes[0];
|
|
2138
2164
|
document.body.appendChild(domElem);
|
|
2139
|
-
//
|
|
2165
|
+
// 4. Configura os listeners dos eventos do componente
|
|
2140
2166
|
// 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.
|
|
2141
2167
|
this._componentCloseSub = this._componentRef.instance.onClose.subscribe(() => this._onClose$.next());
|
|
2142
2168
|
// 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.
|
|
@@ -2180,13 +2206,16 @@ class PesquisaTelasGlobalService {
|
|
|
2180
2206
|
// #endregion GERENCIAMENTO DO COMPONENTE
|
|
2181
2207
|
showErrorMessage(response) { if (response.Error)
|
|
2182
2208
|
throw Error(response.ErrorMessage); }
|
|
2183
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: PesquisaTelasGlobalService, deps: [{ token: i0.
|
|
2209
|
+
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 }); }
|
|
2184
2210
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: PesquisaTelasGlobalService, providedIn: 'root' }); }
|
|
2185
2211
|
}
|
|
2186
2212
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: PesquisaTelasGlobalService, decorators: [{
|
|
2187
2213
|
type: Injectable,
|
|
2188
2214
|
args: [{ providedIn: 'root' }]
|
|
2189
|
-
}], ctorParameters: () => [{ type: i0.
|
|
2215
|
+
}], ctorParameters: () => [{ type: i0.ApplicationRef }, { type: i0.Injector }, { type: i1.HttpClient }, { type: LibCustomEnvironmentService }, { type: AuthUtilService }], propDecorators: { _container: [{
|
|
2216
|
+
type: ViewChild,
|
|
2217
|
+
args: ['container', { read: ViewContainerRef, static: true }]
|
|
2218
|
+
}] } });
|
|
2190
2219
|
|
|
2191
2220
|
class ErrorMenuNotAllowed {
|
|
2192
2221
|
constructor(router, authStorageService) {
|
|
@@ -4655,15 +4684,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
4655
4684
|
;
|
|
4656
4685
|
|
|
4657
4686
|
/**
|
|
4658
|
-
*
|
|
4659
|
-
* com o login para uso da API.
|
|
4660
|
-
*
|
|
4687
|
+
* 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.
|
|
4661
4688
|
* Depende do serviço de autenticação.
|
|
4662
|
-
|
|
4689
|
+
*/
|
|
4663
4690
|
class AuthAplicInterceptor {
|
|
4664
|
-
constructor(
|
|
4665
|
-
this.
|
|
4666
|
-
this.
|
|
4691
|
+
constructor(_authCheckService, _authStorage, _customEnvironmentService) {
|
|
4692
|
+
this._authCheckService = _authCheckService;
|
|
4693
|
+
this._authStorage = _authStorage;
|
|
4667
4694
|
this._customEnvironmentService = _customEnvironmentService;
|
|
4668
4695
|
}
|
|
4669
4696
|
intercept(req, next) {
|
|
@@ -4672,12 +4699,16 @@ class AuthAplicInterceptor {
|
|
|
4672
4699
|
}
|
|
4673
4700
|
async handle(req, next) {
|
|
4674
4701
|
let changedReq = req;
|
|
4675
|
-
if (this.
|
|
4702
|
+
if (this._authCheckService.needsAuthRequest(req.url, req.method, this._customEnvironmentService.needsAuthAplic)) {
|
|
4676
4703
|
// Verifica se o Token precisa ser renovado
|
|
4677
|
-
await this.
|
|
4704
|
+
await this._authStorage.renewToken();
|
|
4678
4705
|
// Adiciona as autenticações necessárias ao servidor.
|
|
4679
|
-
|
|
4680
|
-
|
|
4706
|
+
// 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
|
|
4707
|
+
let headers = req.headers.set('Authorization', `Bearer ${this._authStorage.authToken}`);
|
|
4708
|
+
changedReq = req.clone({
|
|
4709
|
+
headers: headers,
|
|
4710
|
+
withCredentials: true // Parâmetro necessário para utilização dos Cookies HttpOnly
|
|
4711
|
+
});
|
|
4681
4712
|
}
|
|
4682
4713
|
return await lastValueFrom(next.handle(changedReq));
|
|
4683
4714
|
}
|
|
@@ -4689,21 +4720,27 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
4689
4720
|
args: [{ providedIn: 'root' }]
|
|
4690
4721
|
}], ctorParameters: () => [{ type: i3.CheckUrlAndMethodService }, { type: AuthStorageService }, { type: LibCustomEnvironmentService }] });
|
|
4691
4722
|
|
|
4692
|
-
/**
|
|
4693
|
-
* \brief Intercepta uma chamada HTTP para inserir a autenticação da Sispro.
|
|
4694
|
-
*/
|
|
4723
|
+
/** Intercepta uma chamada HTTP para inserir a autenticação da básica das APIs nos Cookies (e no header, para compatibilidade) */
|
|
4695
4724
|
class AuthInfraInterceptor {
|
|
4696
|
-
constructor(
|
|
4697
|
-
this.
|
|
4725
|
+
constructor(_authCheckService, _customEnvironmentService) {
|
|
4726
|
+
this._authCheckService = _authCheckService;
|
|
4698
4727
|
this._customEnvironmentService = _customEnvironmentService;
|
|
4699
4728
|
}
|
|
4700
4729
|
intercept(req, next) {
|
|
4701
4730
|
let changedReq = req;
|
|
4702
|
-
if (this.
|
|
4731
|
+
if (this._authCheckService.needsAuthRequest(req.url, req.method, this._customEnvironmentService.needsAuthInfra)) {
|
|
4732
|
+
// Instanciado inicialmente com os headers da requisição original, para não perder nenhum header que já tenha sido adicionado
|
|
4733
|
+
let headers = req.headers;
|
|
4703
4734
|
// Adiciona as autenticações necessárias ao servidor. Autenticação básica.
|
|
4704
|
-
|
|
4735
|
+
// 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
|
|
4736
|
+
if (localStorage.getItem('configServerUser') && localStorage.getItem('configServerPassword')) {
|
|
4737
|
+
headers = req.headers.set("Authorization", `Basic ${btoa(`${localStorage.getItem('configServerUser')}:${localStorage.getItem('configServerPassword')}`)}
|
|
4705
4738
|
`);
|
|
4706
|
-
|
|
4739
|
+
}
|
|
4740
|
+
changedReq = req.clone({
|
|
4741
|
+
headers: headers,
|
|
4742
|
+
withCredentials: true // Parâmetro necessário para utilização dos Cookies HttpOnly
|
|
4743
|
+
});
|
|
4707
4744
|
}
|
|
4708
4745
|
return next.handle(changedReq);
|
|
4709
4746
|
}
|