amplify-swift/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginA.../DefaultAuthCognito
Sebastian Villena 08d7313870
chore: Fixing SwiftLint warnings (#2732)
* chore: Fixing SwiftLint warnings in Amplify project

* chore: Fixing SwiftLint warnings in APICategoryPlugin  project

* chore: Fixing SwiftLint warnings in AnalyticsCategoryPlugin project

* chore: Fixing SwiftLint warnings in AWSCognitoAuthPlugin project

* chore: Fixing SwiftLint warnings in DataStoreCategoryPlugin project

* chore: Fixing SwiftLint warnings in PredictionsCategoryPlugin project

* chore: Fixing SwiftLint warnings in StoragePlugin project
2023-02-08 15:06:41 -05:00
..
Models chore(datastore): Update single auth integration tests to use V2 Transform (#1936) 2022-06-21 14:52:17 -04:00
AWSDataStoreCategoryPluginAuthIntegrationTests+Support.swift chore(datastore): integration tests (#1510) 2021-12-06 09:16:30 -08:00
AWSDataStoreCategoryPluginAuthIntegrationTests.swift chore: Fixing SwiftLint warnings (#2732) 2023-02-08 15:06:41 -05:00
AWSDataStoreCategoryPluginAuthOwnerIntegrationTests.swift chore: Fixing SwiftLint warnings (#2732) 2023-02-08 15:06:41 -05:00
README.md chore(datastore): Update single auth integration tests to use V2 Transform (#1936) 2022-06-21 14:52:17 -04:00
singleauth-cognito-schema.graphql chore(datastore): Update single auth integration tests to use V2 Transform (#1936) 2022-06-21 14:52:17 -04:00

README.md

DataStore with Auth Integration Tests

The following steps demonstrate how to setup a GraphQL endpoint with AppSync and Cognito User Pools. This configuration is used to run the tests in AWSDataStoreCategoryPluginAuthIntegrationTests.swift.

Set-up

  1. amplify init

  2. Make sure the correct CLI version is used for this test.

  • amplify --v should be at least 8.5.2
  • cli.json "transformerversion": 2
  • cli.json "useexperimentalpipelinedtransformer": true
  • cli.json "usesubusernamefordefaultidentityclaim": true
  1. amplify add api
? Select from one of the below mentioned services: GraphQL
  Authorization modes: Amazon Cognito User Pool (default) 
  Conflict detection (required for DataStore): Enabled 
  Conflict resolution strategy: Auto Merge
? Choose a schema template: Blank Schema  
? Do you want to edit the schema now? `Yes`

Copy the content of the schema from AWSDataStoreCategoryPluginAuthIntegrationTests/DefaultAuthCognito/singleauth-cognito-schema.graphql into the newly created schema.graphql file

  1. amplify update api ? Please select from one of the below mentioned services: GraphQL ? Select from the options below Enable DataStore for entire API

  2. amplify push

? Are you sure you want to continue? `Yes`
? Do you want to generate code for your newly created GraphQL API `No`
  1. Copy amplifyconfiguration.json to a new file named AWSDataStoreCategoryPluginAuthIntegrationTests-amplifyconfiguration.json inside ~/.aws-amplify/amplify-ios/testconfiguration/
cp amplifyconfiguration.json ~/.aws-amplify/amplify-ios/testconfiguration/AWSDataStoreCategoryPluginAuthIntegrationTests-amplifyconfiguration.json
  1. Create AWSDataStoreCategoryPluginAuthIntegrationTests-credentials.json inside the same folder with a json object containing user1, and password, used to create the cognito user in the userpool. In step 2, the cognito userpool is configured to allow users to sign up with their email as the username.
{
    "user1": "<USER EMAIL>",
    "passwordUser1": "<PASSWORD>",
    "user2": "<USER2 EMAIL>",
    "passwordUser2": "<PASSWORD>"
}

Creating users through AWS Console

  1. amplify console auth
? Which console `User Pool`
  1. Click on Users and groups, Sign up the two new users with the email and a temporary password.

  2. Click on App clients, and keep note of the app client web's App client id. This can be used the AWS AppSync console Queries.

  3. amplify console api Click on Queries tab, and click on Log in. This will prompt you to enter the app client id, username, and temporary password. After logging in successfully, it will ask you to enter a new password. Make sure those are the same as the one specified in the credentials json file from step 5. Do this for both users.

Creating users through AWS CLI

  1. Run the following commands
aws cognito-idp admin-create-user --user-pool-id [POOL_ID] --username [USER EMAIL]
aws cognito-idp admin-set-user-password --user-pool-id [POOL_ID] --username [USER EMAIL] --password [PASSWORD] --permanent

The [POOL_ID] can be found in amplifyconfiguration.json under auth.plugin.awsCognitoAuthPlugin.CognitoUserPool.Default.PoolId

Now you can run the AWSDataStoreCategoryPluginAuthIntegrationTests