jwt implemented

This commit is contained in:
Eudes Inácio
2023-11-29 12:17:52 +01:00
parent 7bd1370c0b
commit f4a998584d
41 changed files with 1204 additions and 693 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ export class AttachmentsService {
setHeader() {
this.loggeduser = SessionStore.user
this.headers = new HttpHeaders();;
this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey);
this.headers = this.headers.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
}
uploadFile(formData: any) {
+56 -6
View File
@@ -3,7 +3,7 @@ import { StorageService } from './storage.service';
import { HttpClient, HttpHeaders, HttpEventType } from '@angular/common/http';
import { LoginUserRespose, UserForm, UserSession } from '../models/user.model';
import { environment } from 'src/environments/environment';
import { BehaviorSubject } from 'rxjs';
import { BehaviorSubject, of } from 'rxjs';
import { AlertController } from '@ionic/angular';
import { SessionStore } from '../store/session.service';
import { AESEncrypt } from '../services/aesencrypt.service';
@@ -21,6 +21,7 @@ import { ChatSystemService } from 'src/app/services/chat/chat-system.service';
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
import { captureException } from '@sentry/angular';
import { CPSession } from '../store/documentManagement';
import { catchError, tap } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
@@ -80,17 +81,24 @@ export class AuthService {
}
async login(user: UserForm, { saveSession = true }): Promise<LoginUserRespose> {
user.BasicAuthKey = 'Basic ' + btoa(user.username + ':' + this.aesencrypt.encrypt(user.password, user.username));
user.BasicAuthKey = btoa(user.username + ':' + this.aesencrypt.encrypt(user.password, user.username));
this.headers = this.headers.set('Authorization', user.BasicAuthKey);
this.opts = {
headers: this.headers,
/* headers: this.headers, */
"Content-Type": "application/json",
"Accept": "application/json",
}
let body = {
"Auth": user.BasicAuthKey,
"ChannelId": 1
}
let response: any;
try {
response = await this.http.post<LoginUserRespose>(environment.apiURL + "UserAuthentication/Login", '', this.opts).toPromise();
response = await this.http.post<LoginUserRespose>(environment.apiURL + "UserAuthentication/Login", body, this.opts).toPromise();
if (saveSession) {
@@ -117,7 +125,7 @@ export class AuthService {
let response: any;
try {
response = await this.http.post<LoginUserRespose>(environment.apiURL + "UserAuthentication/LoginJwt", '', this.opts).toPromise();
response = await this.http.post<LoginUserRespose>(environment.apiURL + "UserAuthentication/Login", '', this.opts).toPromise();
console.log('JWT', response)
if (saveSession) {
@@ -169,7 +177,7 @@ export class AuthService {
if (SessionStore.user.ChatData?.data) {
this.RochetChatConnectorService.connect();
this.RochetChatConnectorService.login().then((message: any) => {
console.log('Chat login',message )
console.log('Chat login', message)
SessionStore.user.RochetChatUserId = message.result.id
SessionStore.save()
@@ -293,4 +301,46 @@ export class AuthService {
await alert.present();
}
async logoutUser() {
this.headers = this.headers.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
this.opts = {
headers: this.headers,
}
let response: any;
try {
response = await this.http.delete<LoginUserRespose>(environment.apiURL + "userauthentication/Logout", this.opts).toPromise();
SessionStore.user.Authorization = "";
SessionStore.user.RefreshToken = "";
} catch (error) {
this.errorHandler.handleError(error);
this.httpErroHandle.loginHttpStatusHandle(error)
captureException(error);
} finally {
return response
}
}
refreshToken() {
return this.http
.put<any>(environment.apiURL + "UserAuthentication/RefreshToken", {
refreshToken: SessionStore.user.RefreshToken,
},)
.pipe(
tap((tokens) => {
console.log(tokens)
SessionStore.user.Authorization = tokens.Authorization;
SessionStore.user.RefreshToken = tokens.refreshToken;
}),
catchError((error) => {
this.logoutUser();
return of(false);
})
);
}
}
+1 -1
View File
@@ -371,7 +371,7 @@ export class ChatService {
async refreshtoken() {
if(this.headers && SessionStore.user.ChatData) {
this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey);
this.headers = this.headers.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
let options = {
headers: this.headers
};
+1 -1
View File
@@ -37,7 +37,7 @@ export class ContactsService {
setHeader() {
this.loggeduser = SessionStore.user;
this.headers = new HttpHeaders();;
this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey);
this.headers = this.headers.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
}
getContacts(namefilter:string): Observable<EventPerson[]>{
+14 -14
View File
@@ -99,7 +99,7 @@ export class EventsService {
this.headerSharedOficial= new HttpHeaders();;
this.headerSharedPessoal= new HttpHeaders();;
this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey);
this.headers = this.headers.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
this.usersCalendarIds = [];
this.calendarNames = {}
@@ -137,7 +137,7 @@ export class EventsService {
this.hasOwnOficial = true
this.headersMdOficial = this.headersMdOficial.set('Authorization', SessionStore.user.BasicAuthKey);
this.headersMdOficial = this.headersMdOficial.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
this.headersMdOficial = this.headersMdOficial.set('CalendarId', calendar.CalendarId);
this.headersMdOficial = this.headersMdOficial.set('CalendarRoleId', calendar.CalendarRoleId);
}
@@ -145,7 +145,7 @@ export class EventsService {
this.hasOwnPessoal = true
this.headersMdPessoal = this.headersMdPessoal.set('Authorization', SessionStore.user.BasicAuthKey);
this.headersMdPessoal = this.headersMdPessoal.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
this.headersMdPessoal = this.headersMdPessoal.set('CalendarId', calendar.CalendarId);
this.headersMdPessoal = this.headersMdPessoal.set('CalendarRoleId', calendar.CalendarRoleId);
@@ -159,7 +159,7 @@ export class EventsService {
this.hasSharedOficial = true
this.headersSharedOficial = this.headersSharedOficial.set('Authorization', SessionStore.user.BasicAuthKey);
this.headersSharedOficial = this.headersSharedOficial.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
this.headersSharedOficial = this.headersSharedOficial.set('CalendarId', sharedCalendar.CalendarId);
this.headersSharedOficial = this.headersSharedOficial.set('CalendarRoleId', sharedCalendar.CalendarRoleId);
}
@@ -167,7 +167,7 @@ export class EventsService {
this.hasSharedPessoal = true
this.headersSharedPessoal = this.headersSharedPessoal.set('Authorization', SessionStore.user.BasicAuthKey);
this.headersSharedPessoal = this.headersSharedPessoal.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
this.headersSharedPessoal = this.headersSharedPessoal.set('CalendarId', sharedCalendar.CalendarId);
this.headersSharedPessoal = this.headersSharedPessoal.set('CalendarRoleId', sharedCalendar.CalendarRoleId);
}
@@ -183,7 +183,7 @@ export class EventsService {
this.hasOwnOficial = true
this.headersPrOficial = this.headersPrOficial.set('Authorization', SessionStore.user.BasicAuthKey);
this.headersPrOficial = this.headersPrOficial.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
this.headersPrOficial = this.headersPrOficial.set('CalendarId', calendar.CalendarId);
this.headersPrOficial = this.headersPrOficial.set('CalendarRoleId', calendar.CalendarRoleId);
}
@@ -191,7 +191,7 @@ export class EventsService {
this.hasOwnPessoal = true
this.headersPrPessoal = this.headersPrPessoal.set('Authorization', SessionStore.user.BasicAuthKey);
this.headersPrPessoal = this.headersPrPessoal.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
this.headersPrPessoal = this.headersPrPessoal.set('CalendarId', calendar.CalendarId);
this.headersPrPessoal = this.headersPrPessoal.set('CalendarRoleId', calendar.CalendarRoleId);
@@ -216,7 +216,7 @@ export class EventsService {
this.hasOwnOficial = true
this.headerOwnOficial = this.headerOwnOficial.set('Authorization', SessionStore.user.BasicAuthKey);
this.headerOwnOficial = this.headerOwnOficial.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
this.headerOwnOficial = this.headerOwnOficial.set('CalendarId', calendar.CalendarId);
this.headerOwnOficial = this.headerOwnOficial.set('CalendarRoleId', calendar.CalendarRoleId);
this.headerOwnOficial = this.headerOwnOficial.set('CalendarName', calendar.CalendarName);
@@ -225,7 +225,7 @@ export class EventsService {
this.hasOwnPessoal = true
this.headerOwnPessoal = this.headerOwnPessoal.set('Authorization', SessionStore.user.BasicAuthKey);
this.headerOwnPessoal = this.headerOwnPessoal.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
this.headerOwnPessoal = this.headerOwnPessoal.set('CalendarId', calendar.CalendarId);
this.headerOwnPessoal = this.headerOwnPessoal.set('CalendarRoleId', calendar.CalendarRoleId);
this.headerOwnPessoal = this.headerOwnPessoal.set('CalendarName', calendar.CalendarName);
@@ -248,7 +248,7 @@ export class EventsService {
if (sharedCalendar.CalendarName == 'Oficial') {
this.hasSharedOficial = true
this.headerSharedOficial = this.headerSharedOficial.set('Authorization',SessionStore.user.BasicAuthKey);
this.headerSharedOficial = this.headerSharedOficial.set('Authorization','Bearer ' + SessionStore.user.Authorization);
this.headerSharedOficial = this.headerSharedOficial.set('CalendarId', sharedCalendar.CalendarId);
this.headerSharedOficial = this.headerSharedOficial.set('CalendarRoleId', sharedCalendar.CalendarRoleId);
this.headerSharedOficial = this.headerSharedOficial.set('CalendarName', sharedCalendar.CalendarName);
@@ -257,7 +257,7 @@ export class EventsService {
this.hasSharedPessoal = true
this.headerSharedPessoal = this.headerSharedPessoal.set('Authorization',SessionStore.user.BasicAuthKey);
this.headerSharedPessoal = this.headerSharedPessoal.set('Authorization','Bearer ' + SessionStore.user.Authorization);
this.headerSharedPessoal = this.headerSharedPessoal.set('CalendarId', sharedCalendar.CalendarId);
this.headerSharedPessoal = this.headerSharedPessoal.set('CalendarRoleId', sharedCalendar.CalendarRoleId);
this.headerSharedPessoal = this.headerSharedPessoal.set('CalendarName', sharedCalendar.CalendarName);
@@ -378,7 +378,7 @@ export class EventsService {
makeHeader(calendar: calendarInterface) {
let header = new HttpHeaders();;
header = header.set('Authorization', SessionStore.user.BasicAuthKey);
header = header.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
header = header.set('CalendarId', calendar.CalendarId);
header = header.set('CalendarRoleId', calendar.CalendarRoleId);
header = header.set('CalendarName', calendar.CalendarName);
@@ -616,7 +616,7 @@ export class EventsService {
for(let agendasCalendar of agendasCalendars) {
var header = new HttpHeaders();;
header = header.set('Authorization', SessionStore.user.BasicAuthKey);
header = header.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
header = header.set('CalendarId', agendasCalendar.CalendarId);
header = header.set('CalendarRoleId', agendasCalendar.CalendarRoleId);
header = header.set('CalendarName', agendasCalendar.CalendarName);
@@ -649,7 +649,7 @@ export class EventsService {
for (let sharedCalendar of SessionStore.user.SharedCalendars) {
var header = new HttpHeaders();;
header = header.set('Authorization', SessionStore.user.BasicAuthKey);
header = header.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
header = header.set('CalendarId', sharedCalendar.CalendarId);
header = header.set('CalendarRoleId', sharedCalendar.CalendarRoleId);
header = header.set('CalendarName', sharedCalendar.CalendarName);
+1 -1
View File
@@ -32,7 +32,7 @@ export class OrganicEntityService {
setHeader() {
this.loggeduser = SessionStore.user;
this.headers = new HttpHeaders();;
this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey);
this.headers = this.headers.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
}
getOrganicEntity(): Observable<OrganicEntity[]>{
+2 -2
View File
@@ -46,11 +46,11 @@ export class ProcessesService {
this.headers = new HttpHeaders();;
this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey);
this.headers = this.headers.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
this.headers2 = new HttpHeaders();;
this.headers2 = this.headers2.set('Authorization', "Bearer " + CPSession.AuthorizationJwt);
this.headers2 = this.headers2.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
}
+3 -2
View File
@@ -37,7 +37,7 @@ export class PublicationsService {
setHeader () {
this.loggeduser = SessionStore.user;
this.headers = new HttpHeaders();;
this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey);
this.headers = this.headers.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
}
GetPublicationFolderList(){
@@ -218,7 +218,8 @@ GetIdsPublicationNext(id:any){
//my last tries
CreatePublication(folderId:any,body:any){
const geturl = environment.apiURL + 'presidentialActions/'+folderId+'/posts';
console.log('body publi', body)
const geturl = environment.apiURL + 'presidentialActions/'+folderId+'/v2/posts';
let params = new HttpParams();
params = params.set("folderId", folderId);
let options = {
+1 -1
View File
@@ -38,7 +38,7 @@ export class SearchService {
setHeader() {
this.loggeduser = SessionStore.user;
this.headers = new HttpHeaders();;
this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey);
this.headers = this.headers.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
}