Skip to content

Commit

Permalink
Include audience claim in token
Browse files Browse the repository at this point in the history
  • Loading branch information
humphd committed Feb 24, 2021
1 parent db42a9a commit 0bcb763
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/api/auth/src/token.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const jwt = require('jsonwebtoken');

const { JWT_ISSUER, JWT_AUDIENCE } = process.env;

// TODO - proper signing with RS256 keys
const secret = 'TODO - use RS256 signing...';
const issuer = process.env.JWT_ISSUER;
Expand All @@ -8,11 +10,12 @@ function createToken(audience, subject) {
// TODO - figure out all the various claims we need to use
const payload = {
// The token is issued by us (e.g., this server)
iss: process.env.JWT_ISSUER,
// It is intended for the app running at the specified origin
aud: audience,
iss: JWT_ISSUER,
// It is intended for the services running at this api origin
aud: JWT_AUDIENCE,
// The subject of this token, the user
sub: subject,
// TODO: role info (e.g., admin)
};

const options = { expiresIn: process.env.JWT_EXPIRES_IN || '1h' };
Expand Down

0 comments on commit 0bcb763

Please sign in to comment.