From 09dc518882b724197fdf56b7a22feea6504bb70f Mon Sep 17 00:00:00 2001 From: Divyesh Chitroda Date: Tue, 14 Mar 2023 15:36:20 -0700 Subject: [PATCH] chore: merge main into notifications (#167) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(core): remove unused dynamic nav dependency (#2132) * fix(datastore): remove typename from ModelMetadata (#2122) * fix(datastore): remove typename from ModelMetadata * Test a potential fix * Test a potential fix * fix: callbacks not invoked when attached using getTransfer api (#2111) * fix: listener not invoked when attached using getTransfer api * address PR comments * default state to unknown * add comment * add comment * override getRequest in storage operation & make SocketExcpetion retryable * add nullable annotation * address nullable request Co-authored-by: Tyler Roach * Prevent attempting to read backed up EncryptedSharedPreferences that are no longer readable (#2113) * fix(auth): device metadata migration (#2114) * Number of attributes being too high is not retryable (#2112) * Number of attributes being too high is not retryable * Match iOS at not retrying bad request error -- covering multiple 400 errors * Fix lint * Fix lint * Update Kotlin SDK version Co-authored-by: Thomas Leing * Change errors returned on some apis while federated (#2116) * release: Amplify Android 2.0.0 (#2115) * release: Amplify Android 2.0.0 * add core-kotlin changelog * add more info in changelog * revert unintended change * remove breaking change for analytics * fix(datastore): remove typename from ModelMetadata * fix(datastore): remove typename from ModelMetadata * remove unneeded file * small cleanup * remove print statements * fix comment * force tests * force tests * force tests Co-authored-by: Michael Law <1365977+lawmicha@users.noreply.github.com> Co-authored-by: Michael Schneider Co-authored-by: Saijad Dhuka <83975678+sdhuka@users.noreply.github.com> Co-authored-by: Tyler Roach Co-authored-by: Divyesh Chitroda Co-authored-by: Thomas Leing Co-authored-by: Thomas Leing Co-authored-by: Sunil Timalsina * chore: Remove deprecated maven plugin (#2137) * Remove deprecated maven project * Fix task name grep * chore: Remove Javadoc tasks (#2139) * Remove deprecated maven project * Fix task name grep * Remove Javadoc tasks * fix: Change order of updating state in local cache (#2141) * fix: fix integration test and added logger to integration test (#2143) * fix: Change order of updating state in local cache * change order for updating status and add logger to integ tests * change log level to debug * Fix for when move to idle state is called twice (#2152) * Update README.md (#2120) remove dev-preview APIs note. * Dengdan stress test (#2153) * Initial commit * Work in progress * finish codes * change build * update build * test excludeStressTest * Revert "Merge branch 'main' into dengdan-stress-test" This reverts commit b50840ed920edd5447435a76d95ecb48955c0b74, reversing changes made to 3bacf1b506b887300c1e23a61a4b6be9371b364f. * remove categories * remove external changes * remove external changes * remove more changes * Update copyright and refactor * Update StorageStressTest.kt * Update StorageStressTest.kt * Update StorageStressTest.kt * Update StorageStressTest.kt * linting * Update StorageStressTest.kt * Delete StorageStressTest.kt * Delete amplifyconfigurationupdated.json * Delete amplifyconfigurationupdated.json * Update DataStoreStressTest.kt * Fix(Auth): Sign up if successful should return DONE instead of Confirm sign up (#2130) * If sign up is successful in the first try return DONE * Sign up should send DONE if it is successful * revert jsongenerator cleandir fun * lint fix * Feat(Auth Test): Custom party testing for Custom Test without SRP (#2149) * Adding custom auth test cases * Updating test cases for Custom Auth to ensure they pass * lint format * Fix for phone number * Recreate all tests * Unignore storage and pinpoint tests (#2156) * unignore tests * extend timeout to 60s Co-authored-by: Saijad Dhuka <83975678+sdhuka@users.noreply.github.com> * feat(Geo): Add Kotlin Geo Facade (#2155) * Add Kotlin Geo Facade * Add return docs to the function comments * Add tests to verify options are passed * fix: Add missing apis in storage Kotlin & RxJava facade (#2160) * fix: Add pause, resume api to kotlin and rxJava facade * add unit tests * remove irrelevant code changes * add assertion * Update DeviceFarm build config (#2168) * fix: user metadata was persisted empty in the database (#2165) * fix: usermeta was persisted as empty in the database * fix compilation error * fix compilation error * avoid adding metadata if it is null * Add Geo Rx Bindings (#2159) * chore: Re-add storage tests (#2163) * Readd storage tests * rename file * reduce stress Co-authored-by: Saijad Dhuka <83975678+sdhuka@users.noreply.github.com> * Add a network status listener to restart DataStore after the network … (#2148) * Add a network status listener to restart DataStore after the network comes back online. * Add Reachability monitor * working pretty well * cleanup * update test * fix: fix integration test and added logger to integration test (#2143) * fix: Change order of updating state in local cache * change order for updating status and add logger to integ tests * change log level to debug * Fix for when move to idle state is called twice (#2152) * Update README.md (#2120) remove dev-preview APIs note. * Dengdan stress test (#2153) * Initial commit * Work in progress * finish codes * change build * update build * test excludeStressTest * Revert "Merge branch 'main' into dengdan-stress-test" This reverts commit b50840ed920edd5447435a76d95ecb48955c0b74, reversing changes made to 3bacf1b506b887300c1e23a61a4b6be9371b364f. * remove categories * remove external changes * remove external changes * remove more changes * Update copyright and refactor * Update StorageStressTest.kt * Update StorageStressTest.kt * Update StorageStressTest.kt * Update StorageStressTest.kt * linting * Update StorageStressTest.kt * Delete StorageStressTest.kt * Delete amplifyconfigurationupdated.json * Delete amplifyconfigurationupdated.json * Update DataStoreStressTest.kt * force build * force build * force build * fix typo * Add a network status listener to restart DataStore after the network comes back online. * Add Reachability monitor * working pretty well * cleanup * update test * force build * force build * force build * fix typo * reply to comments * Add testImplementation lin eto compile tests correctly in intellij * reply to comments * make ReachabilityMonitor expose the observable * Update datastore plugin to use the reachability monitor * cleanup * cleanup * cleanup * force tests Co-authored-by: Michael Schneider Co-authored-by: Saijad Dhuka <83975678+sdhuka@users.noreply.github.com> Co-authored-by: gpanshu <91897496+gpanshu@users.noreply.github.com> Co-authored-by: Divyesh Chitroda Co-authored-by: dengdan154 <85711456+dengdan154@users.noreply.github.com> * chore: Upgrade Gradle, AGP, and KtLint (#2172) * Remove deprecated maven project * Fix task name grep * Upgrade Gradle to 7.5.1 * Upgrade AGP * Add VERSION_NAME back to BuildConfig This was removed for library projects in AGP 4.1. We may consider renaming this in the future to disambiguate the Amplify version and the application version. * Update KtLint and fix all new lint errors * Use JDK11 on codebuild * Use JDK11 in workflows * Upgrade compileSdkVersion to 31 * Try using custom commands to install Android SDK 31 * Update device farm buildspec with manual Android SDK install * Fix additional ktlint errors * Upgrade Desugar to JDK11-compatible version * Upgrade Robolectric * Set locale explicitly to match expectation * fix(geo): Increase Geo timeout so that it runs successfully on a Pixel 3a XL (#2177) * Increase Geo timeout so that it runs successfully on a Pixel 3a XL * Fix lint Co-authored-by: Thomas Leing * Add a buildspec file for nightly tests (#2180) * Chore(Auth): Implementation of the custom auth with SRP parity testing use case (#2167) * Added the test case for custom auth with SRP * ktlint * release: Amplify Android 2.1.0 (manually created) (#2185) Co-authored-by: Thomas Leing * chore: Add PR checker workflow (#2188) * fix(Auth): Fix for when loading credentials the success/error is fired twice (#2184) * chore: update changelog for Amplify Android 2.1.0 (#2193) * feat(Auth): Overriding sign in when the State machine is already in the signing in state (#2187) * chore: fix inconsistency with endpointWithAttributes test (#2196) * chore: update changelog for v2.1.0 (#2198) * chore: replace md5 with sha-256 for file data validation (#2199) * chore: Remove unused version and group properties (#2186) * chore: Add a label that will disable the PR title check (#2195) Co-authored-by: gpanshu <91897496+gpanshu@users.noreply.github.com> * chore: add release tag to PR title checker config (#2194) Co-authored-by: Matt Creaser * fix(datastore): Fix lock contention issue when running DataStore.start() from the callback of DataStore.stop() (#2208) Co-authored-by: Michael Schneider * chore: Add group and version back to all subprojects (#2213) * chore: Remove the release-kotlin_v block from prepare release script (#2231) * fix(core): Remove unused dependencies (#2207) Co-authored-by: Matt Creaser * chore: Modify the bump_version branch name to be specific to the base branch (#2240) * fix(geo): Bump MapLibre SDK to 9.6.0 (#2254) * release: Amplify Android 2.1.1 (#2257) Co-authored-by: amplify-android-dev+ghops * fix(analytics): Remove test dependencies from implementation configuration (#2253) * chore: Ignore clearStopsSyncAndDeletesDatabase test (#2262) * fix(auth): Fix Authorization header for HostedUI fetchToken when appSecret is used (#2264) * chore: Supply base_branch when calling `create_next_release_pr` lane (#2245) * chore: Update PR template to include security checklist item (#2251) * feat(auth): add required hash param to cognito api calls (#2266) Co-authored-by: Banji Jolaoso Co-authored-by: AWS Mobile SDK Bot <46607340+awsmobilesdk@users.noreply.github.com> Co-authored-by: Saijad Dhuka <83975678+sdhuka@users.noreply.github.com> Co-authored-by: Tyler Roach * feat(datastore): Add recoverability improvements (#2201) Co-authored-by: Matt Creaser * feat(auth): Added parity test for fetchDevices,rememberDevice,forgetDevice and fetchUserAttributes (#2174) Co-authored-by: Sunil Timalsina Co-authored-by: Banji Jolaoso Co-authored-by: Divyesh Chitroda Co-authored-by: Matt Creaser Co-authored-by: Saijad Dhuka <83975678+sdhuka@users.noreply.github.com> Co-authored-by: Tyler Roach Co-authored-by: Thomas Leing Co-authored-by: Thomas Leing Co-authored-by: gpanshu <91897496+gpanshu@users.noreply.github.com> Co-authored-by: AWS Mobile SDK Bot <46607340+awsmobilesdk@users.noreply.github.com> * release: Amplify Android 2.2.0 (#2269) Co-authored-by: amplify-android-dev+ghops * chore: Convert build.gradle files to Kotlin (#2183) * Convert build.gradle files to Kotlin * Fix missing test dependency * Update copyright year * chore: Set the signing information in project extras (#2277) * fix(auth): Moving credential provider to main (#2273) * chore(analytics): Simplify error code checking, uniformly across platforms (#2274) Co-authored-by: Thomas Leing Co-authored-by: Matt Creaser * feat(auth): added kover plugin for coverage (#2267) Co-authored-by: Banji Jolaoso Co-authored-by: gpanshu <91897496+gpanshu@users.noreply.github.com> * release: Amplify Android 2.2.1 (#2285) Co-authored-by: amplify-android-dev+ghops Co-authored-by: Matt Creaser * chore: Remove circleci configuration file (#2279) Co-authored-by: gpanshu <91897496+gpanshu@users.noreply.github.com> * fix(auth): fix npe in initialize fetch auth session (#2284) Co-authored-by: Banji Jolaoso * fix(auth): Fix confirm signin when incorrect MFA code is entered (#2286) * release: Amplify Android 2.2.2 (#2292) Co-authored-by: amplify-android-dev+ghops * chore: Fix using amplify-android in a composite build (#2294) * chore: update device farm configuration for nightly build (#2281) * chore: remove buildspec files (#2308) * chore: remove amplify-data from codeowners (#2252) Co-authored-by: Saijad Dhuka <83975678+sdhuka@users.noreply.github.com> * fix(datastore): Fix aliasing of column names (#2312) * feat(storage): Add support for S3 acceleration mode (#2304) * feat(aws-datastore): Make the reachability component configurable (#2307) Signed-off-by: Manuel Iglesias <6154160+manueliglesias@users.noreply.github.com> Co-authored-by: Divyesh Chitroda * release: Amplify Android 2.3.0 (#2323) Co-authored-by: amplify-android-dev+ghops * feat(aws-api,aws-datastore): WebSocket improvements (#2283) Signed-off-by: Manuel Iglesias <6154160+manueliglesias@users.noreply.github.com> Co-authored-by: Divyesh Chitroda Co-authored-by: Matt Creaser * chore(auth): Use restricted API to surface the JSON used to configure the Auth category (#2311) Co-authored-by: Thomas Leing * chore: Remove incorrect Developer Preview label (#2328) * fix(auth): Delete user invalid state fixes (#2326) Co-authored-by: Anshul Gupta Co-authored-by: gpanshu <91897496+gpanshu@users.noreply.github.com> * Restore publishing sources jar (#2329) Co-authored-by: Thomas Leing * release: Amplify Android 2.3.0 (#2330) Co-authored-by: amplify-android-dev+ghops Co-authored-by: Thomas Leing * feat(auth): Add aws-core and AWSCredentialsProvider (#2316) Co-authored-by: Tim Schmelter Co-authored-by: Erica Eaton <67125657+eeatonaws@users.noreply.github.com> Co-authored-by: Divyesh Chitroda --------- Signed-off-by: Manuel Iglesias <6154160+manueliglesias@users.noreply.github.com> Co-authored-by: Erica Eaton <67125657+eeatonaws@users.noreply.github.com> Co-authored-by: Michael Schneider Co-authored-by: Michael Law <1365977+lawmicha@users.noreply.github.com> Co-authored-by: Michael Schneider Co-authored-by: Saijad Dhuka <83975678+sdhuka@users.noreply.github.com> Co-authored-by: Tyler Roach Co-authored-by: Thomas Leing Co-authored-by: Thomas Leing Co-authored-by: Sunil Timalsina Co-authored-by: Matt Creaser Co-authored-by: gpanshu <91897496+gpanshu@users.noreply.github.com> Co-authored-by: dengdan154 <85711456+dengdan154@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: amplify-android-dev+ghops Co-authored-by: banji180 Co-authored-by: Banji Jolaoso Co-authored-by: AWS Mobile SDK Bot <46607340+awsmobilesdk@users.noreply.github.com> Co-authored-by: Manuel Iglesias <6154160+manueliglesias@users.noreply.github.com> Co-authored-by: Dane Pilcher Co-authored-by: Anshul Gupta Co-authored-by: Tim Schmelter --- CHANGELOG.md | 5 ++ README.md | 2 +- annotations/.gitignore | 1 + annotations/build.gradle.kts | 46 ++++++++++++++ annotations/gradle.properties | 4 ++ annotations/src/main/AndroidManifest.xml | 20 +++++++ .../annotations/InternalApiWarning.kt | 37 ++++++++++++ aws-analytics-pinpoint/build.gradle.kts | 1 + aws-api-appsync/build.gradle.kts | 1 + aws-api/build.gradle.kts | 1 + aws-auth-cognito/build.gradle.kts | 1 + .../auth/cognito/AWSCognitoAuthPlugin.kt | 9 +++ .../auth/cognito/AWSCognitoAuthService.kt | 2 +- .../auth/cognito/RealAWSCognitoAuthPlugin.kt | 58 +++++++++--------- .../actions/DeleteUserCognitoActions.kt | 33 +++++++--- .../codegen/actions/DeleteUserActions.kt | 1 + .../statemachine/codegen/data/SignOutData.kt | 1 + .../codegen/events/DeleteUserEvent.kt | 5 +- .../codegen/states/AuthenticationState.kt | 3 +- .../codegen/states/AuthorizationState.kt | 28 +++++++-- .../codegen/states/DeleteUserState.kt | 16 +++-- .../codegen/states/SignOutState.kt | 12 +++- .../cognito/RealAWSCognitoAuthPluginTest.kt | 21 +++++++ .../auth/cognito/StateTransitionTestBase.kt | 20 ------- .../auth/cognito/StateTransitionTests.kt | 54 ----------------- aws-core/.gitignore | 1 + aws-core/build.gradle.kts | 50 ++++++++++++++++ aws-core/gradle.properties | 4 ++ aws-core/src/main/AndroidManifest.xml | 20 +++++++ .../auth/AWSAuthSessionInternal.kt | 2 + .../auth/AWSCognitoUserPoolTokens.kt | 0 .../amplifyframework/auth/AWSCredentials.kt | 10 ++++ .../auth/AWSCredentialsProvider.kt | 60 +++++++++++++++++++ .../auth/AuthCredentialsProvider.kt | 2 + .../auth/CognitoCredentialsProvider.kt | 11 +--- aws-datastore/build.gradle.kts | 1 + aws-geo-location/build.gradle.kts | 1 + .../geo/location/AWSLocationGeoPlugin.kt | 2 + aws-predictions-tensorflow/build.gradle.kts | 1 + aws-predictions/build.gradle.kts | 1 + .../build.gradle.kts | 2 +- .../src/main/AndroidManifest.xml | 2 +- .../AWSPinpointPushNotificationsPlugin.kt | 1 - aws-storage-s3/build.gradle.kts | 1 + .../storage/s3/AWSS3StoragePlugin.java | 6 +- build.gradle.kts | 13 ++++ core/build.gradle.kts | 3 +- .../auth/AuthCategoryBehavior.java | 1 - .../pushnotifications/NotificationPayload.kt | 1 - settings.gradle.kts | 2 + 50 files changed, 430 insertions(+), 150 deletions(-) create mode 100644 annotations/.gitignore create mode 100644 annotations/build.gradle.kts create mode 100644 annotations/gradle.properties create mode 100644 annotations/src/main/AndroidManifest.xml create mode 100644 annotations/src/main/java/com/amplifyframework/annotations/InternalApiWarning.kt create mode 100644 aws-core/.gitignore create mode 100644 aws-core/build.gradle.kts create mode 100644 aws-core/gradle.properties create mode 100644 aws-core/src/main/AndroidManifest.xml rename {core => aws-core}/src/main/java/com/amplifyframework/auth/AWSAuthSessionInternal.kt (93%) rename {core => aws-core}/src/main/java/com/amplifyframework/auth/AWSCognitoUserPoolTokens.kt (100%) rename {core => aws-core}/src/main/java/com/amplifyframework/auth/AWSCredentials.kt (86%) create mode 100644 aws-core/src/main/java/com/amplifyframework/auth/AWSCredentialsProvider.kt rename {core => aws-core}/src/main/java/com/amplifyframework/auth/AuthCredentialsProvider.kt (93%) rename {core => aws-core}/src/main/java/com/amplifyframework/auth/CognitoCredentialsProvider.kt (90%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52b69af890..ceb53178a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,14 @@ ### Features - **storage:** Add support for S3 acceleration mode ([#2304](https://github.com/aws-amplify/amplify-android/issues/2304)) - **aws-datastore:** Make the reachability component configurable ([#2307](https://github.com/aws-amplify/amplify-android/issues/2307)) +- **aws-api,aws-datastore:** WebSocket improvements ([#2283](https://github.com/aws-amplify/amplify-android/issues/2283)) ### Bug Fixes - **datastore:** Fix aliasing of column names ([#2312](https://github.com/aws-amplify/amplify-android/issues/2312)) +- **auth:** Delete user invalid state fixes ([#2326](https://github.com/aws-amplify/amplify-android/issues/2326)) + +### Miscellaneous +- Restore publishing sources jar ([#2329](https://github.com/aws-amplify/amplify-android/issues/2329)) [See all changes between 2.2.2 and 2.3.0](https://github.com/aws-amplify/amplify-android/compare/release_v2.2.2...release_v2.3.0) diff --git a/README.md b/README.md index fb8d14f167..f1b496f341 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## Amplify for Android (Developer Preview) +## Amplify for Android AWS Amplify [![DiscordChat](https://img.shields.io/discord/308323056592486420?logo=discord)](https://discord.gg/jWVbPfC) diff --git a/annotations/.gitignore b/annotations/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/annotations/.gitignore @@ -0,0 +1 @@ +/build diff --git a/annotations/build.gradle.kts b/annotations/build.gradle.kts new file mode 100644 index 0000000000..0b85f37c56 --- /dev/null +++ b/annotations/build.gradle.kts @@ -0,0 +1,46 @@ +/* + * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +plugins { + id("com.android.library") + id("kotlin-android") +} + +apply(from = rootProject.file("configuration/checkstyle.gradle")) +apply(from = rootProject.file("configuration/publishing.gradle")) + +group = properties["POM_GROUP"].toString() + +android { + kotlinOptions { + moduleName = "com.amplifyframework.annotations" + } +} + +dependencies { + implementation(dependency.kotlin.stdlib) +} + +afterEvaluate { + // Disables this warning: + // warning: listOf(classfile) MethodParameters attribute + // introduced in version 52.0 class files is ignored in + // version 51.0 class files + // Root project has -Werror, so this warning + // would fail the build, otherwise. + tasks.withType().configureEach { + options.compilerArgs.add("-Xlint:-classfile") + } +} diff --git a/annotations/gradle.properties b/annotations/gradle.properties new file mode 100644 index 0000000000..13ed609b9e --- /dev/null +++ b/annotations/gradle.properties @@ -0,0 +1,4 @@ +POM_ARTIFACT_ID=annotations +POM_NAME=Amplify Framework for Android - Annotations +POM_DESCRIPTION=Amplify Framework for Android - Annotations for AWS Amplify Libraries +POM_PACKAGING=aar diff --git a/annotations/src/main/AndroidManifest.xml b/annotations/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..1f1387a5dc --- /dev/null +++ b/annotations/src/main/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/annotations/src/main/java/com/amplifyframework/annotations/InternalApiWarning.kt b/annotations/src/main/java/com/amplifyframework/annotations/InternalApiWarning.kt new file mode 100644 index 0000000000..63058ac08b --- /dev/null +++ b/annotations/src/main/java/com/amplifyframework/annotations/InternalApiWarning.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.amplifyframework.annotations + +/** + * API marked with this annotation is internal to Amplify, and it is not intended to be used outside. + * It could be modified or removed without any notice. + * + * We strongly recommend to not use such API. + */ +@Suppress("DEPRECATION") +@RequiresOptIn( + level = RequiresOptIn.Level.WARNING, + message = "This API is internal to Amplify and should not be used. It could be removed or changed without notice.", +) +@Target( + AnnotationTarget.CLASS, + AnnotationTarget.TYPEALIAS, + AnnotationTarget.FUNCTION, + AnnotationTarget.PROPERTY, + AnnotationTarget.FIELD, + AnnotationTarget.CONSTRUCTOR, +) +public annotation class InternalApiWarning diff --git a/aws-analytics-pinpoint/build.gradle.kts b/aws-analytics-pinpoint/build.gradle.kts index 2f209e9f4a..db1438ac52 100644 --- a/aws-analytics-pinpoint/build.gradle.kts +++ b/aws-analytics-pinpoint/build.gradle.kts @@ -26,6 +26,7 @@ group = properties["POM_GROUP"].toString() dependencies { implementation(project(":core")) + implementation(project(":aws-core")) implementation(project(":aws-pinpoint-core")) implementation(dependency.androidx.appcompat) diff --git a/aws-api-appsync/build.gradle.kts b/aws-api-appsync/build.gradle.kts index 093f53b53c..0a0da660e8 100644 --- a/aws-api-appsync/build.gradle.kts +++ b/aws-api-appsync/build.gradle.kts @@ -25,6 +25,7 @@ group = properties["POM_GROUP"].toString() dependencies { implementation(project(":core")) + implementation(project(":aws-core")) implementation(dependency.androidx.annotation) implementation(dependency.androidx.core) diff --git a/aws-api/build.gradle.kts b/aws-api/build.gradle.kts index e5a1da97d1..72799ee46e 100644 --- a/aws-api/build.gradle.kts +++ b/aws-api/build.gradle.kts @@ -25,6 +25,7 @@ group = properties["POM_GROUP"].toString() dependencies { api(project(":core")) + api(project(":aws-core")) implementation(project(":aws-api-appsync")) implementation(dependency.androidx.appcompat) diff --git a/aws-auth-cognito/build.gradle.kts b/aws-auth-cognito/build.gradle.kts index 0d4db7c918..c8a8d4cc73 100644 --- a/aws-auth-cognito/build.gradle.kts +++ b/aws-auth-cognito/build.gradle.kts @@ -26,6 +26,7 @@ group = properties["POM_GROUP"].toString() dependencies { implementation(project(":core")) + implementation(project(":aws-core")) implementation(dependency.kotlin.coroutines) implementation(dependency.kotlin.serializationJson) implementation(dependency.androidx.appcompat) diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPlugin.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPlugin.kt index 929179d318..1ffa276ee0 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPlugin.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPlugin.kt @@ -18,6 +18,7 @@ package com.amplifyframework.auth.cognito import android.app.Activity import android.content.Context import android.content.Intent +import androidx.annotation.RestrictTo import androidx.annotation.VisibleForTesting import com.amplifyframework.AmplifyException import com.amplifyframework.auth.AuthCodeDeliveryDetails @@ -91,6 +92,13 @@ class AWSCognitoAuthPlugin : AuthPlugin() { } } + private lateinit var pluginConfigurationJSON: JSONObject + + @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) + fun getPluginConfiguration(): JSONObject { + return pluginConfigurationJSON + } + private fun Exception.toAuthException(): AuthException { return if (this is AuthException) { this @@ -105,6 +113,7 @@ class AWSCognitoAuthPlugin : AuthPlugin() { @Throws(AmplifyException::class) override fun configure(pluginConfiguration: JSONObject, context: Context) { + pluginConfigurationJSON = pluginConfiguration try { val configuration = AuthConfiguration.fromJson(pluginConfiguration) val credentialStoreClient = CredentialStoreClient(configuration, context, logger) diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthService.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthService.kt index 85b03cce2e..0688a51fef 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthService.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthService.kt @@ -17,8 +17,8 @@ package com.amplifyframework.auth.cognito import aws.sdk.kotlin.services.cognitoidentity.CognitoIdentityClient import aws.sdk.kotlin.services.cognitoidentityprovider.CognitoIdentityProviderClient -import aws.sdk.kotlin.services.cognitoidentityprovider.endpoints.EndpointProvider import aws.smithy.kotlin.runtime.client.endpoints.Endpoint +import aws.smithy.kotlin.runtime.client.endpoints.EndpointProvider import com.amplifyframework.statemachine.codegen.data.AuthConfiguration interface AWSCognitoAuthService { diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPlugin.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPlugin.kt index bef2b979ba..c45ab2bfbb 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPlugin.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPlugin.kt @@ -833,7 +833,8 @@ internal class RealAWSCognitoAuthPlugin( when (val authNState = it.authNState) { is AuthenticationState.SigningOut -> { (authNState.signOutState as? SignOutState.SigningOutHostedUI)?.let { signOutState -> - if (callbackUri == null && signOutState.signedInData.signInMethod != + if (callbackUri == null && !signOutState.bypassCancel && + signOutState.signedInData.signInMethod != SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.UNKNOWN) ) { authStateMachine.send( @@ -1734,40 +1735,35 @@ internal class RealAWSCognitoAuthPlugin( private fun _deleteUser(token: String, onSuccess: Action, onError: Consumer) { val listenerToken = StateChangeListenerToken() + var deleteUserException: Exception? = null authStateMachine.listen( listenerToken, { authState -> - when (val authNState = authState.authNState) { - is AuthenticationState.SignedOut -> { - val event = DeleteUserEvent(DeleteUserEvent.EventType.SignOutDeletedUser()) - authStateMachine.send(event) - } - is AuthenticationState.Error -> { - val event = DeleteUserEvent(DeleteUserEvent.EventType.ThrowError(authNState.exception)) - authStateMachine.send(event) - } - else -> { - // No-op - } - } - val authZState = authState.authZState as? AuthorizationState.DeletingUser - when (val deleteUserState = authZState?.deleteUserState) { - is DeleteUserState.UserDeleted -> { - onSuccess.call() - sendHubEvent(AuthChannelEventName.USER_DELETED.toString()) - authStateMachine.cancel(listenerToken) - } - is DeleteUserState.Error -> { - authStateMachine.cancel(listenerToken) - onError.accept( - CognitoAuthExceptionConverter.lookup( - deleteUserState.exception, - "Request to delete user may have failed. Please check exception stack" + if (authState is AuthState.Configured) { + val (authNState, authZState) = authState + val exception = deleteUserException + when { + authZState is AuthorizationState.DeletingUser && + authZState.deleteUserState is DeleteUserState.Error -> { + deleteUserException = authZState.deleteUserState.exception + } + authNState is AuthenticationState.SignedOut && authZState is AuthorizationState.Configured -> { + sendHubEvent(AuthChannelEventName.USER_DELETED.toString()) + authStateMachine.cancel(listenerToken) + onSuccess.call() + } + authZState is AuthorizationState.SessionEstablished && exception != null -> { + authStateMachine.cancel(listenerToken) + onError.accept( + CognitoAuthExceptionConverter.lookup( + exception, + "Request to delete user may have failed. Please check exception stack" + ) ) - ) - } - else -> { - // No-op + } + else -> { + // No - op + } } } }, diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/DeleteUserCognitoActions.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/DeleteUserCognitoActions.kt index 9e65f1652d..0f3fa8621c 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/DeleteUserCognitoActions.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/DeleteUserCognitoActions.kt @@ -22,31 +22,48 @@ import com.amplifyframework.statemachine.Action import com.amplifyframework.statemachine.codegen.actions.DeleteUserActions import com.amplifyframework.statemachine.codegen.data.SignOutData import com.amplifyframework.statemachine.codegen.events.AuthenticationEvent +import com.amplifyframework.statemachine.codegen.events.AuthorizationEvent import com.amplifyframework.statemachine.codegen.events.DeleteUserEvent internal object DeleteUserCognitoActions : DeleteUserActions { override fun initDeleteUserAction(accessToken: String): Action = Action("DeleteUser") { id, dispatcher -> logger.verbose("$id Starting execution") - val evt = try { + try { cognitoAuthService.cognitoIdentityProviderClient?.deleteUser( DeleteUserRequest.invoke { this.accessToken = accessToken } ) - AuthenticationEvent(AuthenticationEvent.EventType.SignOutRequested(SignOutData(globalSignOut = false))) + val evt = DeleteUserEvent(DeleteUserEvent.EventType.UserDeleted()) + logger.verbose("$id Sending event ${evt.type}") + dispatcher.send(evt) } catch (e: Exception) { logger.warn("Failed to delete user.", e) if (e is UserNotFoundException) { // The user could have been remotely deleted, clear local session - AuthenticationEvent( - AuthenticationEvent.EventType.SignOutRequested( - SignOutData(globalSignOut = false) - ) - ) + val evt = DeleteUserEvent(DeleteUserEvent.EventType.ThrowError(e, true)) + logger.verbose("$id Sending event ${evt.type}") + dispatcher.send(evt) } else { - DeleteUserEvent(DeleteUserEvent.EventType.ThrowError(e)) + val evt = DeleteUserEvent(DeleteUserEvent.EventType.ThrowError(e, false)) + logger.verbose("$id Sending event ${evt.type}") + dispatcher.send(evt) + val evt2 = AuthorizationEvent(AuthorizationEvent.EventType.ThrowError(e)) + logger.verbose("$id Sending event ${evt2.type}") + dispatcher.send(evt2) } } + } + + override fun initiateSignOut(): Action = + Action("Sign Out Deleted User") { id, dispatcher -> + logger.verbose("$id Starting execution") + val evt = AuthorizationEvent(AuthorizationEvent.EventType.UserDeleted()) + val evt2 = AuthenticationEvent( + AuthenticationEvent.EventType.SignOutRequested(SignOutData(globalSignOut = true, bypassCancel = true)) + ) logger.verbose("$id Sending event ${evt.type}") dispatcher.send(evt) + logger.verbose("$id Sending event ${evt2.type}") + dispatcher.send(evt2) } } diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/actions/DeleteUserActions.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/actions/DeleteUserActions.kt index 7097a3363a..78f3fdbea3 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/actions/DeleteUserActions.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/actions/DeleteUserActions.kt @@ -19,4 +19,5 @@ import com.amplifyframework.statemachine.Action internal interface DeleteUserActions { fun initDeleteUserAction(accessToken: String): Action + fun initiateSignOut(): Action } diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/data/SignOutData.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/data/SignOutData.kt index 427ff7cad6..05f925d2be 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/data/SignOutData.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/data/SignOutData.kt @@ -18,4 +18,5 @@ package com.amplifyframework.statemachine.codegen.data internal data class SignOutData( val globalSignOut: Boolean = false, val browserPackage: String? = null, + val bypassCancel: Boolean = false // When user deleted, even if sign out is cancelled, proceed to sign out locally ) diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/DeleteUserEvent.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/DeleteUserEvent.kt index 78a27bae84..dddfead926 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/DeleteUserEvent.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/DeleteUserEvent.kt @@ -24,9 +24,8 @@ internal class DeleteUserEvent( ) : StateMachineEvent { sealed class EventType { data class DeleteUser(val accessToken: String) : EventType() - data class UserSignedOutAndDeleted(val id: String = "") : EventType() - data class SignOutDeletedUser(val id: String = "") : EventType() - data class ThrowError(val exception: Exception) : EventType() + data class UserDeleted(val id: String = "") : EventType() + data class ThrowError(val exception: Exception, val signOutUser: Boolean) : EventType() } override val type: String = eventType.javaClass.simpleName diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/AuthenticationState.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/AuthenticationState.kt index 4add2c4860..bdfb3775e7 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/AuthenticationState.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/AuthenticationState.kt @@ -130,7 +130,8 @@ internal sealed class AuthenticationState : State { StateResolution(SigningIn(), listOf(action)) } authenticationEvent is AuthenticationEvent.EventType.SignOutRequested -> { - val action = authenticationActions.initiateSignOutAction(authenticationEvent, null) + val action = authenticationActions + .initiateSignOutAction(authenticationEvent, null) StateResolution(SigningOut(), listOf(action)) } authorizationEvent is AuthorizationEvent.EventType.StartFederationToIdentityPool -> { diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/AuthorizationState.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/AuthorizationState.kt index ce74b24b07..c3e3bd7af7 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/AuthorizationState.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/AuthorizationState.kt @@ -51,7 +51,10 @@ internal sealed class AuthorizationState : State { val refreshSessionState: RefreshSessionState ) : AuthorizationState() - data class DeletingUser(val deleteUserState: DeleteUserState) : AuthorizationState() + data class DeletingUser( + val deleteUserState: DeleteUserState, + val amplifyCredential: AmplifyCredential + ) : AuthorizationState() data class StoringCredentials(val amplifyCredential: AmplifyCredential) : AuthorizationState() data class SessionEstablished(val amplifyCredential: AmplifyCredential) : AuthorizationState() data class FederatingToIdentityPool( @@ -231,9 +234,22 @@ internal sealed class AuthorizationState : State { ) } } - is DeletingUser -> { - val resolution = deleteUserResolver.resolve(oldState.deleteUserState, event) - StateResolution(DeletingUser(resolution.newState), resolution.actions) + is DeletingUser -> when (authorizationEvent) { + is AuthorizationEvent.EventType.UserDeleted -> { + StateResolution( + SigningOut(oldState.amplifyCredential), + listOf() + ) + } + is AuthorizationEvent.EventType.ThrowError -> { + StateResolution(SessionEstablished(oldState.amplifyCredential)) + } + else -> { + val resolution = deleteUserResolver.resolve(oldState.deleteUserState, event) + StateResolution( + DeletingUser(resolution.newState, oldState.amplifyCredential), resolution.actions + ) + } } is SessionEstablished -> when { authenticationEvent is AuthenticationEvent.EventType.SignInRequested -> StateResolution(SigningIn()) @@ -242,7 +258,7 @@ internal sealed class AuthorizationState : State { StateResolution(SigningOut(oldState.amplifyCredential)) } deleteUserEvent is DeleteUserEvent.EventType.DeleteUser -> StateResolution( - DeletingUser(DeleteUserState.NotStarted()), + DeletingUser(DeleteUserState.NotStarted(), oldState.amplifyCredential), listOf(authorizationActions.initiateDeleteUser(deleteUserEvent)) ) authorizationEvent is AuthorizationEvent.EventType.RefreshSession -> { @@ -305,7 +321,7 @@ internal sealed class AuthorizationState : State { } deleteUserEvent is DeleteUserEvent.EventType.DeleteUser -> { StateResolution( - DeletingUser(DeleteUserState.NotStarted()), + DeletingUser(DeleteUserState.NotStarted(), AmplifyCredential.Empty), listOf(authorizationActions.initiateDeleteUser(deleteUserEvent)) ) } diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/DeleteUserState.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/DeleteUserState.kt index f722c48093..2d7570781d 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/DeleteUserState.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/DeleteUserState.kt @@ -26,7 +26,6 @@ import java.lang.Exception internal sealed class DeleteUserState : State { data class NotStarted(val id: String = "") : DeleteUserState() data class DeletingUser(val id: String = "") : DeleteUserState() - data class SigningOut(val id: String = "") : DeleteUserState() data class UserDeleted(val id: String = "") : DeleteUserState() data class Error(val exception: Exception) : DeleteUserState() @@ -54,14 +53,21 @@ internal sealed class DeleteUserState : State { } is DeletingUser -> { when (deleteUserEvent) { - is DeleteUserEvent.EventType.SignOutDeletedUser -> StateResolution(UserDeleted()) + is DeleteUserEvent.EventType.UserDeleted -> { + val action = deleteUserActions.initiateSignOut() + StateResolution(UserDeleted(), listOf(action)) + } is DeleteUserEvent.EventType.ThrowError -> { - StateResolution(Error(deleteUserEvent.exception)) + if (deleteUserEvent.signOutUser) { + val action = deleteUserActions.initiateSignOut() + StateResolution(UserDeleted(), listOf(action)) + } else { + StateResolution(Error(deleteUserEvent.exception)) + } } else -> StateResolution(oldState) } - } - else -> StateResolution(oldState) + } else -> StateResolution(oldState) } } } diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SignOutState.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SignOutState.kt index d8ad161bef..376c3ef0ed 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SignOutState.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SignOutState.kt @@ -29,7 +29,11 @@ import com.amplifyframework.statemachine.codegen.events.SignOutEvent internal sealed class SignOutState : State { data class NotStarted(val id: String = "") : SignOutState() - data class SigningOutHostedUI(val signedInData: SignedInData, val globalSignOut: Boolean) : SignOutState() + data class SigningOutHostedUI( + val signedInData: SignedInData, + val globalSignOut: Boolean, + val bypassCancel: Boolean + ) : SignOutState() data class SigningOutGlobally(val id: String = "") : SignOutState() data class RevokingToken(val id: String = "") : SignOutState() data class BuildingRevokeTokenError(val id: String = "") : SignOutState() @@ -49,7 +53,11 @@ internal sealed class SignOutState : State { is SignOutEvent.EventType.InvokeHostedUISignOut -> { val action = signOutActions.hostedUISignOutAction(signOutEvent) StateResolution( - SigningOutHostedUI(signOutEvent.signedInData, signOutEvent.signOutData.globalSignOut), + SigningOutHostedUI( + signOutEvent.signedInData, + signOutEvent.signOutData.globalSignOut, + signOutEvent.signOutData.bypassCancel + ), listOf(action) ) } diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPluginTest.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPluginTest.kt index 2db28e2a71..4c55943360 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPluginTest.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPluginTest.kt @@ -40,6 +40,7 @@ import aws.sdk.kotlin.services.cognitoidentityprovider.model.VerifyUserAttribute import aws.sdk.kotlin.services.cognitoidentityprovider.model.VerifyUserAttributeResponse import com.amplifyframework.auth.AuthCodeDeliveryDetails import com.amplifyframework.auth.AuthException +import com.amplifyframework.auth.AuthSession import com.amplifyframework.auth.AuthUserAttribute import com.amplifyframework.auth.AuthUserAttributeKey import com.amplifyframework.auth.cognito.exceptions.configuration.InvalidUserPoolConfigurationException @@ -199,6 +200,26 @@ class RealAWSCognitoAuthPluginTest { verify { onError.accept(expectedAuthError) } } + @Test + fun testFetchAuthSessionSucceedsIfSignedOut() { + // GIVEN + val onSuccess = mockk>() + val onError = mockk>(relaxed = true) + val currentAuthState = mockk { + every { authNState } returns AuthenticationState.SignedOut(mockk()) + every { authZState } returns AuthorizationState.Configured() + } + every { authStateMachine.getCurrentState(captureLambda()) } answers { + lambda<(AuthState) -> Unit>().invoke(currentAuthState) + } + + // WHEN + plugin.fetchAuthSession(onSuccess, onError) + + // THEN + verify(exactly = 0) { onSuccess.accept(any()) } + } + @Test fun testConfirmSignUpFailsIfNotConfigured() { // GIVEN diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTestBase.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTestBase.kt index a6c01e7b26..b6341d623a 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTestBase.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTestBase.kt @@ -37,9 +37,7 @@ import com.amplifyframework.statemachine.codegen.data.AuthConfiguration import com.amplifyframework.statemachine.codegen.data.CognitoUserPoolTokens import com.amplifyframework.statemachine.codegen.data.DeviceMetadata import com.amplifyframework.statemachine.codegen.data.LoginsMapProvider -import com.amplifyframework.statemachine.codegen.data.SignInData import com.amplifyframework.statemachine.codegen.data.SignInMethod -import com.amplifyframework.statemachine.codegen.data.SignOutData import com.amplifyframework.statemachine.codegen.data.SignedInData import com.amplifyframework.statemachine.codegen.data.SignedOutData import com.amplifyframework.statemachine.codegen.events.AuthEvent @@ -68,9 +66,6 @@ open class StateTransitionTestBase { fun uninitialized(): T = null as T } - @Mock - internal lateinit var signInData: SignInData - @Mock internal lateinit var signedInData: SignedInData @@ -485,19 +480,4 @@ open class StateTransitionTestBase { } ) } - - internal fun setupDeleteAction() { - Mockito.`when`( - mockDeleteUserActions.initDeleteUserAction(MockitoHelper.anyObject()) - ) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - AuthenticationEvent( - AuthenticationEvent.EventType.SignOutRequested(SignOutData(true)) - ) - ) - } - ) - } } diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTests.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTests.kt index 48dba44b10..f8a09bbbb3 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTests.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTests.kt @@ -24,7 +24,6 @@ import com.amplifyframework.statemachine.codegen.data.SignedOutData import com.amplifyframework.statemachine.codegen.events.AuthEvent import com.amplifyframework.statemachine.codegen.events.AuthenticationEvent import com.amplifyframework.statemachine.codegen.events.AuthorizationEvent -import com.amplifyframework.statemachine.codegen.events.DeleteUserEvent import com.amplifyframework.statemachine.codegen.events.SignInChallengeEvent import com.amplifyframework.statemachine.codegen.events.SignInEvent import com.amplifyframework.statemachine.codegen.events.SignOutEvent @@ -78,7 +77,6 @@ class StateTransitionTests : StateTransitionTestBase() { setupSRPActions() setupSignOutActions() setupFetchAuthActions() - setupDeleteAction() setupStateMachine() Dispatchers.setMain(mainThreadSurrogate) } @@ -682,56 +680,4 @@ class StateTransitionTests : StateTransitionTestBase() { assertTrue { configureLatch.await(5, TimeUnit.SECONDS) } assertTrue { testLatch.await(5, TimeUnit.SECONDS) } } - - @Test - fun testDeleteUser() { - setupConfigureSignedIn() - val configureLatch = CountDownLatch(1) - val subscribeLatch = CountDownLatch(1) - val testLatch = CountDownLatch(1) - val token = StateChangeListenerToken() - stateMachine.listen( - token, - { it -> - val authState = - it.takeIf { it is AuthState.Configured && it.authNState is AuthenticationState.SignedIn } - authState?.run { - configureLatch.countDown() - stateMachine.send( - DeleteUserEvent( - DeleteUserEvent.EventType.DeleteUser("TOKEN-123") - ) - ) - } - val signoutState = it.takeIf { it.authNState is AuthenticationState.SignedOut } - signoutState?.run { - stateMachine.send( - DeleteUserEvent( - DeleteUserEvent.EventType.SignOutDeletedUser() - ) - ) - } - val deleteUserState = (it.authZState as? AuthorizationState.DeletingUser)?.deleteUserState - val userDeletedSuccess = deleteUserState?.takeIf { - it is DeleteUserState.UserDeleted - } - - userDeletedSuccess?.run { - stateMachine.cancel(token) - testLatch.countDown() - } - }, - { - subscribeLatch.countDown() - } - ) - - assertTrue { subscribeLatch.await(5, TimeUnit.SECONDS) } - - stateMachine.send( - AuthEvent(AuthEvent.EventType.ConfigureAuth(configuration)) - ) - assertTrue { configureLatch.await(5, TimeUnit.SECONDS) } - assertTrue { testLatch.await(5, TimeUnit.SECONDS) } - } } diff --git a/aws-core/.gitignore b/aws-core/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/aws-core/.gitignore @@ -0,0 +1 @@ +/build diff --git a/aws-core/build.gradle.kts b/aws-core/build.gradle.kts new file mode 100644 index 0000000000..eb799fb7f8 --- /dev/null +++ b/aws-core/build.gradle.kts @@ -0,0 +1,50 @@ +/* + * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +plugins { + id("com.android.library") + id("kotlin-android") +} + +apply(from = rootProject.file("configuration/checkstyle.gradle")) +apply(from = rootProject.file("configuration/publishing.gradle")) + +group = properties["POM_GROUP"].toString() + +android { + kotlinOptions { + moduleName = "com.amplifyframework.aws-core" + } +} + +dependencies { + implementation(project(":core")) + implementation(dependency.kotlin.stdlib) + implementation(dependency.kotlin.coroutines) + + implementation(dependency.aws.credentials) +} + +afterEvaluate { + // Disables this warning: + // warning: listOf(classfile) MethodParameters attribute + // introduced in version 52.0 class files is ignored in + // version 51.0 class files + // Root project has -Werror, so this warning + // would fail the build, otherwise. + tasks.withType().configureEach { + options.compilerArgs.add("-Xlint:-classfile") + } +} diff --git a/aws-core/gradle.properties b/aws-core/gradle.properties new file mode 100644 index 0000000000..f5cda23871 --- /dev/null +++ b/aws-core/gradle.properties @@ -0,0 +1,4 @@ +POM_ARTIFACT_ID=aws-core +POM_NAME=Amplify Framework for Android - AWS Core +POM_DESCRIPTION=Amplify Framework for Android - AWS Core components and utilities for AWS Amplify Libraries +POM_PACKAGING=aar diff --git a/aws-core/src/main/AndroidManifest.xml b/aws-core/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..a2c4ba9f7a --- /dev/null +++ b/aws-core/src/main/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/core/src/main/java/com/amplifyframework/auth/AWSAuthSessionInternal.kt b/aws-core/src/main/java/com/amplifyframework/auth/AWSAuthSessionInternal.kt similarity index 93% rename from core/src/main/java/com/amplifyframework/auth/AWSAuthSessionInternal.kt rename to aws-core/src/main/java/com/amplifyframework/auth/AWSAuthSessionInternal.kt index 33cb2dccf8..7b98a4c56c 100644 --- a/core/src/main/java/com/amplifyframework/auth/AWSAuthSessionInternal.kt +++ b/aws-core/src/main/java/com/amplifyframework/auth/AWSAuthSessionInternal.kt @@ -14,8 +14,10 @@ */ package com.amplifyframework.auth +import com.amplifyframework.annotations.InternalApiWarning import com.amplifyframework.auth.result.AuthSessionResult +@InternalApiWarning open class AWSAuthSessionInternal( @get:JvmName("getSignedIn") open val isSignedIn: Boolean, diff --git a/core/src/main/java/com/amplifyframework/auth/AWSCognitoUserPoolTokens.kt b/aws-core/src/main/java/com/amplifyframework/auth/AWSCognitoUserPoolTokens.kt similarity index 100% rename from core/src/main/java/com/amplifyframework/auth/AWSCognitoUserPoolTokens.kt rename to aws-core/src/main/java/com/amplifyframework/auth/AWSCognitoUserPoolTokens.kt diff --git a/core/src/main/java/com/amplifyframework/auth/AWSCredentials.kt b/aws-core/src/main/java/com/amplifyframework/auth/AWSCredentials.kt similarity index 86% rename from core/src/main/java/com/amplifyframework/auth/AWSCredentials.kt rename to aws-core/src/main/java/com/amplifyframework/auth/AWSCredentials.kt index 31276197eb..8135bd4eaf 100644 --- a/core/src/main/java/com/amplifyframework/auth/AWSCredentials.kt +++ b/aws-core/src/main/java/com/amplifyframework/auth/AWSCredentials.kt @@ -15,6 +15,7 @@ package com.amplifyframework.auth +import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials import aws.smithy.kotlin.runtime.time.Instant /** @@ -85,3 +86,12 @@ class AWSTemporaryCredentials( */ val expiration: Instant ) : AWSCredentials(accessKeyId, secretAccessKey) + +internal fun AWSCredentials.toSdkCredentials(): Credentials { + return Credentials( + accessKeyId = this.accessKeyId, + secretAccessKey = this.secretAccessKey, + sessionToken = (this as? AWSTemporaryCredentials)?.sessionToken, + expiration = (this as? AWSTemporaryCredentials)?.expiration + ) +} diff --git a/aws-core/src/main/java/com/amplifyframework/auth/AWSCredentialsProvider.kt b/aws-core/src/main/java/com/amplifyframework/auth/AWSCredentialsProvider.kt new file mode 100644 index 0000000000..34c9555bdb --- /dev/null +++ b/aws-core/src/main/java/com/amplifyframework/auth/AWSCredentialsProvider.kt @@ -0,0 +1,60 @@ +/* + * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.amplifyframework.auth + +import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials +import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProvider +import com.amplifyframework.core.Consumer +import kotlin.coroutines.resume +import kotlin.coroutines.resumeWithException +import kotlin.coroutines.suspendCoroutine + +/** + * Customer provided CredentialsProvider implementation that fetches and returns AWSCredentials or a subclass such + * as AWSTemporaryCredentials. For example: + * + * class AWSTemporaryCredentialsProvider: AWSCredentialsProvider { + * override fun fetchAWSCredentials( + * onSuccess: Consumer, + * onError: Consumer + * ) { + * // customer provided fetch implementation + * } + * } + */ +interface AWSCredentialsProvider { + + fun fetchAWSCredentials( + onSuccess: Consumer<@UnsafeVariance T>, + onError: Consumer + ) +} + +fun convertToSdkCredentialsProvider( + awsCredentialsProvider: AWSCredentialsProvider +): CredentialsProvider { + + return object : CredentialsProvider { + override suspend fun getCredentials(): Credentials { + return suspendCoroutine { continuation -> + awsCredentialsProvider.fetchAWSCredentials( + { continuation.resume(it.toSdkCredentials()) }, + { continuation.resumeWithException(it) } + ) + } + } + } +} diff --git a/core/src/main/java/com/amplifyframework/auth/AuthCredentialsProvider.kt b/aws-core/src/main/java/com/amplifyframework/auth/AuthCredentialsProvider.kt similarity index 93% rename from core/src/main/java/com/amplifyframework/auth/AuthCredentialsProvider.kt rename to aws-core/src/main/java/com/amplifyframework/auth/AuthCredentialsProvider.kt index ec898cc843..21657259b9 100644 --- a/core/src/main/java/com/amplifyframework/auth/AuthCredentialsProvider.kt +++ b/aws-core/src/main/java/com/amplifyframework/auth/AuthCredentialsProvider.kt @@ -16,8 +16,10 @@ package com.amplifyframework.auth import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProvider +import com.amplifyframework.annotations.InternalApiWarning import com.amplifyframework.core.Consumer +@InternalApiWarning interface AuthCredentialsProvider : CredentialsProvider { /** * Get the identity ID of the currently logged in user if they are registered in identity pools. diff --git a/core/src/main/java/com/amplifyframework/auth/CognitoCredentialsProvider.kt b/aws-core/src/main/java/com/amplifyframework/auth/CognitoCredentialsProvider.kt similarity index 90% rename from core/src/main/java/com/amplifyframework/auth/CognitoCredentialsProvider.kt rename to aws-core/src/main/java/com/amplifyframework/auth/CognitoCredentialsProvider.kt index 6da1ee0839..a807afd05e 100644 --- a/core/src/main/java/com/amplifyframework/auth/CognitoCredentialsProvider.kt +++ b/aws-core/src/main/java/com/amplifyframework/auth/CognitoCredentialsProvider.kt @@ -36,7 +36,7 @@ open class CognitoCredentialsProvider : AuthCredentialsProvider { Amplify.Auth.fetchAuthSession( { authSession -> authSession.toAWSAuthSession()?.awsCredentialsResult?.value?.let { - continuation.resume(it.toCredentials()) + continuation.resume(it.toSdkCredentials()) } ?: continuation.resumeWithException( AuthException( "Failed to get credentials. " + @@ -98,12 +98,3 @@ open class CognitoCredentialsProvider : AuthCredentialsProvider { private fun AuthSession.toAWSAuthSession(): AWSAuthSessionInternal? { return this as? AWSAuthSessionInternal } - -private fun AWSCredentials.toCredentials(): Credentials { - return Credentials( - accessKeyId = this.accessKeyId, - secretAccessKey = this.secretAccessKey, - sessionToken = (this as? AWSTemporaryCredentials)?.sessionToken, - expiration = (this as? AWSTemporaryCredentials)?.expiration - ) -} diff --git a/aws-datastore/build.gradle.kts b/aws-datastore/build.gradle.kts index 38a8e73535..b5cd1ee15f 100644 --- a/aws-datastore/build.gradle.kts +++ b/aws-datastore/build.gradle.kts @@ -25,6 +25,7 @@ group = properties["POM_GROUP"].toString() dependencies { implementation(project(":core")) + implementation(project(":aws-core")) implementation(project(":aws-api-appsync")) implementation(dependency.androidx.appcompat) diff --git a/aws-geo-location/build.gradle.kts b/aws-geo-location/build.gradle.kts index 5e72d4a9b6..cd0a88b81b 100644 --- a/aws-geo-location/build.gradle.kts +++ b/aws-geo-location/build.gradle.kts @@ -24,6 +24,7 @@ group = properties["POM_GROUP"].toString() dependencies { implementation(project(":core")) + implementation(project(":aws-core")) implementation(dependency.aws.location) testImplementation(project(":testutils")) diff --git a/aws-geo-location/src/main/java/com/amplifyframework/geo/location/AWSLocationGeoPlugin.kt b/aws-geo-location/src/main/java/com/amplifyframework/geo/location/AWSLocationGeoPlugin.kt index 5519cda7c2..2f20108069 100644 --- a/aws-geo-location/src/main/java/com/amplifyframework/geo/location/AWSLocationGeoPlugin.kt +++ b/aws-geo-location/src/main/java/com/amplifyframework/geo/location/AWSLocationGeoPlugin.kt @@ -19,6 +19,7 @@ import android.content.Context import aws.sdk.kotlin.services.location.LocationClient import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProvider import com.amplifyframework.AmplifyException +import com.amplifyframework.annotations.InternalApiWarning import com.amplifyframework.auth.AuthCategory import com.amplifyframework.auth.CognitoCredentialsProvider import com.amplifyframework.core.Amplify @@ -64,6 +65,7 @@ class AWSLocationGeoPlugin( configuration.searchIndices!!.default } + @InternalApiWarning val credentialsProvider: CredentialsProvider by lazy { CognitoCredentialsProvider() } diff --git a/aws-predictions-tensorflow/build.gradle.kts b/aws-predictions-tensorflow/build.gradle.kts index 8e0b5dec62..25cef8c9c1 100644 --- a/aws-predictions-tensorflow/build.gradle.kts +++ b/aws-predictions-tensorflow/build.gradle.kts @@ -25,6 +25,7 @@ group = properties["POM_GROUP"].toString() dependencies { implementation(project(":core")) + implementation(project(":aws-core")) implementation(dependency.androidx.appcompat) implementation(dependency.tensorflow) diff --git a/aws-predictions/build.gradle.kts b/aws-predictions/build.gradle.kts index 3648bdec72..f2ec25cf9a 100644 --- a/aws-predictions/build.gradle.kts +++ b/aws-predictions/build.gradle.kts @@ -25,6 +25,7 @@ group = properties["POM_GROUP"].toString() dependencies { implementation(project(":core")) + implementation(project(":aws-core")) implementation(dependency.androidx.appcompat) implementation(dependency.aws.comprehend) implementation(dependency.aws.polly) diff --git a/aws-push-notifications-pinpoint/build.gradle.kts b/aws-push-notifications-pinpoint/build.gradle.kts index 8afac0069b..e4153e9bfa 100644 --- a/aws-push-notifications-pinpoint/build.gradle.kts +++ b/aws-push-notifications-pinpoint/build.gradle.kts @@ -25,7 +25,7 @@ group = properties["POM_GROUP"].toString() dependencies { implementation(project(":core")) - implementation(project(":aws-auth-cognito")) + implementation(project(":aws-core")) implementation(project(":aws-pinpoint-core")) api(project(":aws-push-notifications-pinpoint-utils")) diff --git a/aws-push-notifications-pinpoint/src/main/AndroidManifest.xml b/aws-push-notifications-pinpoint/src/main/AndroidManifest.xml index 61b6d00aae..4effc86390 100644 --- a/aws-push-notifications-pinpoint/src/main/AndroidManifest.xml +++ b/aws-push-notifications-pinpoint/src/main/AndroidManifest.xml @@ -15,7 +15,7 @@ --> + package="com.amplifyframework.pushnotifications.pinpoint"> diff --git a/aws-push-notifications-pinpoint/src/main/java/com/amplifyframework/pushnotifications/pinpoint/AWSPinpointPushNotificationsPlugin.kt b/aws-push-notifications-pinpoint/src/main/java/com/amplifyframework/pushnotifications/pinpoint/AWSPinpointPushNotificationsPlugin.kt index fd5e097605..7b57bf70db 100644 --- a/aws-push-notifications-pinpoint/src/main/java/com/amplifyframework/pushnotifications/pinpoint/AWSPinpointPushNotificationsPlugin.kt +++ b/aws-push-notifications-pinpoint/src/main/java/com/amplifyframework/pushnotifications/pinpoint/AWSPinpointPushNotificationsPlugin.kt @@ -26,7 +26,6 @@ import aws.smithy.kotlin.runtime.http.interceptors.HttpInterceptor import com.amplifyframework.AmplifyException import com.amplifyframework.analytics.UserProfile import com.amplifyframework.auth.CognitoCredentialsProvider -import com.amplifyframework.auth.cognito.BuildConfig import com.amplifyframework.core.Action import com.amplifyframework.core.Amplify import com.amplifyframework.core.Consumer diff --git a/aws-storage-s3/build.gradle.kts b/aws-storage-s3/build.gradle.kts index 601506f988..3ebe967e09 100644 --- a/aws-storage-s3/build.gradle.kts +++ b/aws-storage-s3/build.gradle.kts @@ -25,6 +25,7 @@ group = properties["POM_GROUP"].toString() dependencies { implementation(project(":core")) + implementation(project(":aws-core")) implementation(dependency.androidx.appcompat) implementation(dependency.aws.s3) diff --git a/aws-storage-s3/src/main/java/com/amplifyframework/storage/s3/AWSS3StoragePlugin.java b/aws-storage-s3/src/main/java/com/amplifyframework/storage/s3/AWSS3StoragePlugin.java index 4f354a6fd4..8f47e082c8 100644 --- a/aws-storage-s3/src/main/java/com/amplifyframework/storage/s3/AWSS3StoragePlugin.java +++ b/aws-storage-s3/src/main/java/com/amplifyframework/storage/s3/AWSS3StoragePlugin.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -17,8 +17,10 @@ import android.content.Context; import androidx.annotation.NonNull; +import androidx.annotation.OptIn; import androidx.annotation.VisibleForTesting; +import com.amplifyframework.annotations.InternalApiWarning; import com.amplifyframework.auth.AuthCredentialsProvider; import com.amplifyframework.auth.CognitoCredentialsProvider; import com.amplifyframework.core.Consumer; @@ -107,6 +109,7 @@ public final class AWSS3StoragePlugin extends StoragePlugin { * Constructs the AWS S3 Storage Plugin initializing the executor service. */ @SuppressWarnings("unused") // This is a public API. + @OptIn(markerClass = InternalApiWarning.class) public AWSS3StoragePlugin() { this(new CognitoCredentialsProvider()); } @@ -117,6 +120,7 @@ public AWSS3StoragePlugin() { * @param awsS3StoragePluginConfiguration storage plugin configuration */ @SuppressWarnings("unused") // This is a public API. + @OptIn(markerClass = InternalApiWarning.class) public AWSS3StoragePlugin(AWSS3StoragePluginConfiguration awsS3StoragePluginConfiguration) { this(new CognitoCredentialsProvider(), awsS3StoragePluginConfiguration); } diff --git a/build.gradle.kts b/build.gradle.kts index 5144d811ba..fc0deb7197 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,6 +15,7 @@ import com.android.build.gradle.LibraryExtension import org.jetbrains.dokka.gradle.DokkaTask +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile buildscript { repositories { @@ -64,6 +65,10 @@ tasks.register("clean").configure { delete(rootProject.buildDir) } +val optInAnnotations = listOf( + "com.amplifyframework.annotations.InternalApiWarning" +) + subprojects { apply(plugin = "org.jlleitschuh.gradle.ktlint") @@ -100,6 +105,14 @@ subprojects { failOnPassedAfterRetry.set(true) } } + + tasks.withType { + kotlinOptions { + optInAnnotations.forEach { + freeCompilerArgs += "-opt-in=$it" + } + } + } } @Suppress("ExpiredTargetSdkVersion") diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 38539d51d7..8cfdddfbef 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -31,6 +31,7 @@ android { } dependencies { + api(project(":annotations")) implementation(dependency.androidx.v4support) implementation(dependency.androidx.annotation) implementation(dependency.androidx.nav.fragment) @@ -38,8 +39,6 @@ dependencies { implementation(dependency.androidx.security) implementation(dependency.kotlin.serializationJson) - implementation(dependency.aws.credentials) - testImplementation(project(":aws-api-appsync")) // Used to reference Temporal types in tests. testImplementation(project(":testmodels")) diff --git a/core/src/main/java/com/amplifyframework/auth/AuthCategoryBehavior.java b/core/src/main/java/com/amplifyframework/auth/AuthCategoryBehavior.java index d2bde4e990..82d7254ca7 100644 --- a/core/src/main/java/com/amplifyframework/auth/AuthCategoryBehavior.java +++ b/core/src/main/java/com/amplifyframework/auth/AuthCategoryBehavior.java @@ -48,7 +48,6 @@ * Specifies the behavior for the Auth category. */ public interface AuthCategoryBehavior { - /** * Creates a new user account with the specified username and password. * Can also pass in user attributes to associate with the user through diff --git a/core/src/main/java/com/amplifyframework/notifications/pushnotifications/NotificationPayload.kt b/core/src/main/java/com/amplifyframework/notifications/pushnotifications/NotificationPayload.kt index 17dd22d442..31a9a74f2d 100644 --- a/core/src/main/java/com/amplifyframework/notifications/pushnotifications/NotificationPayload.kt +++ b/core/src/main/java/com/amplifyframework/notifications/pushnotifications/NotificationPayload.kt @@ -16,7 +16,6 @@ package com.amplifyframework.notifications.pushnotifications import android.os.Parcelable -import java.util.UUID import kotlinx.parcelize.Parcelize @Parcelize diff --git a/settings.gradle.kts b/settings.gradle.kts index 2e00855fb3..e847b9393d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -138,7 +138,9 @@ dependencyResolutionManagement { } } +include(":annotations") include(":core") +include(":aws-core") // Plugin Modules include(":aws-analytics-pinpoint")