Skip to content
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

Custom Auth user signup returns NotAuthorizedException #1650

Closed
2 of 9 tasks
twink1e opened this issue May 29, 2022 · 4 comments
Closed
2 of 9 tasks

Custom Auth user signup returns NotAuthorizedException #1650

twink1e opened this issue May 29, 2022 · 4 comments
Labels
auth Issues related to the Auth Category pending-community-response Pending response from the issue opener or other community members pending-triage This issue is in the backlog of issues to triage

Comments

@twink1e
Copy link

twink1e commented May 29, 2022

Description

We have just switched from email/password authentication to custom auth, after #410 was released.

However, when I call

SignUpResult res = await Amplify.Auth.signUp(
          username: "name",
          password: "password",
          options: CognitoSignUpOptions(userAttributes: {
            CognitoUserAttributeKey.custom('email'): 'a123@gmail.com'
          }));

it returns

Unhandled Exception: NotAuthorizedException(message: A client attempted to write unauthorized attribute, recoverySuggestion: Check whether the given values are correct and the user is authorized to perform the operation., underlyingException: null)

Our cognito user pool was configured to have a mandatory email attribute.
image

Changes I have made to change into custom auth:

  1. use "authenticationFlowType": "CUSTOM_AUTH" in amplifyconfiguration.dart
  2. added "Define Auth Challenge" trigger like suggested in https://docs.amplify.aws/lib/auth/signin_with_custom_flow/q/platform/flutter/
exports.handler = async function(event) {
  if (
    event.request.session.length == 1 &&
    event.request.session[0].challengeName == 'SRP_A'
  ) {
    event.response.issueTokens = false;
    event.response.failAuthentication = false;
    event.response.challengeName = 'CUSTOM_CHALLENGE';
  } else if (
    event.request.session.length == 2 &&
    event.request.session[1].challengeName == 'CUSTOM_CHALLENGE' &&
    event.request.session[1].challengeResult == true
  ) {
    event.response.issueTokens = true;
    event.response.failAuthentication = false;
    event.response.challengeName = 'CUSTOM_CHALLENGE';
  } else {
    event.response.issueTokens = false;
    event.response.failAuthentication = true;
  }
  return event;
};
  1. added "Pre sign-up" trigger, but it doesn't seem to have reached here
module.exports.handler = async event => {
  event.response.autoConfirmUser = true;
  return event;
};

I'm confused about which unauthorized attribute I was writing, as it used to work in 0.2.5 and USER_SRP_AUTH

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Storage

Steps to Reproduce

No response

Screenshots

No response

Platforms

  • iOS
  • Android

Android Device/Emulator API Level

No response

Environment

[✓] Flutter (Channel stable, 2.8.1, on macOS 11.6.3 20G415 darwin-x64, locale en-GB)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 13.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] Android Studio (version 2020.3)
[✓] IntelliJ IDEA Community Edition (version 2021.1)
[✓] VS Code (version 1.67.1)
[✓] Connected device (2 available)

Dependencies

Dart SDK 2.15.1
Flutter SDK 2.8.1
dependencies:
- amplify_auth_cognito 0.5.1 [amplify_auth_cognito_android amplify_auth_cognito_ios amplify_auth_plugin_interface amplify_core collection flutter plugin_platform_interface]
- amplify_flutter 0.5.1 [amplify_analytics_plugin_interface amplify_api_plugin_interface amplify_auth_plugin_interface amplify_core amplify_datastore_plugin_interface amplify_flutter_android amplify_flutter_ios amplify_storage_plugin_interface collection flutter json_annotation meta plugin_platform_interface]
- amplify_storage_s3 0.5.1 [flutter amplify_storage_plugin_interface plugin_platform_interface amplify_storage_s3_android amplify_storage_s3_ios amplify_core]
- common_utils 1.2.4 [decimal crypto convert]
- cupertino_icons 0.1.3
- dio 4.0.6 [http_parser path]
- drag_container 1.0.2 [flutter]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_native_image 0.0.6+1 [flutter]
- flutter_swiper 1.1.6 [flutter transformer_page_view flutter_page_indicator]
- flutter_uxcam 2.1.1 [flutter]
- fluttertoast 8.0.9 [flutter flutter_web_plugins]
- http 0.13.4 [async http_parser meta path]
- image_picker 0.8.5+3 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_platform_interface]
- intl 0.16.1 [path]
- path_provider 2.0.10 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
- permission_handler 8.3.0 [flutter meta permission_handler_platform_interface]
- provider 4.3.3 [collection flutter nested]
- shared_preferences 2.0.15 [flutter shared_preferences_android shared_preferences_ios shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- url_launcher 6.1.2 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- walletconnect_dart 0.0.10 [web_socket_channel uuid cryptography convert json_annotation stack_trace]

transitive dependencies:
- amplify_analytics_plugin_interface 0.5.1 [amplify_core flutter meta]
- amplify_api_plugin_interface 0.5.1 [amplify_core collection flutter json_annotation meta]
- amplify_auth_cognito_android 0.5.1 [flutter]
- amplify_auth_cognito_ios 0.5.1 [amplify_core flutter]
- amplify_auth_plugin_interface 0.5.1 [amplify_core flutter meta]
- amplify_core 0.5.1 [collection date_time_format flutter meta plugin_platform_interface uuid]
- amplify_datastore_plugin_interface 0.5.1 [flutter meta collection amplify_core]
- amplify_flutter_android 0.5.1 [flutter]
- amplify_flutter_ios 0.5.1 [amplify_core flutter]
- amplify_storage_plugin_interface 0.5.1 [flutter meta amplify_core]
- amplify_storage_s3_android 0.5.1 [flutter]
- amplify_storage_s3_ios 0.5.1 [flutter]
- async 2.8.2 [collection meta]
- characters 1.2.0
- charcode 1.3.1
- collection 1.15.0
- convert 3.0.1 [typed_data]
- cross_file 0.3.3+1 [js meta]
- crypto 3.0.2 [typed_data]
- cryptography 2.0.5 [collection crypto fixnum js meta typed_data]
- date_time_format 2.0.1
- decimal 2.2.0 [rational]
- ffi 1.2.1
- file 6.1.2 [meta path]
- fixnum 1.0.1
- flutter_page_indicator 0.0.3 [flutter]
- flutter_plugin_android_lifecycle 2.0.6 [flutter]
- flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math]
- http_parser 4.0.1 [collection source_span string_scanner typed_data]
- image_picker_android 0.8.4+13 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- image_picker_for_web 2.1.8 [flutter flutter_web_plugins image_picker_platform_interface]
- image_picker_ios 0.8.5+5 [flutter image_picker_platform_interface]
- image_picker_platform_interface 2.5.0 [cross_file flutter http plugin_platform_interface]
- js 0.6.3
- json_annotation 4.5.0 [meta]
- meta 1.7.0
- nested 1.0.0 [flutter]
- path 1.8.0
- path_provider_android 2.0.14 [flutter path_provider_platform_interface]
- path_provider_ios 2.0.9 [flutter path_provider_platform_interface]
- path_provider_linux 2.1.7 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_macos 2.0.6 [flutter path_provider_platform_interface]
- path_provider_platform_interface 2.0.4 [flutter platform plugin_platform_interface]
- path_provider_windows 2.0.7 [ffi flutter path path_provider_platform_interface win32]
- permission_handler_platform_interface 3.7.0 [flutter meta plugin_platform_interface]
- platform 3.1.0
- plugin_platform_interface 2.1.2 [meta]
- process 4.2.4 [file path platform]
- rational 2.2.0
- shared_preferences_android 2.0.12 [flutter shared_preferences_platform_interface]
- shared_preferences_ios 2.1.1 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.1.1 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]
- shared_preferences_macos 2.0.4 [flutter shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.0.0 [flutter]
- shared_preferences_web 2.0.4 [flutter flutter_web_plugins shared_preferences_platform_interface]
- shared_preferences_windows 2.1.1 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- sky_engine 0.0.99
- source_span 1.8.1 [collection path term_glyph]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- string_scanner 1.1.0 [charcode source_span]
- term_glyph 1.2.0
- transformer_page_view 0.1.6 [flutter]
- typed_data 1.3.0 [collection]
- url_launcher_android 6.0.17 [flutter url_launcher_platform_interface]
- url_launcher_ios 6.0.17 [flutter url_launcher_platform_interface]
- url_launcher_linux 3.0.1 [flutter url_launcher_platform_interface]
- url_launcher_macos 3.0.1 [flutter url_launcher_platform_interface]
- url_launcher_platform_interface 2.0.5 [flutter plugin_platform_interface]
- url_launcher_web 2.0.7 [flutter flutter_web_plugins url_launcher_platform_interface]
- url_launcher_windows 3.0.1 [flutter url_launcher_platform_interface]
- uuid 3.0.6 [crypto]
- vector_math 2.1.1
- web_socket_channel 2.2.0 [async crypto stream_channel]
- win32 2.5.2 [ffi]
- xdg_directories 0.2.0+1 [meta path process]

Device

iphone 13 pro max

OS

iOS 15.1

CLI Version

8.3.1

Additional Context

No response

@Jordan-Nelson
Copy link
Member

Hi @twink1e - Were you using 'CognitoUserAttributeKey.custom('email')' previously? '.custom' is intended for custom attributes, but email is a standard attribute. If you are trying to add an email you should be able to use 'CognitoUserAttributeKey.email'.

@Jordan-Nelson Jordan-Nelson added auth Issues related to the Auth Category pending-triage This issue is in the backlog of issues to triage pending-community-response Pending response from the issue opener or other community members labels May 31, 2022
@haverchuck
Copy link
Contributor

haverchuck commented May 31, 2022

Hi @twink1e - Did @Jordan-Nelson 's suggestion work for you? If not, did you set up your triggers using the Amplify CLI?

@twink1e
Copy link
Author

twink1e commented Jun 1, 2022

Hi @twink1e - Were you using 'CognitoUserAttributeKey.custom('email')' previously? '.custom' is intended for custom attributes, but email is a standard attribute. If you are trying to add an email you should be able to use 'CognitoUserAttributeKey.email'.

Hi @Jordan-Nelson thanks that's indeed the problem. I wasn't careful with the changes in writing the attribute key when upgrading from verison 0.2.5 to 0.5.1.
Thank you so much!

@twink1e twink1e closed this as completed Jun 1, 2022
@twink1e
Copy link
Author

twink1e commented Jun 1, 2022

Hi @twink1e - Did @Jordan-Nelson 's suggestion work for you? If not, did you set up your triggers using the Amplify CLI?

@haverchuck Hi, thanks for checking! It worked and I set up my triggers on the Cognito user pool console

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth Issues related to the Auth Category pending-community-response Pending response from the issue opener or other community members pending-triage This issue is in the backlog of issues to triage
Projects
None yet
Development

No branches or pull requests

3 participants