-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (29 loc) · 859 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const axios = require("axios");
module.exports = class BogToken {
constructor(bogClientId, bogClientSecret) {
this.clientId = bogClientId;
this.clientSecret = bogClientSecret;
}
async getBOGToken() {
try {
const basicAuth = Buffer.from(
`${this.clientId}:${this.clientSecret}`,
"utf-8"
).toString("base64");
const Authorization = "Basic " + basicAuth;
const response = await axios.post(
"https://oauth2.bog.ge/auth/realms/bog/protocol/openid-connect/token",
new URLSearchParams({ grant_type: "client_credentials" }),
{
headers: {
Authorization,
"Content-Type": "application/x-www-form-urlencoded",
},
}
);
return [response.data.access_token, null];
} catch (error) {
return [null, error];
}
}
};