ngx-sp-auth 4.20.4 → 4.20.7
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
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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 } from '@angular/core';
|
|
3
3
|
import * as i1 from '@angular/common/http';
|
|
4
4
|
import { HTTP_INTERCEPTORS, HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
|
5
5
|
import * as i1$2 from '@azure/msal-angular';
|
|
@@ -881,15 +881,14 @@ class AuthStorageService {
|
|
|
881
881
|
};
|
|
882
882
|
const url = `${this._BASE_URL}/GetNewToken`;
|
|
883
883
|
const headers = new HttpHeaders()
|
|
884
|
-
.set('Content-Type', 'application/json')
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
}
|
|
892
|
-
}));
|
|
884
|
+
.set('Content-Type', 'application/json');
|
|
885
|
+
// Remover/comentar o header abaixo pois o token será enviado via Cookie HttpOnly, e não mais via header Authorization
|
|
886
|
+
// .set('Authorization',
|
|
887
|
+
// `Basic ${btoa(`${localStorage.getItem('configServerUser')}:${localStorage.getItem('configServerPassword')}`)}`
|
|
888
|
+
// );
|
|
889
|
+
return this._httpClient.post(url, token, { 'headers': headers, withCredentials: true })
|
|
890
|
+
.pipe(take(1), tap((response) => { if (response.Error)
|
|
891
|
+
throw Error(response.ErrorMessage); }));
|
|
893
892
|
}
|
|
894
893
|
getNewToken() {
|
|
895
894
|
return new Promise((resolve, reject) => {
|
|
@@ -1130,7 +1129,7 @@ class AuthService {
|
|
|
1130
1129
|
this.city = "undefined";
|
|
1131
1130
|
this.state = "undefined";
|
|
1132
1131
|
this.country = "undefined";
|
|
1133
|
-
this._BASE_URL = `${this._customEnvironmentService.
|
|
1132
|
+
this._BASE_URL = `${this._customEnvironmentService.Sp2LocalhostInfra2LoginWS}/LoginSisproERP`; // SpInfra2WS
|
|
1134
1133
|
this._AUTH_BASE_URL = `${this._customEnvironmentService.SpInfra2AuthWS}/Auth`; // SpInfra2AuthWS
|
|
1135
1134
|
this._BASE_OS_URL = `${this._customEnvironmentService.SpInfra2LoginWS}/LoginIntegradoOS`; // SpInfra2LoginWS
|
|
1136
1135
|
this._BASE_URL = !this._customEnvironmentService.production ? this._BASE_URL : `${this._customEnvironmentService.SpInfra2LoginWS}/LoginSisproERP`;
|
|
@@ -1193,8 +1192,10 @@ class AuthService {
|
|
|
1193
1192
|
if (response.Error) {
|
|
1194
1193
|
throw Error(response.ErrorMessage);
|
|
1195
1194
|
}
|
|
1196
|
-
|
|
1197
|
-
|
|
1195
|
+
// Comentadas pois não serão mais armazenadas desta forma, o webservice gerará um Cookie com o valor já formatado para Base64
|
|
1196
|
+
// E o mesmo será enviada nas requisições subsequentes via párâmetro `withCredentials: true`, e não mais via header Authorization
|
|
1197
|
+
// localStorage.setItem('configServerUser', response.User);
|
|
1198
|
+
// localStorage.setItem('configServerPassword', response.Password);
|
|
1198
1199
|
this._authStorageService.tenantId = response.TenantId;
|
|
1199
1200
|
this._authStorageService.dominio = response.Domain;
|
|
1200
1201
|
this._authStorageService.infraInAuthTypeId = response.InfraInAuthTypeId;
|
|
@@ -1972,16 +1973,12 @@ class PesquisaTelasGlobalService {
|
|
|
1972
1973
|
// #region PUBLIC
|
|
1973
1974
|
// #endregion PUBLIC
|
|
1974
1975
|
// #endregion ==========> PROPERTIES <==========
|
|
1975
|
-
constructor(
|
|
1976
|
-
this._componentFactoryResolver = _componentFactoryResolver;
|
|
1976
|
+
constructor(_appRef, _injector, _httpClient, _customEnvironmentService, _authUtils) {
|
|
1977
1977
|
this._appRef = _appRef;
|
|
1978
1978
|
this._injector = _injector;
|
|
1979
1979
|
this._httpClient = _httpClient;
|
|
1980
1980
|
this._customEnvironmentService = _customEnvironmentService;
|
|
1981
1981
|
this._authUtils = _authUtils;
|
|
1982
|
-
// #region ==========> PROPERTIES <==========
|
|
1983
|
-
// #region PRIVATE
|
|
1984
|
-
// #region GERENCIAMENTO DINÂMICO DO COMPONENTE
|
|
1985
1982
|
/**
|
|
1986
1983
|
* Referência ao componente dinâmico criado.
|
|
1987
1984
|
* Usado para gerenciar o ciclo de vida e estado do componente.
|
|
@@ -2103,7 +2100,7 @@ class PesquisaTelasGlobalService {
|
|
|
2103
2100
|
*
|
|
2104
2101
|
* 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
2102
|
*
|
|
2106
|
-
* 1. Criar o componente via
|
|
2103
|
+
* 1. Criar o componente via `container.createComponent()`
|
|
2107
2104
|
* 2. Configurar suas propriedades iniciais
|
|
2108
2105
|
* 3. Registrá-lo no mecanismo de detecção de mudanças do Angular
|
|
2109
2106
|
* 4. Anexá-lo ao DOM (fora da hierarquia normal de componentes)
|
|
@@ -2119,24 +2116,18 @@ class PesquisaTelasGlobalService {
|
|
|
2119
2116
|
if (this._componentRef) {
|
|
2120
2117
|
return;
|
|
2121
2118
|
}
|
|
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
|
|
2119
|
+
// 1. Cria uma nova instância do componente
|
|
2120
|
+
this._componentRef = this._container.createComponent(SearchInputComponent);
|
|
2121
|
+
// 2. Registra a view do componente no ApplicationRef
|
|
2131
2122
|
// Isso é CRÍTICO: sem este passo, o componente não participaria
|
|
2132
2123
|
// do ciclo de detecção de mudanças do Angular
|
|
2133
2124
|
this._appRef.attachView(this._componentRef.hostView);
|
|
2134
|
-
//
|
|
2125
|
+
// 3. Obtém o elemento DOM raiz do componente e o anexa ao body
|
|
2135
2126
|
// Como este componente é criado fora da hierarquia normal,
|
|
2136
2127
|
// precisamos anexá-lo manualmente ao DOM
|
|
2137
2128
|
const domElem = this._componentRef.hostView.rootNodes[0];
|
|
2138
2129
|
document.body.appendChild(domElem);
|
|
2139
|
-
//
|
|
2130
|
+
// 4. Configura os listeners dos eventos do componente
|
|
2140
2131
|
// 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
2132
|
this._componentCloseSub = this._componentRef.instance.onClose.subscribe(() => this._onClose$.next());
|
|
2142
2133
|
// 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 +2171,16 @@ class PesquisaTelasGlobalService {
|
|
|
2180
2171
|
// #endregion GERENCIAMENTO DO COMPONENTE
|
|
2181
2172
|
showErrorMessage(response) { if (response.Error)
|
|
2182
2173
|
throw Error(response.ErrorMessage); }
|
|
2183
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: PesquisaTelasGlobalService, deps: [{ token: i0.
|
|
2174
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: PesquisaTelasGlobalService, deps: [{ token: i0.ApplicationRef }, { token: i0.Injector }, { token: i1.HttpClient }, { token: LibCustomEnvironmentService }, { token: AuthUtilService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2184
2175
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: PesquisaTelasGlobalService, providedIn: 'root' }); }
|
|
2185
2176
|
}
|
|
2186
2177
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: PesquisaTelasGlobalService, decorators: [{
|
|
2187
2178
|
type: Injectable,
|
|
2188
2179
|
args: [{ providedIn: 'root' }]
|
|
2189
|
-
}], ctorParameters: () => [{ type: i0.
|
|
2180
|
+
}], ctorParameters: () => [{ type: i0.ApplicationRef }, { type: i0.Injector }, { type: i1.HttpClient }, { type: LibCustomEnvironmentService }, { type: AuthUtilService }], propDecorators: { _container: [{
|
|
2181
|
+
type: ViewChild,
|
|
2182
|
+
args: ['container', { read: ViewContainerRef, static: true }]
|
|
2183
|
+
}] } });
|
|
2190
2184
|
|
|
2191
2185
|
class ErrorMenuNotAllowed {
|
|
2192
2186
|
constructor(router, authStorageService) {
|
|
@@ -4321,15 +4315,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImpo
|
|
|
4321
4315
|
;
|
|
4322
4316
|
|
|
4323
4317
|
/**
|
|
4324
|
-
*
|
|
4325
|
-
* com o login para uso da API.
|
|
4326
|
-
*
|
|
4318
|
+
* 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.
|
|
4327
4319
|
* Depende do serviço de autenticação.
|
|
4328
|
-
|
|
4320
|
+
*/
|
|
4329
4321
|
class AuthAplicInterceptor {
|
|
4330
|
-
constructor(
|
|
4331
|
-
this.
|
|
4332
|
-
this.
|
|
4322
|
+
constructor(_authCheckService, _authStorage, _customEnvironmentService) {
|
|
4323
|
+
this._authCheckService = _authCheckService;
|
|
4324
|
+
this._authStorage = _authStorage;
|
|
4333
4325
|
this._customEnvironmentService = _customEnvironmentService;
|
|
4334
4326
|
}
|
|
4335
4327
|
intercept(req, next) {
|
|
@@ -4338,12 +4330,16 @@ class AuthAplicInterceptor {
|
|
|
4338
4330
|
}
|
|
4339
4331
|
async handle(req, next) {
|
|
4340
4332
|
let changedReq = req;
|
|
4341
|
-
if (this.
|
|
4333
|
+
if (this._authCheckService.needsAuthRequest(req.url, req.method, this._customEnvironmentService.needsAuthAplic)) {
|
|
4342
4334
|
// Verifica se o Token precisa ser renovado
|
|
4343
|
-
await this.
|
|
4335
|
+
await this._authStorage.renewToken();
|
|
4344
4336
|
// Adiciona as autenticações necessárias ao servidor.
|
|
4345
|
-
|
|
4346
|
-
|
|
4337
|
+
// 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
|
|
4338
|
+
let headers = req.headers.set('Authorization', `Bearer ${this._authStorage.authToken}`);
|
|
4339
|
+
changedReq = req.clone({
|
|
4340
|
+
headers: headers,
|
|
4341
|
+
withCredentials: true // Parâmetro necessário para utilização dos Cookies HttpOnly
|
|
4342
|
+
});
|
|
4347
4343
|
}
|
|
4348
4344
|
return await lastValueFrom(next.handle(changedReq));
|
|
4349
4345
|
}
|
|
@@ -4355,21 +4351,27 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImpo
|
|
|
4355
4351
|
args: [{ providedIn: 'root' }]
|
|
4356
4352
|
}], ctorParameters: () => [{ type: i3.CheckUrlAndMethodService }, { type: AuthStorageService }, { type: LibCustomEnvironmentService }] });
|
|
4357
4353
|
|
|
4358
|
-
/**
|
|
4359
|
-
* \brief Intercepta uma chamada HTTP para inserir a autenticação da Sispro.
|
|
4360
|
-
*/
|
|
4354
|
+
/** Intercepta uma chamada HTTP para inserir a autenticação da básica das APIs nos Cookies (e no header, para compatibilidade) */
|
|
4361
4355
|
class AuthInfraInterceptor {
|
|
4362
|
-
constructor(
|
|
4363
|
-
this.
|
|
4356
|
+
constructor(_authCheckService, _customEnvironmentService) {
|
|
4357
|
+
this._authCheckService = _authCheckService;
|
|
4364
4358
|
this._customEnvironmentService = _customEnvironmentService;
|
|
4365
4359
|
}
|
|
4366
4360
|
intercept(req, next) {
|
|
4367
4361
|
let changedReq = req;
|
|
4368
|
-
if (this.
|
|
4362
|
+
if (this._authCheckService.needsAuthRequest(req.url, req.method, this._customEnvironmentService.needsAuthInfra)) {
|
|
4363
|
+
// Instanciado inicialmente com os headers da requisição original, para não perder nenhum header que já tenha sido adicionado
|
|
4364
|
+
let headers = req.headers;
|
|
4369
4365
|
// Adiciona as autenticações necessárias ao servidor. Autenticação básica.
|
|
4370
|
-
|
|
4366
|
+
// 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
|
|
4367
|
+
if (localStorage.getItem('configServerUser') && localStorage.getItem('configServerPassword')) {
|
|
4368
|
+
headers = req.headers.set("Authorization", `Basic ${btoa(`${localStorage.getItem('configServerUser')}:${localStorage.getItem('configServerPassword')}`)}
|
|
4371
4369
|
`);
|
|
4372
|
-
|
|
4370
|
+
}
|
|
4371
|
+
changedReq = req.clone({
|
|
4372
|
+
headers: headers,
|
|
4373
|
+
withCredentials: true // Parâmetro necessário para utilização dos Cookies HttpOnly
|
|
4374
|
+
});
|
|
4373
4375
|
}
|
|
4374
4376
|
return next.handle(changedReq);
|
|
4375
4377
|
}
|