-
Notifications
You must be signed in to change notification settings - Fork 251
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 multiAuth is not working as expected #1693
Comments
Hi @sadaqatdev - Can you please share your schema (or at least a subset of it with the public/private models)? |
HI @Jordan-Nelson the following is schema type RoomConnectServiceStatus @model @auth(rules: [{allow: private}, {allow: public, provider: iam, operations: [read]}]) {
id: ID!
isActivatedstatus: Boolean
roomIdstatus: String
serviceIDstatus: String
currentDeviceUidstatus: String
updateTimestatus: AWSDateTime
}
type MqttCloudConfig @model @auth(rules: [{allow: private}, {allow: public, provider: iam, operations: [read]}]) {
id: ID!
ip: String
port: String
password: String
username: String
}
type Nurse @model @auth(rules: [{allow: private}]) {
id: ID!
name: String
phone: AWSPhone!
thumbnail: String
}
type Owner @model @auth(rules: [{allow: private}]) {
id: ID!
roomID: ID
nurseID: ID
}
type Room @model @auth(rules: [{allow: private}, {allow: public, provider: iam, operations: [read]}]) {
id: ID!
title: String
}
type RoomConnecttoService @model @auth(rules: [{allow: private}, {allow: public, provider: iam, operations: [read]}]) {
id: ID!
roomID: ID
serviceID: ID
currentDeviceUid: String
isActivated: Boolean
}
type Services @model @auth(rules: [{allow: private}, {allow: public, provider: iam, operations: [read]}]) {
id: ID!
name: String
ordered: Boolean
fulfilled: Boolean
thumbnail: String
roomConnectoId: String
}
type Patient @model @auth(rules: [{allow: private}]) {
id: ID!
name: String
phone: AWSPhone!
thumbnail: String
}
type SubscribedRooms @model @auth(rules: [{allow: private}]) {
id: ID!
roomID: ID
userID: ID
} |
@sadaqatdev - Is the log you provided above to full output? Is there any additional output? For multi auth, it should attempt to perform the sync with the next auth mode if the first fails. It would be helpful to know if there is any additional output after the first sync failure. |
I also want to confirm that you have the |
yes I configure multi auth , but not working |
Full log output: Launching lib/main.dart on SM J610F in debug mode... |
Thanks @sadaqatdev. Can you also provide your amplifyconfig.json (with sensitive info masked or removed)? |
I see you already commented on #1220. This could be related, although it looks like that was resolved a while back. |
const amplifyconfig = ''' {
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"api": {
"plugins": {
"awsAPIPlugin": {
"sisterhelpbg": {
"endpointType": "GraphQL",
"endpoint": " ",
"region": "eu-west-1",
"authorizationType": "AWS_IAM"
}
}
}
},
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"UserAgent": "aws-amplify-cli/0.1.0",
"Version": "0.1.0",
"IdentityManager": {
"Default": {}
},
"AppSync": {
"Default": {
"ApiUrl": " ",
"Region": "eu-west-1",
"AuthMode": "AWS_IAM",
"ClientDatabasePrefix": " "
},
"sisterhelpbg_AMAZON_COGNITO_USER_POOLS": {
"ApiUrl": " ",
"Region": "eu-west-1",
"AuthMode": "AMAZON_COGNITO_USER_POOLS",
"ClientDatabasePrefix": " "
}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": " ",
"Region": "eu-west-1"
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": " ",
"AppClientId": " ",
"Region": "eu-west-1"
}
},
"Auth": {
"Default": {
"authenticationFlowType": "USER_SRP_AUTH",
"socialProviders": [],
"usernameAttributes": [
"PHONE_NUMBER"
],
"signupAttributes": [
"PHONE_NUMBER"
],
"passwordProtectionSettings": {
"passwordPolicyMinLength": 8,
"passwordPolicyCharacters": []
},
"mfaConfiguration": "OFF",
"mfaTypes": [
"SMS"
],
"verificationMechanisms": [
"EMAIL"
]
}
}
}
}
}
}'''; |
From testing, I saw unexpected behaviors with DataStore with both amplify-swift and amplify-android libraries. To summarize the issue: When use mixed auth rules, i.e. public permission and private/owner permission, DataStore fails to allow the public access when there is no authenticated user session. 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 on AndroidAs a developer, I want my end users to have
Actual Behavior on Android
What happened: with amplify-android, it attempted to create subscription for Expected Behavior on iOSAs a developer, I want my end users to have
Actual Behavior on iOS
What happened: amplify-swift attempted to establish subscriptions for |
I also quick tested with GraphQL API, cognito + API Key. Whenever I try to access without cognito user, even public model. It gives error. |
Hi @MarlonJD thanks for testing and following up. I believe the API plugin doesn't have a automatic fall-back mechanism like DataStore to choose a working auth strategy. If you are using multi-auth with API plugin, you probably need to specify which auth mode you are going to use when initiate an operation. Details see: https://docs.amplify.aws/lib/graphqlapi/authz/q/platform/flutter/#configure-multiple-authorization-modes |
Hmm I'm using API GraphQL instead of DataStore but I'll try with specifying apiName. I'll let you know soon |
This should be resolved in the next release (after #3612 is merged). Given the following schema, below are the results for an unauthenticated user. The results are the same on iOS and Android.
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
} |
Awesome, happy to hear that, I couldn't use datastore for this reasons. I'll try when it comes to release. Thanks! |
As mentioned above, this should be resolved as of v1.4.0 |
Description
without login public models are not syn in android , iOS works fine
Categories
Steps to Reproduce
create public model and use iam auth and add data exception occur
Screenshots
No response
Platforms
Android Device/Emulator API Level
No response
Environment
Dependencies
Device
android Samsung G9
OS
NA
CLI Version
8.3.1
Additional Context
No response
The text was updated successfully, but these errors were encountered: