![]() |
||
---|---|---|
.. | ||
Models | ||
AWSDataStoreAuthBaseTest.swift | ||
AWSDataStoreCategoryPluginAuthIntegrationTests+Support.swift | ||
AWSDataStoreCategoryPluginAuthIntegrationTests.swift | ||
AWSDataStoreCategoryPluginAuthOwnerIntegrationTests.swift | ||
README.md | ||
TestConfigHelper.swift | ||
singleauth-cognito-schema.graphql |
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
-
amplify init
-
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
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
-
amplify update api
? Please select from one of the below mentioned services:GraphQL
? Select from the options belowEnable DataStore for entire API
-
amplify push
? Are you sure you want to continue? `Yes`
? Do you want to generate code for your newly created GraphQL API `No`
- Copy
amplifyconfiguration.json
to a new file namedAWSDataStoreCategoryPluginAuthIntegrationTests-amplifyconfiguration.json
inside~/.aws-amplify/amplify-ios/testconfiguration/
cp amplifyconfiguration.json ~/.aws-amplify/amplify-ios/testconfiguration/AWSDataStoreCategoryPluginAuthIntegrationTests-amplifyconfiguration.json
- Create
AWSDataStoreCategoryPluginAuthIntegrationTests-credentials.json
inside the same folder with a json object containinguser1
, andpassword
, 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
amplify console auth
? Which console `User Pool`
-
Click on
Users and groups
, Sign up the two new users with the email and a temporary password. -
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. -
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
- 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