From f00892d8151900894baf63cf284331904bb79316 Mon Sep 17 00:00:00 2001
From: FORESTIER Fabien <fabien.forestier@soprasteria.com>
Date: Thu, 6 Jun 2019 15:49:32 +0200
Subject: [PATCH] Add withCredential option on some http calls

---
 src/app/services/format.service.ts   |  6 +++---
 src/app/services/resource.service.ts | 19 +++++++++++++------
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/app/services/format.service.ts b/src/app/services/format.service.ts
index 722f25a..bd2b12a 100644
--- a/src/app/services/format.service.ts
+++ b/src/app/services/format.service.ts
@@ -58,18 +58,18 @@ export class FormatService {
   }
 
   delete(id) {
-    return this._httpClient.delete(this.formatServiceUrl + id);
+    return this._httpClient.delete(this.formatServiceUrl + id, { withCredentials: true });
   }
 
   replaceOrCreate(data): Observable<Format> {
     if (data.id) {
-      return this._httpClient.put<IFormat>(this.formatServiceUrl + data.id, data).pipe(
+      return this._httpClient.put<IFormat>(this.formatServiceUrl + data.id, data, { withCredentials: true }).pipe(
         map((response) => {
           return new Format(response);
         }),
       );
     }
-    return this._httpClient.post<IFormat>(this.formatServiceUrl, data).pipe(
+    return this._httpClient.post<IFormat>(this.formatServiceUrl, data, { withCredentials: true }).pipe(
       map((response) => {
         return new Format(response);
       }),
diff --git a/src/app/services/resource.service.ts b/src/app/services/resource.service.ts
index b598eb3..a46b3d3 100644
--- a/src/app/services/resource.service.ts
+++ b/src/app/services/resource.service.ts
@@ -52,18 +52,18 @@ export class ResourceService {
   }
 
   delete(id) {
-    return this._httpClient.delete(this.resourceServiceUrl + id);
+    return this._httpClient.delete(this.resourceServiceUrl + id, { withCredentials: true });
   }
 
   replaceOrCreate(data): Observable<Resource> {
     if (data.id) {
-      return this._httpClient.put<IResource>(this.resourceServiceUrl + data.id, data).pipe(
+      return this._httpClient.put<IResource>(this.resourceServiceUrl + data.id, data, { withCredentials: true }).pipe(
         map((response) => {
           return new Resource(response);
         }),
       );
     }
-    return this._httpClient.post<IResource>(this.resourceServiceUrl, data).pipe(
+    return this._httpClient.post<IResource>(this.resourceServiceUrl, data, { withCredentials: true }).pipe(
       map((response) => {
         return new Resource(response);
       }),
@@ -73,7 +73,7 @@ export class ResourceService {
   createResourceFormats(resourceId: string, resourceFormats: IResourceFormat[]): Observable<IResourceFormat> {
     return from(resourceFormats).pipe(
       concatMap((rf) => {
-        return this._httpClient.post<IResourceFormat>(`${this.resourceServiceUrl}${resourceId}/formats`, rf);
+        return this._httpClient.post<IResourceFormat>(`${this.resourceServiceUrl}${resourceId}/formats`, rf, { withCredentials: true });
       }),
     );
   }
@@ -81,7 +81,11 @@ export class ResourceService {
   updateResourceFormats(resourceId: string, resourceFormats: IResourceFormat[]) {
     return from(resourceFormats).pipe(
       concatMap((rf) => {
-        return this._httpClient.put<IResourceFormat>(`${this.resourceServiceUrl}${resourceId}/formats/${rf.id}`, rf);
+        return this._httpClient.put<IResourceFormat>(
+          `${this.resourceServiceUrl}${resourceId}/formats/${rf.id}`,
+          rf,
+          { withCredentials: true },
+        );
       }),
     );
   }
@@ -89,7 +93,10 @@ export class ResourceService {
   deleteResourceFormats(resourceId: string, resourceFormatsId: string[]) {
     return from(resourceFormatsId).pipe(
       concatMap((rfId) => {
-        return this._httpClient.delete<IResourceFormat>(`${this.resourceServiceUrl}${resourceId}/formats/${rfId}`);
+        return this._httpClient.delete<IResourceFormat>(
+          `${this.resourceServiceUrl}${resourceId}/formats/${rfId}`,
+          { withCredentials: true },
+        );
       }),
     );
   }
-- 
GitLab