-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): Add aws-core and AWSCredentialsProvider (#2316)
Co-authored-by: Tim Schmelter <[email protected]> Co-authored-by: Erica Eaton <[email protected]> Co-authored-by: Divyesh Chitroda <[email protected]>
- Loading branch information
1 parent
3d4336f
commit d0dd5e6
Showing
29 changed files
with
290 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<JavaCompile>().configureEach { | ||
options.compilerArgs.add("-Xlint:-classfile") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
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. | ||
--> | ||
|
||
<manifest package="com.amplifyframework.annotations" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
</manifest> | ||
|
37 changes: 37 additions & 0 deletions
37
annotations/src/main/java/com/amplifyframework/annotations/InternalApiWarning.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<JavaCompile>().configureEach { | ||
options.compilerArgs.add("-Xlint:-classfile") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
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. | ||
--> | ||
|
||
<manifest package="com.amplifyframework.aws.core" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
</manifest> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
aws-core/src/main/java/com/amplifyframework/auth/AWSCredentialsProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<AWSTemporaryCredentials> { | ||
* override fun fetchAWSCredentials( | ||
* onSuccess: Consumer<AWSTemporaryCredentials>, | ||
* onError: Consumer<AuthException> | ||
* ) { | ||
* // customer provided fetch implementation | ||
* } | ||
* } | ||
*/ | ||
interface AWSCredentialsProvider<out T : AWSCredentials> { | ||
|
||
fun fetchAWSCredentials( | ||
onSuccess: Consumer<@UnsafeVariance T>, | ||
onError: Consumer<AuthException> | ||
) | ||
} | ||
|
||
fun <T : AWSCredentials> convertToSdkCredentialsProvider( | ||
awsCredentialsProvider: AWSCredentialsProvider<T> | ||
): CredentialsProvider { | ||
|
||
return object : CredentialsProvider { | ||
override suspend fun getCredentials(): Credentials { | ||
return suspendCoroutine { continuation -> | ||
awsCredentialsProvider.fetchAWSCredentials( | ||
{ continuation.resume(it.toSdkCredentials()) }, | ||
{ continuation.resumeWithException(it) } | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.