Skip to content

@auth with groupsField and groupClaim not working in V2 transformer #110

@spc16670

Description

@spc16670

Before opening, please confirm:

  • I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

14

Amplify CLI Version

7.6.20

What operating system are you using?

Windows

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No manual changes made

Amplify Categories

auth, api

Amplify Commands

add

Describe the bug

I upgraded from GraphQL transformer version: 1 to 2, updated my schema, deployed the changes and I see getting awful lot of 'Unauthorized' responses completely breaking my app in many places.

This is my model (one of them):

type Client @model
  @auth(rules: [
    { allow: groups, groups: ["Root"] },
    { allow: groups, groups: ["Partner"], operations: [create] },
    { allow: groups, groupsField: "id", groupClaim: "client:owner" },
    { allow: groups, groupsField: "id", groupClaim: "client:custodian", operations: [read, update] },
    { allow: groups, groupsField: "id", groupClaim: "client:user", operations: [read] }
  ]) 
{
  id: ID! @primaryKey
  name: String!
  createdAt: AWSDateTime!
  updatedAt: AWSDateTime
}

I configure amplify to send ID token to the server

Amplify.configure({
  API: {
    graphql_headers: async () => {
      const session = await Auth.currentSession();
      const idToken = session.getIdToken();
      return {
        Authorization: idToken.getJwtToken()
      };
    }
  },
});

My token has:

client:custodian: "[\"GVP8919\"]"

There is the corresponding entry in the database with that ID.

And yet, the list operation does not return any results 😦

{"data":{"listClients":{"__typename":"ModelClientConnection","items":[],"nextToken":null}}}

I am using Cognito user pools for authentication.

Expected behavior

@auth with groupsField and groupClaim works the way it used to

Reproduction steps

  1. Update to V2
  2. Create a model as described below
  3. Login as user with Cognito Id token with custom claim as shown above
  4. Attempt a list on the model

GraphQL schema(s)

# Put schemas below this line


Log output

# Put your logs below this line


Additional information

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions