-
-
Notifications
You must be signed in to change notification settings - Fork 570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(postgraphql): extract pgRole from arbitrary JWT path #480
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dd36d4e
feat(postgraphql) Added an option to allow the pgRole to be extracted…
a3e2fff
Merge branch 'master' into master
angelosarto 82bfa6e
Merge remote-tracking branch 'upstream/master'
78d3f8c
feat(postgraphql) Added an option to allow the pgRole to be extracted…
44e9c5b
Merge branch 'master' of github.com:angelosarto/postgraphql
fb7a845
feat(postgraphql) Added an option to allow the pgRole to be extracted…
2dab361
feat(postgraphql) Added an option to allow the pgRole to be extracted…
d6993c3
feat(postgraphql) Added an option to allow the pgRole to be extracted…
7f446d1
feat(postgraphql) Added an option to allow the pgRole to be extracted…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,13 +36,15 @@ export default async function withPostGraphQLContext( | |
jwtToken, | ||
jwtSecret, | ||
jwtAudiences = ['postgraphql'], | ||
jwtRole = ['role'], | ||
pgDefaultRole, | ||
pgSettings, | ||
}: { | ||
pgPool: Pool, | ||
jwtToken?: string, | ||
jwtSecret?: string, | ||
jwtAudiences?: Array<string>, | ||
jwtRole?: Array<string>, | ||
pgDefaultRole?: string, | ||
pgSettings?: { [key: string]: mixed }, | ||
}, | ||
|
@@ -64,6 +66,7 @@ export default async function withPostGraphQLContext( | |
jwtToken, | ||
jwtSecret, | ||
jwtAudiences, | ||
jwtRole, | ||
pgDefaultRole, | ||
pgSettings, | ||
}) | ||
|
@@ -95,13 +98,15 @@ async function setupPgClientTransaction ({ | |
jwtToken, | ||
jwtSecret, | ||
jwtAudiences, | ||
jwtRole, | ||
pgDefaultRole, | ||
pgSettings, | ||
}: { | ||
pgClient: Client, | ||
jwtToken?: string, | ||
jwtSecret?: string, | ||
jwtAudiences?: Array<string>, | ||
jwtRole?: Array<string>, | ||
pgDefaultRole?: string, | ||
pgSettings?: { [key: string]: mixed }, | ||
}): Promise<string | undefined> { | ||
|
@@ -124,7 +129,7 @@ async function setupPgClientTransaction ({ | |
audience: jwtAudiences, | ||
}) | ||
|
||
const roleClaim = jwtClaims['role'] | ||
const roleClaim = getPath(jwtClaims, jwtRole) | ||
|
||
// If there is a `role` property in the claims, use that instead of our | ||
// default role. | ||
|
@@ -227,4 +232,22 @@ function debugPgClient (pgClient: Client): Client { | |
|
||
return pgClient | ||
} | ||
|
||
/** | ||
* Safely extract a nested object or undefined where inObject is any object and path is | ||
* an array of indexes into an object | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* | ||
* @private | ||
*/ | ||
function getPath(inObject: any, path: any): any { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe something like |
||
let object = inObject | ||
// From https://github.com/lodash/lodash/blob/master/.internal/baseGet.js | ||
let index = 0 | ||
const length = path.length | ||
|
||
while (object && index < length) { | ||
object = object[path[index++]] | ||
} | ||
return (index && index === length) ? object : undefined | ||
} | ||
// tslint:enable no-any |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if none is provided
< missing capital following fullstop