Browse Source

basic auth headers

kunickyd 3 years ago
parent
commit
d4b530c32c
1 changed files with 9 additions and 3 deletions
  1. 9 3
      src/app/bc-info/bc-info.service.ts

+ 9 - 3
src/app/bc-info/bc-info.service.ts

@@ -1,5 +1,5 @@
 import { Injectable } from '@angular/core';
-import { HttpClient } from '@angular/common/http';
+import { HttpClient, HttpHeaders } from '@angular/common/http';
 import {
   CommandService_v1Client as CommandService,
   QueryService_v1Client as QueryService
@@ -17,8 +17,10 @@ export class BcInfoService {
   ASSET = "testcoin#test" as const;
   ADMIN_USER = "admin@test" as const;
 
+
   commandService: CommandService;
   queryService: QueryService;
+  basicAuthHeaders: HttpHeaders;
   user = 'kunickyd@test';
   // userPrivateKey = 'ecb7f22887b0b45d1923fcd147d34bb6fd79f56eb54ed5af42c9d70c7808a9d8';
   userBalance = -1;
@@ -38,6 +40,10 @@ export class BcInfoService {
     this.queryService = new QueryService(this.IROHA_ADDRESS);
     this.getUserBalance();
     this.getPrice(this.extent).then(price => this.price = price);
+
+    this.basicAuthHeaders = new HttpHeaders();
+
+    this.basicAuthHeaders.append("Authorization", "Basic " + Buffer.from("admin:password", 'base64'));
   }
 
   async getUserBalance(): Promise<any> {
@@ -121,14 +127,14 @@ export class BcInfoService {
   }
 
   async getPrice(extent: Array<Array<number>>) : Promise<number>{
-    let response = await this.httpClient.post(this.CHAIN4ALL_SERVICE_URL + '/price', { extent: extent }).toPromise();
+    let response = await this.httpClient.post(this.CHAIN4ALL_SERVICE_URL + '/price', { extent: extent }, { headers: this.basicAuthHeaders} ).toPromise();
 
     console.debug(response);
     return response["price"];
   }
 
   async requestData(paymentHash: string, user: string) : Promise<string>{
-    let response = await this.httpClient.post(this.CHAIN4ALL_SERVICE_URL + '/buy', { txHash: paymentHash, user }).toPromise();
+    let response = await this.httpClient.post(this.CHAIN4ALL_SERVICE_URL + '/buy', { txHash: paymentHash, user }, { headers: this.basicAuthHeaders}).toPromise();
 
     console.debug(response);
     return response["dataUrl"];