-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithubapp.js
More file actions
40 lines (32 loc) · 902 Bytes
/
githubapp.js
File metadata and controls
40 lines (32 loc) · 902 Bytes
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
const jwt = require('jsonwebtoken');
const axios = require('axios');
const fs = require("fs");
require('dotenv').config()
const privateKey = fs.readFileSync("private_key.pem","utf8");
const appId = process.env.APP_ID
const installation_id=process.env.INSTALLATION_ID
const header = {
alg: "RS256",
typ: "JWT"
};
const payload = {
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + (10 * 60),
iss: process.env.APP_ID,
};
const token = jwt.sign(payload, privateKey, { algorithm: 'RS256', header: header } );
const headers = {
Authorization: `Bearer ${token}`,
'User-Agent': 'SiyaaJhawar',
};
axios
.post('https://api.github.com/repos/SiyaaJhawar/learning-/issues', {
title: 'Hi',
body: 'This is a sample code',
}, { headers })
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.error(error);
});