Skip to content

Commit

Permalink
feat(auth): add options to updateAttribute, updateAttributes, resendU…
Browse files Browse the repository at this point in the history
…serAttributeConfirmationCode (#775)

* chore: move attribute types to new dir

* chore: rename fetch attribute classes

* feat: add client metadata to user attribute methods

* deprecate renamed types

* chore: update comments for consistency

* chore: rename methods, tests

* chore: break out depracted classes, make new classes abstract

* chore: revert star import

* chore: bump amplify-android to 1.24.0

* chore: apply suggestions from code review

* chore: remove empty line
  • Loading branch information
Jordan-Nelson authored Aug 17, 2021
1 parent 0bad2d7 commit 924861a
Show file tree
Hide file tree
Showing 36 changed files with 659 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ public class AuthCognito : FlutterPlugin, ActivityAware, MethodCallHandler, Plug
var req = FlutterUpdateUserAttributeRequest(request)
Amplify.Auth.updateUserAttribute(
req.attribute,
req.options,
{ result -> prepareUpdateUserAttributeResult(flutterResult, result) },
{ error -> errorHandler.handleAuthError(flutterResult, error) }
);
Expand All @@ -478,6 +479,7 @@ public class AuthCognito : FlutterPlugin, ActivityAware, MethodCallHandler, Plug
var req = FlutterUpdateUserAttributesRequest(request)
Amplify.Auth.updateUserAttributes(
req.attributes,
req.options,
{ result -> prepareUpdateUserAttributesResult(flutterResult, result) },
{ error -> errorHandler.handleAuthError(flutterResult, error) }
);
Expand Down Expand Up @@ -507,6 +509,7 @@ public class AuthCognito : FlutterPlugin, ActivityAware, MethodCallHandler, Plug
var req = FlutterResendUserAttributeConfirmationCodeRequest(request)
Amplify.Auth.resendUserAttributeConfirmationCode(
req.userAttributeKey,
req.options,
{ result -> prepareResendUserAttributeConfirmationCodeResult(flutterResult, result) },
{ error -> errorHandler.handleAuthError(flutterResult, error) }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@
package com.amazonaws.amplify.amplify_auth_cognito.types

import com.amazonaws.amplify.amplify_auth_cognito.utils.createAuthUserAttributeKey
import com.amplifyframework.auth.AuthUserAttributeKey
import com.amazonaws.amplify.amplify_core.exception.ExceptionMessages
import com.amazonaws.amplify.amplify_core.exception.InvalidRequestException
import com.amplifyframework.auth.AuthUserAttributeKey
import com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendUserAttributeConfirmationCodeOptions

data class FlutterResendUserAttributeConfirmationCodeRequest(val map: HashMap<String, *>) {
val userAttributeKey: AuthUserAttributeKey = createAuthUserAttributeKey(map["userAttributeKey"] as String);
val options: AWSCognitoAuthResendUserAttributeConfirmationCodeOptions = createOptions(map["options"] as HashMap<String, Any>?)

private fun createOptions(rawOptions: HashMap<String, *>?): AWSCognitoAuthResendUserAttributeConfirmationCodeOptions {
val optionsBuilder = AWSCognitoAuthResendUserAttributeConfirmationCodeOptions.builder();
if (rawOptions?.get("clientMetadata") != null) {
optionsBuilder.metadata(rawOptions["clientMetadata"] as HashMap<String, String>);
}
return optionsBuilder.build();
}

companion object {
private const val validationErrorMessage: String = "ResendUserAttributeConfirmationCode Request malformed."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,28 @@ import com.amazonaws.amplify.amplify_auth_cognito.utils.validateUserAttribute
import com.amazonaws.amplify.amplify_core.exception.ExceptionMessages
import com.amazonaws.amplify.amplify_core.exception.InvalidRequestException
import com.amplifyframework.auth.AuthUserAttribute
import com.amplifyframework.auth.cognito.options.AWSCognitoAuthUpdateUserAttributeOptions

data class FlutterUpdateUserAttributeRequest(val map: HashMap<String, *>) {

val attribute: AuthUserAttribute = formatUpdateUserAttribute(map["attribute"] as HashMap<String, *>);
val attribute: AuthUserAttribute = createAttribute(map["attribute"] as HashMap<String, *>);
val options: AWSCognitoAuthUpdateUserAttributeOptions = createOptions(map["options"] as HashMap<String, Any>?)

private fun formatUpdateUserAttribute(@NonNull rawAttribute: HashMap<String, *>): AuthUserAttribute {
private fun createAttribute(@NonNull rawAttribute: HashMap<String, *>): AuthUserAttribute {
val value = rawAttribute["value"].toString();
val key: String = rawAttribute["userAttributeKey"] as String;
val attribute: AuthUserAttribute = createAuthUserAttribute(key, value);
return attribute;
}

private fun createOptions(rawOptions: HashMap<String, *>?): AWSCognitoAuthUpdateUserAttributeOptions {
val optionsBuilder = AWSCognitoAuthUpdateUserAttributeOptions.builder();
if (rawOptions?.get("clientMetadata") != null) {
optionsBuilder.metadata(rawOptions["clientMetadata"] as HashMap<String, String>);
}
return optionsBuilder.build();
}

companion object {
private const val validationErrorMessage: String = "UpdateUserAttributeRequest Request malformed."
fun validate(req: HashMap<String, *>?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,23 @@ import com.amazonaws.amplify.amplify_auth_cognito.utils.validateUserAttribute
import com.amazonaws.amplify.amplify_core.exception.ExceptionMessages
import com.amazonaws.amplify.amplify_core.exception.InvalidRequestException
import com.amplifyframework.auth.AuthUserAttribute
import com.amplifyframework.auth.cognito.options.AWSCognitoAuthUpdateUserAttributesOptions

data class FlutterUpdateUserAttributesRequest(val map: HashMap<String, *>) {

val attributes: List<AuthUserAttribute> = (map["attributes"] as List<HashMap<*, *>>)
.map { createAuthUserAttribute(it["userAttributeKey"] as String, it["value"] as String) }

val options: AWSCognitoAuthUpdateUserAttributesOptions = createOptions(map["options"] as HashMap<String, Any>?)

private fun createOptions(rawOptions: HashMap<String, *>?): AWSCognitoAuthUpdateUserAttributesOptions {
val optionsBuilder = AWSCognitoAuthUpdateUserAttributesOptions.builder();
if (rawOptions?.get("clientMetadata") != null) {
optionsBuilder.metadata(rawOptions["clientMetadata"] as HashMap<String, String>);
}
return optionsBuilder.build();
}

companion object {
private const val validationErrorMessage: String = "UpdateUserAttributesRequest Request malformed."
fun validate(req: HashMap<String, *>?) {
Expand Down
Loading

0 comments on commit 924861a

Please sign in to comment.