Include cognito client ID in Lambda env when a lambda resource is allowed in defineAuth #2357
Labels
auth
Issue pertaining to Amplify Auth
feature-request
New feature or request
function
Issue pertaining to Amplify Function
Environment information
Describe the feature
When using the
access
field ofdefineAuth
to provide bestow userPool permissions to a lambda, only theuserPool ID (
env.AMPLIFY_AUTH_USERPOOL_ID
) is added to the environment variables by default. I propose that the userPool client ID should be included as well, for example inenv.AMPLIFY_AUTH_USERPOOL_CLIENT_ID
Use case
My use case for this feature would be to more easily use the CognitoJwtVerifier package within a custom authorizer lambda. My team uses this custom authorizer to resolve fine-grained permissions defined in a userInfo table that is associated with our cognito users.
The JWT verification step ensures that the token is valid and to obtain the claims from the access key. One such claim is the user
sub
which is used to obtain the full userInfo record. From there the permissions are resolved based on the graphQL and the permissions object.The CognitoJwtVerifier package requires the cognito client ID. Currently this can be done within the backend configuration by adding an environment variable after
defineBackend
is called (or by a bootstrapping step involving Amplify secrets, as was required to avoid circular dependencies within the cfn stacks, though this is no longer necessary). By addingenv.AMPLIFY_AUTH_USERPOOL_ID
to the lambda env by default, the need for workarounds goes away entirelyThe text was updated successfully, but these errors were encountered: