This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
70 lines (55 loc) · 1.72 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import "./taquito/listener.js";
//import {getToken} from "./taquito/listener.js";
import { createRequire } from "module";
//import cors from 'cors';
const require = createRequire(import.meta.url);
const express = require('express');
const http = require('http');
const WebSocket = require('ws');
//export
const app = express();
const server = http.createServer(app);
const wss = new WebSocket.Server({ server });
const port = 3005;
app.use(express.json());
//app.use(cors());
app.post('/webhook', (req, res) => {
console.log('Webhook received:', req.body);
wss.clients.forEach(client => {
if (client.readyState === WebSocket.OPEN) {
client.send(JSON.stringify(req.body));
}
});
res.sendStatus(200);
});
server.listen(port, () => console.log('Server listening on port ' + port + '.'));
const axios = require('axios');
const qs = require('qs');
export let access_token = '';
export let refresh_token = '';
let data = qs.stringify({
'grant_type': 'password',
'username': process.env.keycloak_user_username,
'password': process.env.keycloak_user_password,
'client_id': process.env.client_id,
'scope': 'openid',
'client_secret': process.env.client_secret
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: process.env.keycloak_protocol +'://'+ process.env.keycloak_address + '/realms/gaia-x/protocol/openid-connect/token',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data : data
};
axios.request(config)
.then((response) => {
access_token = response.data.access_token;
refresh_token = response.data.refresh_token;
console.log(access_token);
})
.catch((error) => {
console.log(error);
});