Skip to content
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

How to use identityClaim auth field with profile or custom:x other than user sub #7386

Closed
halilduygulu opened this issue May 23, 2021 · 7 comments
Labels
question General question

Comments

@halilduygulu
Copy link

Note: If your question is regarding the AWS Amplify Console service, please log it in the
AWS Amplify Console repository

Which Category is your question related to?
I am using graphql api via amplify schema generated appsync. I am trying to set auth field value from cognito fields, currently default version is working but i could not get custom:account_id or cognito:profile values working.
In all combinations that I tried, I got ___xamznone____ in dynamo table as owner field values.

How can I make this work as described here?
https://docs.amplify.aws/cli/graphql-transformer/auth#custom-claims

Amplify CLI Version

You can use amplify -v to check the amplify cli version on your system
$ amplify -v
4.51.0

What AWS Services are you utilizing?
auth, graphql

Provide additional details e.g. code snippets

type Account
  @model
  @auth(
    rules: [
      {
        allow: groups
        groups: ["admin"]
        operations: [create, update, delete, read]
      }
      {
        allow: owner
        ownerField: "owner"
        identityClaim: "custom:account_id"
        operations: [create, read]
      }
      {
        allow: owner
        ownerField: "owner2"
        identityClaim: "profile"
        operations: [create, read]
      }
    ]
  ) {
  id: ID!
  description: String!
  owner: String
@halilduygulu
Copy link
Author

I even tried to make authPreTokenGeneration lambda to put my custom "account_id" claim in and I can see it in browser console idToken payload. But owner in dynamo table is still ___xamznone____
I used this on schema file. both with and without provider section.

{
  allow: owner
  ownerField: "owner"
  provider: userPools
  identityField: "account_id"
  operations: [create, read] 
}

Screenshot 2021-05-23 at 16 45 13

@halilduygulu
Copy link
Author

seems like i am having this problem. different information inside idToken and accessToken
aws-amplify/amplify-data#485

@halilduygulu
Copy link
Author

I have changed the Authorization header for graphql calls to idtoken and suddenly everything is working. This should be mentioned in documentation -> custom claims section.

@dylan-westbury
Copy link

@halilduygulu yes you can receive that information using the ID token, but question remains is this secure as it's trusting the client for that information.

There has been official responses from Amplify staff about using the ID token to access it but no response on if it's secure / a secure way to manage.

@halilduygulu
Copy link
Author

Would not be the case if someone can edit a field in access or id token can also edit sub/username in any of these tokens so assume someone else's identity? I am not aware of details much, but my logical explanation is that all fields inside idtoken and accesstoken are equally secure. If this is not the case then I would like to learn which ones can be trusted.

@dylan-westbury
Copy link

Yes correct @halilduygulu

So we need to verify the token in some way.

I assume we need to do so like this https://aws.amazon.com/premiumsupport/knowledge-center/decode-verify-cognito-json-token/

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question General question
Projects
None yet
Development

No branches or pull requests

2 participants