forked from rawanbardaweel/Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (33 loc) · 1012 Bytes
/
server.js
File metadata and controls
37 lines (33 loc) · 1012 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
'use strict';
const express=require('express');
const app=express();
const cors=require('cors');
const jwt=require('jsonwebtoken');
const jwksClient=require('jwks-rsa');
require('dotenv').config();
app.use(cors());
const client = jwksClient({
// this url comes from your app on the auth0 dashboard
jwksUri: `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`
});
// this is a ready to use function
const getKey=(header, callback)=>{
client.getSigningKey(header.kid, function(err, key) {
const signingKey = key.publicKey || key.rsaPublicKey;
callback(null, signingKey);
});
}
// 'Bearer ;alsdkj;laskd;lkasd;lkl'
app.get('/authorize',(req,res)=>{
const token=req.headers.authorization.split(' ')[1];
jwt.verify(token,getKey,{},(err,user)=>{
if(err){
res.send('invalid token');
}
res.send(user)
})
res.send(token);
});
app.listen(process.env.PORT,()=>{
console.log(`listening to port: ${process.env.PORT}`);
})