Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Commit

Permalink
changed all uses of SECRET -> JWT_SECRET
Browse files Browse the repository at this point in the history
  • Loading branch information
joelazwar authored and menghif committed Feb 17, 2022
1 parent 743ef81 commit 1e6f149
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ npm install --save @senecacdot/satellite

The following JWT verification values are required:

- `SECRET`: the secret used for JWT token verification
- `JWT_SECRET`: the secret used for JWT token verification
- `JWT_AUDIENCE`: the audience (aud) claim expected in JWT token verification
- `JWT_ISSUER`: the issuer (iss) claim expected in JWT token verification

Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Define the env variables our code expects
process.env = Object.assign(process.env, {
SECRET: 'test-secret',
JWT_SECRET: 'your-super-secret-jwt-token-with-at-least-32-characters-long',
JWT_AUDIENCE: 'http://localhost',
JWT_ISSUER: 'http://localhost',
JWT_EXPIRES_IN: '1h',
Expand Down
2 changes: 1 addition & 1 deletion src/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const logger = require('./logger');
// We expect to get JWT config details via the env.
function isAuthenticated() {
return jwt({
secret: process.env.SECRET,
secret: process.env.JWT_SECRET,
audience: process.env.JWT_AUDIENCE,
issuer: process.env.JWT_ISSUER,
// TODO: proper public/private key token signing
Expand Down
4 changes: 2 additions & 2 deletions src/service-token.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const jwt = require('jsonwebtoken');

const { JWT_ISSUER, JWT_AUDIENCE, SECRET } = process.env;
const { JWT_ISSUER, JWT_AUDIENCE, JWT_SECRET } = process.env;

/**
* Create a short-lived service-to-service JWT, useful for authorizing
Expand All @@ -16,7 +16,7 @@ function createServiceToken() {
roles: ['service'],
};

return jwt.sign(payload, SECRET, { expiresIn: '5m' });
return jwt.sign(payload, JWT_SECRET, { expiresIn: '5m' });
}

module.exports = createServiceToken;
8 changes: 4 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const {
fetch,
} = require('./src');
const { errors } = require('@elastic/elasticsearch');
const { JWT_EXPIRES_IN, JWT_ISSUER, JWT_AUDIENCE, SECRET } = process.env;
const { JWT_EXPIRES_IN, JWT_ISSUER, JWT_AUDIENCE, JWT_SECRET } = process.env;

const createSatelliteInstance = (options) => {
const service = new Satellite(options || { name: 'test' });
Expand Down Expand Up @@ -50,7 +50,7 @@ const createToken = ({ sub, roles }) => {
payload = { ...payload, roles };
}

return jwt.sign(payload, SECRET, { expiresIn: JWT_EXPIRES_IN });
return jwt.sign(payload, JWT_SECRET, { expiresIn: JWT_EXPIRES_IN });
};

describe('Satellite()', () => {
Expand Down Expand Up @@ -450,7 +450,7 @@ describe('Satellite()', () => {
name: 'test',
});
const token = createToken({ sub: 'admin@email.com' });
const decoded = jwt.verify(token, SECRET);
const decoded = jwt.verify(token, JWT_SECRET);

const router = service.router;
router.get('/public', (req, res) => res.json({ hello: 'public' }));
Expand Down Expand Up @@ -905,7 +905,7 @@ describe('Create Error tests for Satellite', () => {
describe('createServiceToken()', () => {
test('should create a service token', () => {
const token = createServiceToken();
const decoded = jwt.verify(token, SECRET);
const decoded = jwt.verify(token, JWT_SECRET);

expect(decoded.sub).toEqual('telescope-service');
expect(Array.isArray(decoded.roles)).toBe(true);
Expand Down

0 comments on commit 1e6f149

Please sign in to comment.