File size: 715 Bytes
b778f8d
8c66f34
 
b778f8d
 
 
8c66f34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b778f8d
 
 
 
 
 
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
const express = require('express');
const jwt = require('jsonwebtoken');

const app = express();
const port = 4001;

const privateKey = process.env.JWT_PRIVATE_KEY;
if (!privateKey) {
  console.error('JWT_PRIVATE_KEY environment variable is required');
  process.exit(1);
}

app.get('/auth-token', (req, res) => {
  try {
    const token = jwt.sign({}, privateKey, {
      algorithm: process.env.JWT_ALGORITHM || 'RS256',
      expiresIn: '1h'
    });
    
    res.json({ token });
  } catch (error) {
    console.error('Error generating token:', error);
    res.status(500).json({ error: 'Failed to generate token' });
  }
});

app.listen(port, () => {
  console.log(`Auth service listening on port ${port}`);
});