Quantcast
Viewing all articles
Browse latest Browse all 1553

BWS Web API bio PhotoVerify

I'm using Nestjs to access the PhotoVerify API of the BioID Developer. This is the documentation: https://developer.bioid.com/classicbws/bwsreference/webapi/photoverify

This is my bio-id.service.ts file.

import { Injectable, HttpException, Logger } from '@nestjs/common';import { HttpService } from '@nestjs/axios';import { AxiosResponse } from 'axios';import { firstValueFrom } from 'rxjs';import axios from 'axios';@Injectable()export class BioIdService {  private readonly endpoint = 'https://bws.bioid.com/extension/photoverify';   private readonly appId = 'f57e0ab5-e4e1-41e3-8788-3ddc794f7c95';  private readonly appSecret = 'k5ookOqYcZfYv7Bv1wSEGNzs';  constructor(private readonly httpService: HttpService) {}  // Función para descargar y convertir una imagen a una cadena Base64  private async encodeImageFromUrlToBase64(imageUrl: string): Promise<string> {    try {      Logger.log(`Downloading image from ${imageUrl}`, 'BioIdService/encodeImageFromUrlToBase64');      const response = await axios.get(imageUrl, { responseType: 'arraybuffer' });      const base64 = Buffer.from(response.data, 'binary').toString('base64');      const mimeType = response.headers['content-type'];      return `data:${mimeType};base64,${base64}`;    } catch (error) {      Logger.error(`Error downloading image from ${imageUrl}: ${error.message}`, 'BioIdService/encodeImageFromUrlToBase64');      throw new HttpException(`Error downloading image from ${imageUrl}`, 500);    }  }  async photoVerify(accuracy: number, liveImageUrl: string, idPhotoUrl: string): Promise<boolean> {    const authHeader = `Basic ${Buffer.from(`${this.appId}:${this.appSecret}`).toString('base64')}`;    Logger.log(`Auth header: ${authHeader}`, 'BioIdService/photoVerify')    const headers = {      Authorization: authHeader,'Content-Type': 'application/json',    };    const liveImage = await this.encodeImageFromUrlToBase64(liveImageUrl);    const idPhoto = await this.encodeImageFromUrlToBase64(idPhotoUrl);    const body = {      liveimage: liveImage,      idphoto: idPhoto,    };    try {      Logger.log(`Sending request to PhotoVerify service with accuracy ${accuracy}`, 'BioIdService/photoVerify');      const response: AxiosResponse = await firstValueFrom(        this.httpService.post(`${this.endpoint}?accuracy=${accuracy}`, body, { headers }),      );      return response.data === true;    } catch (error) {      Logger.error(`Error connecting to PhotoVerify service: ${error.response?.data || error.message}`, 'BioIdService/photoVerify');      throw new HttpException(error.message || 'Error connecting to PhotoVerify service', error.response?.status || 500);    }  }}

I obtained the appId and appSecret credentials from https://bwsportal.bioid.com/

However, the API is returning a 401 which indicates that I'm not authorized. I would like to know if the way I'm creating the access basic token is correct.

this is the Request URLhttp://localhost:4000/v1/bioId/photoverify?accuracy=3&liveImageUrl=https%3A%2F%2Fres.cloudinary.com%2Fsafyride%2Fimage%2Fupload%2Fv1716060705%2Fusers%2F0ab44df9-8393-4b63-a64f-8b8289a50867%2FFace.jpg&idPhotoUrl=https%3A%2F%2Fres.cloudinary.com%2Fsafyride%2Fimage%2Fupload%2Fv1716060706%2Fusers%2F0ab44df9-8393-4b63-a64f-8b8289a50867%2FNipFront.jpg

this what I´m getting: Error: Unauthorized

Response body{"statusCode": 401,"message": "Request failed with status code 401"}

this is what i expected returns the OK HTTP status code 200


Viewing all articles
Browse latest Browse all 1553

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>