Skip to content

Commit

Permalink
code prettified
Browse files Browse the repository at this point in the history
  • Loading branch information
varsha766 committed Jul 24, 2023
1 parent 29a9b4d commit 45a5c54
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions src/ssiApi/apiAuth/apiAuth.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
import fetch from "node-fetch"
import { IgenerateToken } from "./IAuth";
import {APIENDPOINT} from "../api-constant"
import fetch from 'node-fetch';
import { IgenerateToken } from './IAuth';
import { APIENDPOINT } from '../api-constant';
export class ApiAuth {
private apiKey: string;
constructor(apiKey) {
if (!apiKey || apiKey.trim() === "") {
throw new Error("HID-SSI_SDK:: Error: Please Provide apiKey")
}
this.apiKey = apiKey
private apiKey: string;
constructor(apiKey) {
if (!apiKey || apiKey.trim() === '') {
throw new Error('HID-SSI_SDK:: Error: Please Provide apiKey');
}
async generateAccessToken(): Promise<IgenerateToken> {
const studioApiUrl = `${APIENDPOINT.STUDIO_API_BASE_URL}${APIENDPOINT.AUTH}`
const headers = {
"X-Api-Secret-Key": this.apiKey,
}
const requestOptions = {
method: "POST",
headers,
}
const response = await fetch(studioApiUrl, requestOptions)
const authToken = await response.json()
if (!response.ok) {
throw new Error(`HID-SSI-SDK:: Error: ${authToken.message}`)
}
return authToken


this.apiKey = apiKey;
}
async generateAccessToken(): Promise<IgenerateToken> {
const studioApiUrl = `${APIENDPOINT.STUDIO_API_BASE_URL}${APIENDPOINT.AUTH}`;
const headers = {
'X-Api-Secret-Key': this.apiKey,
};
const requestOptions = {
method: 'POST',
headers,
};
const response = await fetch(studioApiUrl, requestOptions);
const authToken = await response.json();
if (!response.ok) {
throw new Error(`HID-SSI-SDK:: Error: ${authToken.message}`);
}
return authToken;
}
}

0 comments on commit 45a5c54

Please sign in to comment.