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

DataStore multi-auth is not working with mixed owner and public auth rules #2399

Closed
1 task done
HuiSF opened this issue Apr 18, 2023 · 4 comments
Closed
1 task done
Assignees
Labels
bug Something isn't working datastore DataStore category/plugins pending-release Code has been merged but pending release

Comments

@HuiSF
Copy link
Member

HuiSF commented Apr 18, 2023

Before opening, please confirm:

Language and Async Model

Kotlin

Amplify Categories

DataStore

Gradle script dependencies

// Put output below this line

Environment information

# Put output below this line


Please include any relevant guides or documentation you're referencing

No response

Describe the bug

Original issue: aws-amplify/amplify-flutter#2527 | aws-amplify/amplify-flutter#1693
Related amplify-swift issue: aws-amplify/amplify-swift#2873

DataStore multi-auth is not working as expected.

Take schema

type UserProfile @model @auth(rules: [{ allow: owner }]) {
  id: ID!
  name: String!
}

type ModelA @model @auth(rules: [{ allow: public, provider: apiKey }]) {
  id: ID!
  content: String
}

type ModelB
  @model
  @auth(
    rules: [
      { allow: public, provider: apiKey, operations: [read] }
      { allow: owner }
    ]
  ) {
  id: ID!
  content: String
}

type ModelC
  @model
  @auth(
    rules: [
      { allow: public, provider: apiKey, operations: [read] }
      { allow: private, provider: userPools }
    ]
  ) {
  id: ID!
  content: String
}

When configure DataStore to use multi-auth mode with NO authenticated session:

Expected Behavior

As a developer, I want my end users to have read access to Model A B and C, including receiving subscription events.

models sync queries subscriptions
UserProfile No No
ModelA Yes Yes
ModelB Yes Yes
ModelC Yes Yes

Actual Behavior

models sync queries subscriptions
UserProfile No No
ModelA No No
ModelB No No
ModelC No No

What happened: with amplify-android, it attempted to create subscription for UserProfile , when there was no authenticated user session, the subscription failed, and put DataStore into the LOCAL_ONLY mode. The should-be-allowed read operations on other models were not working. This make the multi-auth mode unusable.

Reproduction steps (if applicable)

  1. Use above schema example to setup datastore + API sync + auth (default Cognito User Pool + API key as additional auth mode)
  2. Start DataStore without signing a user and watch the sync behavior
  3. Sign in a user, start DataStore and watch the sync behavior

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line


amplifyconfiguration.json

No response

GraphQL Schema

// Put your schema below this line

Additional information and screenshots

No response

@HuiSF HuiSF added the datastore DataStore category/plugins label Apr 18, 2023
@dengdan154 dengdan154 added bug Something isn't working pending-triage Issue is pending triage labels Apr 20, 2023
@eeatonaws eeatonaws removed the pending-triage Issue is pending triage label Apr 21, 2023
@mattcreaser mattcreaser assigned mattcreaser and unassigned tjleing Aug 11, 2023
@mattcreaser
Copy link
Member

I've verified this error and will look into it.

@mattcreaser
Copy link
Member

Okay so it looks like what is happening in this case is that in the MultiAuthSubscriptionOperation once all the auth modes are exhausted it emits a generic ApiException. Meanwhile, back in DataStore, the SubscriptionProcessor will ignore Unauthorized errors from GraphQL, but the generic error instead falls into the failure logic that cancels everything.

Seems like we need a two part fix here:

  • When auth modes are exhausted the API category should emit an exception that explicitly indicates what happened.
  • DataStore should ignore this error type for the purposes of establishing subscriptions.

@mattcreaser
Copy link
Member

This fix was released in Amplify Android 2.12.0!

@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working datastore DataStore category/plugins pending-release Code has been merged but pending release
Projects
None yet
Development

No branches or pull requests

5 participants