Skip to content

Commit

Permalink
feat(jwt): add support for jsonwebtoken.sign options (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
speller authored and benjie committed Aug 6, 2019
1 parent 4ddc47b commit 7825f25
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/graphile-build-pg/src/plugins/PgJWTPlugin.js
Expand Up @@ -4,7 +4,7 @@ import { sign as signJwt } from "jsonwebtoken";

export default (function PgJWTPlugin(
builder,
{ pgJwtTypeIdentifier, pgJwtSecret }
{ pgJwtTypeIdentifier, pgJwtSecret, pgJwtSignOptions }
) {
builder.hook(
"init",
Expand Down Expand Up @@ -78,17 +78,18 @@ export default (function PgJWTPlugin(
pgJwtSecret,
Object.assign(
{},
token.aud
pgJwtSignOptions,
token.aud || (pgJwtSignOptions && pgJwtSignOptions.audience)
? null
: {
audience: "postgraphile",
},
token.iss
token.iss || (pgJwtSignOptions && pgJwtSignOptions.issuer)
? null
: {
issuer: "postgraphile",
},
token.exp
token.exp || (pgJwtSignOptions && pgJwtSignOptions.expiresIn)
? null
: {
expiresIn: "1 day",
Expand Down
4 changes: 4 additions & 0 deletions packages/postgraphile-core/src/index.ts
Expand Up @@ -20,6 +20,7 @@ import {
formatSQLForDebugging,
} from "graphile-build-pg";
import { Pool, PoolClient } from "pg";
import { SignOptions } from "jsonwebtoken";

export {
Plugin,
Expand Down Expand Up @@ -73,6 +74,7 @@ export interface PostGraphileCoreOptions {
skipPlugins?: Array<Plugin>;
jwtPgTypeIdentifier?: string;
jwtSecret?: string;
jwtSignOptions?: SignOptions;
/**
* @deprecated UNSUPPORTED! Use an inflector plugin instead.
*/
Expand Down Expand Up @@ -201,6 +203,7 @@ const getPostGraphileBuilder = async (
skipPlugins = [],
jwtPgTypeIdentifier,
jwtSecret,
jwtSignOptions,
disableDefaultMutations,
graphileBuildOptions,
graphqlBuildOptions, // DEPRECATED!
Expand Down Expand Up @@ -368,6 +371,7 @@ const getPostGraphileBuilder = async (
nodeIdFieldName: nodeIdFieldName || (classicIds ? "id" : "nodeId"),
pgJwtTypeIdentifier: jwtPgTypeIdentifier,
pgJwtSecret: jwtSecret,
pgJwtSignOptions: jwtSignOptions,
pgDisableDefaultMutations: disableDefaultMutations,
pgViewUniqueKey: viewUniqueKey,
pgEnableTags: enableTags,
Expand Down

0 comments on commit 7825f25

Please sign in to comment.