|
1 | 1 | import { webAppUrl } from "../config";
|
2 |
| -import { get } from "axios"; |
| 2 | +import Axios from "axios"; |
3 | 3 | import * as jwt from "jsonwebtoken";
|
4 | 4 | import { log } from "../logger";
|
5 | 5 |
|
6 | 6 | let url = webAppUrl + "/api/public_key";
|
7 | 7 |
|
8 | 8 | function keyOk(resp) {
|
9 |
| - log("Downloaded certificate from " + url); |
10 |
| - return new Buffer(resp.data, 'utf8'); |
| 9 | + log("Downloaded certificate from " + url); |
| 10 | + return new Buffer(resp.data, 'utf8'); |
11 | 11 | }
|
12 | 12 |
|
13 | 13 | function no(error) {
|
14 |
| - log("Unable to download certificate from " + url); |
15 |
| - log("Is the FarmBot API running?"); |
16 |
| - process.exit(); |
| 14 | + log("Unable to download certificate from " + url); |
| 15 | + log("Is the FarmBot API running?"); |
| 16 | + process.exit(); |
17 | 17 | }
|
18 | 18 |
|
19 |
| -let getCertificate = get(url).then(keyOk, no); |
| 19 | +let getCertificate = Axios.get(url).then(keyOk, no); |
20 | 20 |
|
21 |
| -export default function verifyToken(token) { |
22 |
| - function no(error) { |
23 |
| - log("Unable to verify token " + url); |
24 |
| - } |
| 21 | +export function verifyToken(token) { |
| 22 | + function no(error) { |
| 23 | + log("Unable to verify token " + url); |
| 24 | + } |
25 | 25 |
|
26 |
| - function ok(cert) { |
27 |
| - log("Did fetch certifiacte. Will verify token with certificate."); |
28 |
| - return jwt.verify(token, cert, { algorithms: ['RS256'] }); |
29 |
| - } |
30 |
| - log("Will fetch certificate...") |
31 |
| - return getCertificate.then(ok, no) |
| 26 | + function ok(cert) { |
| 27 | + log("Did fetch certifiacte. Will verify token with certificate."); |
| 28 | + return jwt.verify(token, cert, { algorithms: ['RS256'] }); |
| 29 | + } |
| 30 | + log("Will fetch certificate...") |
| 31 | + return getCertificate.then(ok, no) |
32 | 32 | };
|
0 commit comments