From 80443762d64e889177be3b66634749ff8d6cdcf4 Mon Sep 17 00:00:00 2001 From: David Vo Date: Sat, 12 Oct 2019 18:16:58 +1100 Subject: [PATCH] Add JWT audience --- config.example.json | 1 + src/core/auth/auth.module.ts | 7 +++++-- src/core/auth/jwt.strategy.ts | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/config.example.json b/config.example.json index 399045c..6cd0dba 100644 --- a/config.example.json +++ b/config.example.json @@ -4,6 +4,7 @@ "pass": "password" }, "jwt": { + "audience": "https://api.syncs.org.au", "secret": "supersecret", "duration": "6h" }, diff --git a/src/core/auth/auth.module.ts b/src/core/auth/auth.module.ts index 6ba85a1..75b1c7a 100644 --- a/src/core/auth/auth.module.ts +++ b/src/core/auth/auth.module.ts @@ -14,8 +14,11 @@ const config = require("../../../config.json"); PassportModule, JwtModule.register({ secret: config.jwt.secret, - signOptions: { expiresIn: config.jwt.duration }, - }) + signOptions: { + audience: config.jwt.audience, + expiresIn: config.jwt.duration, + }, + }), ], exports: [AuthService], providers: [AuthService, LocalStrategy, JwtStrategy], diff --git a/src/core/auth/jwt.strategy.ts b/src/core/auth/jwt.strategy.ts index dcc2ea8..d72c667 100644 --- a/src/core/auth/jwt.strategy.ts +++ b/src/core/auth/jwt.strategy.ts @@ -10,6 +10,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) { jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), ignoreExpiration: false, secretOrKey: config.jwt.secret, + audience: config.jwt.audience, }); }