-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(auth): Add aws-core and AWSCredentialsProvider #2316
Changes from 17 commits
7f5029f
2b0a99e
0c49f26
4a161c9
004fd0d
502f187
c0a4037
6e71778
64d6572
647e6fe
7cf253e
5cc041e
8d6caba
d9eca6c
3b0eefb
944a722
e4f1a82
edd402c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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") | ||
} | ||
} |
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 |
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> | ||
|
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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") | ||
} | ||
} |
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 |
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> | ||
|
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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think this needs to be publicly exposed. If the goal is to pass AWSCredentialsProvider to other components and SDK CredentialsProvider is always accessible through escape hatch, I dont see a reason for this conversion API. Maybe start with non-public and if customers need it we can exposed it in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @div5yesh The reason I exposed is because I don't think we want customers having to use multiple credentials providers, or at least, having to create their own AWSCredentialsProvider and SDKs CredentialsProvider. Our suggested implementation should be to create a single AWSCredentialsProvider, and when that is needed for the Kotlin SDK escape hatch, they can use this public conversion method. |
||
awsCredentialsProvider: AWSCredentialsProvider<T> | ||
): CredentialsProvider { | ||
|
||
return object : CredentialsProvider { | ||
override suspend fun getCredentials(): Credentials { | ||
return suspendCoroutine { continuation -> | ||
awsCredentialsProvider.fetchAWSCredentials( | ||
{ continuation.resume(it.toSdkCredentials()) }, | ||
{ continuation.resumeWithException(it) } | ||
) | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to get thoughts on usage of
@UnsafeVariance
here, rather than usingin
. Whilein
is technically correct, it forces customers to use a non obviousConsumer<in AWSTemporaryCredentials
in onSuccess and Java users to typeConsumer<super ? AWSTemporaryCredentials>
.UnsafeVariance still provides compile time safety here and appears to be commonly used in Kotlin Std Lib, such as List implementation.