Authentication support for cdt
[appc/cdt.git] / src / app / shared / services / httpUtil / http-util.service.ts
index fc9c327..40c1518 100644 (file)
@@ -1,7 +1,7 @@
 /*
 ============LICENSE_START==========================================
 ===================================================================
-Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
 ===================================================================
 
 Unless otherwise specified, all software contained herein is licensed
@@ -54,5 +54,28 @@ export class HttpUtilService {
             .post(req.url, req.data, this.options)
             .map((res: Response) => res.json())
     }
+    
+    postWithAuth(req) {
+        var authString = sessionStorage['auth'];
+        if(authString === undefined || authString === null || authString.length === 0){
+            this.options = new RequestOptions({
+                headers: new Headers({
+                    'Content-Type': 'application/json'
+                })
+            });
+        } else {
+            this.options = new RequestOptions({
+                headers: new Headers({
+                    'Content-Type': 'application/json',
+                    'Authorization': 'Basic ' + authString
+                })
+            });
+        }
+        
+        return this
+        .http
+        .post(req.url, req.data, this.options)
+        .map((res: Response) => res.json())
+    }
 
 }