-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
24 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |