From 988070ad3906e542349788aee5885970d738257e Mon Sep 17 00:00:00 2001 From: Kirill Zhukov Date: Thu, 18 May 2023 16:11:28 -0700 Subject: [PATCH] Add customAuth API (#61) --- .../liftric/cognito/idp/IdentityProviderClient.kt | 12 ++++++++++++ .../kotlin/com/liftric/cognito/idp/core/Constants.kt | 3 ++- .../com/liftric/cognito/idp/core/IdentityProvider.kt | 8 ++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/com/liftric/cognito/idp/IdentityProviderClient.kt b/src/commonMain/kotlin/com/liftric/cognito/idp/IdentityProviderClient.kt index a24b549..cf7b675 100644 --- a/src/commonMain/kotlin/com/liftric/cognito/idp/IdentityProviderClient.kt +++ b/src/commonMain/kotlin/com/liftric/cognito/idp/IdentityProviderClient.kt @@ -70,6 +70,18 @@ open class IdentityProviderClient(region: String, clientId: String, engine: Http ) ) + override suspend fun customAuth( + username: String, + password: String, + ): Result = request( + Request.SignIn, + SignIn( + AuthFlow = Authentication.CustomAuth.flow, + ClientId = configuration.clientId, + AuthParameters = SignIn.Parameters(username, password) + ) + ) + override suspend fun resendConfirmationCode( username: String ): Result = request( diff --git a/src/commonMain/kotlin/com/liftric/cognito/idp/core/Constants.kt b/src/commonMain/kotlin/com/liftric/cognito/idp/core/Constants.kt index 85a12cb..06ab6be 100644 --- a/src/commonMain/kotlin/com/liftric/cognito/idp/core/Constants.kt +++ b/src/commonMain/kotlin/com/liftric/cognito/idp/core/Constants.kt @@ -16,7 +16,8 @@ internal object Header { internal enum class Authentication(val flow: String) { RefreshTokenAuth("REFRESH_TOKEN_AUTH"), - UserPasswordAuth("USER_PASSWORD_AUTH") + UserPasswordAuth("USER_PASSWORD_AUTH"), + CustomAuth("CUSTOM_AUTH"), } internal enum class Request(val value: String) { diff --git a/src/commonMain/kotlin/com/liftric/cognito/idp/core/IdentityProvider.kt b/src/commonMain/kotlin/com/liftric/cognito/idp/core/IdentityProvider.kt index 3bc8454..e044e3e 100644 --- a/src/commonMain/kotlin/com/liftric/cognito/idp/core/IdentityProvider.kt +++ b/src/commonMain/kotlin/com/liftric/cognito/idp/core/IdentityProvider.kt @@ -18,6 +18,14 @@ interface IdentityProvider { */ suspend fun confirmSignUp(username: String, confirmationCode: String): Result + /** + * Signs in the user with the given parameters using custom authentication flow. + * @param username The username + * @param password The password + * @return Result object containing SignInResponse on success or an error on failure + */ + suspend fun customAuth(username: String, password: String): Result + /** * Resends the confirmation (for confirmation of registration) to a specific user in the user pool. * @param username The username