-
Notifications
You must be signed in to change notification settings - Fork 117
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
Combining API KEY authorization "read" and "listen" access doesn't work #2770
Comments
Hi @gpavlov2016 👋 it seems that this may be intended behavior. When I try to deploy the same schema, I get this error:
|
Thanks for looking into this @chrisbonifacio. My scenario is:
When I try with |
hi @gpavlov2016 the Another common reason we see why subscription "come across as failing" is because the GraphQL selection set of the mutation must include all the fields that the subscriber is looking for. Can you share the code where you trigger the mutation and the Android code where you listen to the subscription? |
The subscription fails at the authentication stage before I even try to do any mutation, and based on the logs it's trying to use Cognito for authentication. Query operation with the same code succeeds.
And here is how the model is defined in the Android client (autogenerated from using amplify config file).
And this is the code that calls the subscribe method:
For reference, this is the query call that works with the same settings:
Error message from logcat:
|
Hi @gpavlov2016 because the issue seems to be with auth in the android sdk, I am transferring this issue over to the amplify/android repo for better support. |
Hi @gpavlov2016, this is amplify android, our team will take a look into the issue |
Hey @gpavlov2016 thanks for your patience. I'll take a look into this. |
Thanks @mattcreaser ! The title is probably need to change since it's not about the access permissions in amplify-js but about support of api key auth in android based on the triage of the js team |
Definitely looks like the issue would be in the Multi-auth subscription operation, but we will know more after we investigate. |
Hi @gpavlov2016. I've been looking into this issue and have some updates to share. The reason Amplify is trying to use the user pool is because that is the default authorization mode for your API. Normally you would get around this by choosing a new auth mode for your request. The current way to do this for Gen2 is using this builder API (we'll be adding a more convenient way to set this soon): val request = ModelSubscription.onCreate(Video::class.java) as AppSyncGraphQLRequest
val apiKeyRequest = request.newBuilder()
.authorizationType(AuthorizationType.API_KEY)
.build<Video>()
val onCreateSubscription = Amplify.API.subscribe(apiKeyRequest, ...) However, while testing this out I actually found a bug in Amplify's handling of multiple auth rules for subscriptions, so the above is not working as expected. I'll work on a fix for that, but in the meantime you can actually get the desired behaviour by requesting a multi-auth subscription: val request = ModelSubscription.onCreate(Video::class.java) as AppSyncGraphQLRequest
val multiAuthRequest = request.newBuilder()
.requestAuthorizationStrategyType(AuthModeStrategyType.MULTIAUTH)
.build<Video>()
val onCreateSubscription - Amplify.API.subscribe(multiAuthRequest, ...) That should allow you to subscribe to the video model without logging in. I'll update this issue again once the fix to directly use API_KEY in this situation becomes available. |
The bug mentioned above was fixed in Amplify Android 2.20.0. We also have an in-progress feature to improve the experience for setting the auth mode for a request that will be included in a future release. Closing this issue now! |
This issue is now closed. Comments on closed issues are hard for our team to see. |
Before opening, please confirm:
JavaScript Framework
Next.js
Amplify APIs
Authentication, GraphQL API
Amplify Version
v6
Amplify Categories
auth
Backend
Amplify Gen 2 (Preview)
Environment information
Describe the bug
Combining both
read
andlisten
permissions doesn't work.Either
listen
orread
on their own do workExpected behavior
After saving the file with sandbox running the model is deployed
Reproduction steps
a.allow.public().to(['read', 'listen'])
to amplifydata\resource.ts
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: