-
Couldn't load subscription status.
- Fork 89
Added cognito group parsing #3271
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
base: main
Are you sure you want to change the base?
Added cognito group parsing #3271
Conversation
- When resolving a child model from a parent model using the `@auth` directive to specify a dynamic group where the `groupsField` referenced is the same field as the `@index` directive being used by the parent model's `@hasMany` directive, an error occurs because the VTL template does not correctly parse the information from the context `indentity.claims.cognito:groups` - This commit adds correct parsing to the VTL generated in this circumstance - A test has been added to check the content of the VTL auth file generated - This change has been tested manually within an existing production project that I manage and has fixed an issue I was having with the authorisation. - No linting fixes have been applied to the edited `query` file because I did not wish to pollute the PR with other changes
|
Additional context: The current code generates a VTL file that does not utilise the ## [Start] Authorization Steps. **
$util.qr($ctx.stash.put(\\"hasAuth\\", true))
#set( $isAuthorized = false )
#if( $util.authType() == \\"User Pool Authorization\\" )
#if( !$isAuthorized )
#set( $primaryRole0 = $util.defaultIfNull($ctx.identity.claims.get(\\"cognito:groups\\"), null) )
#if( !$util.isNull($primaryRole0) )
#set( $ownerClaimsList0 = [] ) ## <--- here is the problem
#if( (!$util.isNull($ctx.source.id)) && (($ctx.source.id == $primaryRole0) || $ownerClaimsList0.contains($ctx.source.id)) )
#set( $isAuthorized = true )
$util.qr($ctx.stash.put(\\"authFilter\\", null))
#else
#if( !$isAuthorized && $util.isNull($ctx.stash.authFilter) )
$util.qr($ctx.stash.connectionAttributes.put(\\"id\\", $primaryRole0))
#set( $isAuthorized = true )
#end
#end
#end
#end
#end
#if( !$isAuthorized && $util.isNull($ctx.stash.authFilter) )
$util.unauthorized()
#end
$util.toJson({\\"version\\":\\"2018-05-29\\",\\"payload\\":{}})
## [End] Authorization Steps. **You will see that the variable It feels like the The changes in this PR parse the "## [Start] Authorization Steps. **
$util.qr($ctx.stash.put(\\"hasAuth\\", true))
#set( $isAuthorized = false )
#if( $util.authType() == \\"User Pool Authorization\\" )
#if( !$isAuthorized )
#set( $primaryRole0 = $util.defaultIfNull($ctx.identity.claims.get(\\"cognito:groups\\"), null) )
#if( !$util.isNull($primaryRole0) )
#set( $ownerClaimsList0 = [] )
## START OF CHANGE
#if( $util.isString($primaryRole0) )
#if( $util.isList($util.parseJson($primaryRole0)) )
#set( $ownerClaimsList0 = $util.parseJson($primaryRole0) )
#else
#set( $ownerClaimsList0 = [$primaryRole0] )
#end
#else
#set( $ownerClaimsList0 = $primaryRole0 )
#end
## END OF CHANGE
#if( (!$util.isNull($ctx.source.id)) && (($ctx.source.id == $primaryRole0) || $ownerClaimsList0.contains($ctx.source.id)) )
#set( $isAuthorized = true )
$util.qr($ctx.stash.put(\\"authFilter\\", null))
#else
#if( !$isAuthorized && $util.isNull($ctx.stash.authFilter) )
$util.qr($ctx.stash.connectionAttributes.put(\\"id\\", $primaryRole0))
#set( $isAuthorized = true )
#end
#end
#end
#end
#end
#if( !$isAuthorized && $util.isNull($ctx.stash.authFilter) )
$util.unauthorized()
#end
$util.toJson({\\"version\\":\\"2018-05-29\\",\\"payload\\":{}})
## [End] Authorization Steps. **" |
|
@AnilMaktala @phani-srikar you are both assigned to the ticket that I believe this ticket fixes. Could you please review this PR or assign it to the relevant person? |
|
@ShadowCat567 Any chance you can approve this? I've seen you approving other PRs recently. |
Description of changes
@authdirective to specify a dynamic group where thegroupsFieldreferenced is the same field as the@indexdirective being used by the parent model's@hasManydirective, an error occurs because the VTL template does not correctly parse the information from the contextindentity.claims.cognito:groupsqueryfile because I did not wish to pollute the PR with other changesCDK / CloudFormation Parameters Changed
Issue #, if available
Description of how you validated changes
Checklist
yarn testpassesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.