aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.44k stars 2.13k forks source link

Unable to resolve InvalidRedirectException #12816

Closed mattekelly closed 9 months ago

mattekelly commented 10 months ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Authentication

Amplify Version

v6

Amplify Categories

auth

Backend

Other

Environment information

``` # Put output below this line System: OS: macOS 14.1.1 CPU: (8) arm64 Apple M1 Pro Memory: 84.69 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 18.17.0 - ~/.nvm/versions/node/v18.17.0/bin/node npm: 10.2.3 - ~/.nvm/versions/node/v18.17.0/bin/npm Watchman: 2023.05.08.00 - /opt/homebrew/bin/watchman Browsers: Brave Browser: 120.1.61.114 Safari: 17.1 npmPackages: @apollo/client: 3.8.8 => 3.8.8 @apollo/client/cache: undefined () @apollo/client/core: undefined () @apollo/client/dev: undefined () @apollo/client/errors: undefined () @apollo/client/link/batch: undefined () @apollo/client/link/batch-http: undefined () @apollo/client/link/context: undefined () @apollo/client/link/core: undefined () @apollo/client/link/error: undefined () @apollo/client/link/http: undefined () @apollo/client/link/persisted-queries: undefined () @apollo/client/link/remove-typename: undefined () @apollo/client/link/retry: undefined () @apollo/client/link/schema: undefined () @apollo/client/link/subscriptions: undefined () @apollo/client/link/utils: undefined () @apollo/client/link/ws: undefined () @apollo/client/react: undefined () @apollo/client/react/components: undefined () @apollo/client/react/context: undefined () @apollo/client/react/hoc: undefined () @apollo/client/react/hooks: undefined () @apollo/client/react/parser: undefined () @apollo/client/react/ssr: undefined () @apollo/client/testing: undefined () @apollo/client/testing/core: undefined () @apollo/client/utilities: undefined () @apollo/client/utilities/globals: undefined () @aws-amplify/react-native: ^1.0.10 => 1.0.10 @aws-amplify/rtn-web-browser: ^1.0.10 => 1.0.10 @aws-sdk/client-cognito-identity: ^3.485.0 => 3.485.0 @babel/core: ^7.20.0 => 7.23.7 @babel/preset-env: ^7.20.0 => 7.23.8 @babel/runtime: ^7.20.0 => 7.23.8 @glassbox/react-native-storyboard: ^6.696.1 => 6.698.0 @miblanchard/react-native-slider: ^2.3.1 => 2.3.1 @notifee/react-native: ^5.5.0 => 5.7.0 @project-arbuckle/body-condition-history-schema: ^1.0.0 => v1.0.1 @react-native-async-storage/async-storage: ^1.21.0 => 1.21.0 @react-native-community/checkbox: 0.5.16 => 0.5.16 @react-native-community/eslint-config: ^3.2.0 => 3.2.0 @react-native-community/netinfo: ^11.2.1 => 11.2.1 @react-native-firebase/analytics: 18.7.3 => 18.7.3 @react-native-firebase/app: 18.7.3 => 18.7.3 @react-native-firebase/crashlytics: 18.7.3 => 18.7.3 @react-native-firebase/dynamic-links: 18.7.3 => 18.7.3 @react-native-firebase/messaging: 18.7.3 => 18.7.3 @react-native-firebase/remote-config: 18.7.3 => 18.7.3 @react-native-picker/picker: github:react-native-picker/picker => 2.6.1 @react-navigation/bottom-tabs: 6.5.11 => 6.5.11 @react-navigation/drawer: 6.6.6 => 6.6.6 @react-navigation/native: ^6.0.8 => 6.1.9 @react-navigation/native-stack: 6.9.17 => 6.9.17 @react-navigation/stack: 6.3.20 => 6.3.20 @reduxjs/toolkit: 2.0.1 => 2.0.1 @reduxjs/toolkit-query: 1.0.0 @reduxjs/toolkit-query-react: 1.0.0 @reduxjs/toolkit-react: 1.0.0 @testing-library/jest-native: ^5.4.2 => 5.4.3 @testing-library/react-native: ^12.4.1 => 12.4.3 @tsconfig/react-native: ^2.0.2 => 2.0.3 @types/jest: ^29.2.1 => 29.5.11 @types/luxon: ^3.3.7 => 3.4.0 @types/node: ^18.19.3 => 18.19.5 @types/react: ^18.0.24 => 18.2.47 @types/react-native: ^0.71.13 => 0.71.13 (0.70.19) @types/react-native-vector-icons: ^6.4.18 => 6.4.18 @types/react-redux: 7.1.33 => 7.1.33 @types/react-test-renderer: ^18.0.0 => 18.0.7 @types/redux-mock-store: 1.0.6 => 1.0.6 @types/semver: ^7.3.11 => 7.5.6 @typescript-eslint/eslint-plugin: ^5.3.0 => 5.62.0 @typescript-eslint/parser: ^5.3.0 => 5.62.0 (6.18.1) ApptentiveExample: 6.0.0 GlassboxReactExampleApp: 0.0.1 HelloWorld: 0.0.1 apollo-link-rest: ^0.9.0 => 0.9.0 apptentive-react-native: ^6.1.3 => 6.1.3 aws-amplify: ^6.0.10 => 6.0.10 aws-amplify/adapter-core: undefined () aws-amplify/analytics: undefined () aws-amplify/analytics/kinesis: undefined () aws-amplify/analytics/kinesis-firehose: undefined () aws-amplify/analytics/personalize: undefined () aws-amplify/analytics/pinpoint: undefined () aws-amplify/api: undefined () aws-amplify/api/server: undefined () aws-amplify/auth: undefined () aws-amplify/auth/cognito: undefined () aws-amplify/auth/cognito/server: undefined () aws-amplify/auth/enable-oauth-listener: undefined () aws-amplify/auth/server: undefined () aws-amplify/datastore: undefined () aws-amplify/in-app-messaging: undefined () aws-amplify/in-app-messaging/pinpoint: undefined () aws-amplify/push-notifications: undefined () aws-amplify/push-notifications/pinpoint: undefined () aws-amplify/storage: undefined () aws-amplify/storage/s3: undefined () aws-amplify/storage/s3/server: undefined () aws-amplify/storage/server: undefined () aws-amplify/utils: undefined () babel-jest: ^29.2.1 => 29.7.0 base-64: ^1.0.0 => 1.0.0 buffer: ^6.0.3 => 6.0.3 (4.9.2, 5.7.1) eslint: ^8.19.0 => 8.56.0 eslint-config-prettier: ^7.2.0 => 7.2.0 (8.10.0) eslint-plugin-import: ^2.25.2 => 2.29.1 eslint-plugin-jsx-a11y: ^6.4.1 => 6.8.0 eslint-plugin-prettier: ^3.4.1 => 3.4.1 (4.2.1) eslint-plugin-react: ^7.26.1 => 7.33.2 eslint-plugin-react-hooks: ^4.6.0 => 4.6.0 expo: ^49.0.21 => 49.0.21 expo-barcode-scanner: 12.7.0 => 12.7.0 expo-camera: ~13.6.0 => 13.6.0 expo-file-system: ~15.6.0 => 15.6.0 (15.4.5) expo-sharing: 11.7.0 => 11.7.0 graphql: 14.7.0 => 14.7.0 (15.8.0) jest: ^29.2.1 => 29.7.0 jest-junit: ^16.0.0 => 16.0.0 jest-junit-reporter: ^1.1.0 => 1.1.0 jest-serializer: ^28.0.0 => 28.0.0 (27.5.1) lodash: ^4.17.21 => 4.17.21 luxon: 3.4.4 => 3.4.4 metro-react-native-babel-preset: 0.73.10 => 0.73.10 (0.76.8) patch-package: ^6.4.7 => 6.5.1 prettier: ^2.4.1 => 2.8.8 react: 18.2.0 => 18.2.0 react-native: 0.71.14 => 0.71.14 react-native-barcode-mask: ^1.2.4 => 1.2.4 react-native-ble-plx: 3.1.2 => 3.1.2 react-native-config: 1.5.1 => 1.5.1 react-native-date-picker: 4.3.4 => 4.3.4 react-native-gesture-handler: ^2.9.0 => 2.14.0 react-native-get-random-values: ^1.10.0 => 1.10.0 react-native-inappbrowser-reborn: ^3.7.0 => 3.7.0 react-native-localize: 3.0.4 => 3.0.4 react-native-modal: 13.0.1 => 13.0.1 react-native-navigation-bar-color: 2.0.2 => 2.0.2 react-native-paper: ^4.11.1 => 4.12.8 react-native-permissions: 3.10.1 => 3.10.1 react-native-reanimated: ^2.14.1 => 2.17.0 react-native-restart: 0.0.27 => 0.0.27 react-native-safe-area-context: 4.8.0 => 4.8.0 react-native-screens: 3.29.0 => 3.29.0 react-native-splash-screen: 3.3.0 => 3.3.0 react-native-svg: 14.1.0 => 14.1.0 react-native-svg-transformer: 1.1.0 => 1.1.0 react-native-url-polyfill: 2.0.0 => 2.0.0 react-native-vector-icons: ^10.0.2 => 10.0.3 react-native-version-number: ^0.3.6 => 0.3.6 react-native-webview: 11.23.1 => 11.23.1 react-native-youtube-iframe: ^2.3.0 => 2.3.0 react-redux: 9.0.4 => 9.0.4 react-test-renderer: 18.2.0 => 18.2.0 reactotron-react-native: ^5.0.4 => 5.0.4 reactotron-redux: ^3.1.4 => 3.1.4 redux-mock-store: ^1.5.4 => 1.5.4 redux-persist: ^6.0.0 => 6.0.0 redux-persist/integration/react: undefined () semver: 7.5.4 => 7.5.4 (6.3.1, 5.7.2, 7.5.3, 7.3.2) ts-jest: ^29.1.1 => 29.1.1 typescript: 4.8.4 => 4.8.4 (4.9.5, 5.3.3) unimported: ^1.29.2 => 1.31.1 victory-native: 36.7.0 => 36.7.0 webdriverio: ^7.19.7 => 7.34.0 npmGlobalPackages: corepack: 0.18.0 npm: 10.2.3 ```

Describe the bug

Receiving a InvalidRedirectException: signInRedirect or signOutRedirect had an invalid format or was not found. error when tapping either Google or Apple Sign In buttons.

Expected behavior

Hosted UI opens and prompts for username and password for provider.

Reproduction steps

  1. Open app, sign in screen loads with two provider options (Apple & Google)
  2. Tap either of the sign-in buttons
  3. No navigation/modal appears, but an error is received
  4. Check metro bundler for details where log output is found

Code Snippet

Config object:

const rackspaceDevAmplifyConfig = {
  Auth: {
    Cognito: {
      userPoolClientId: 'our-user-pool-client-id',
      userPoolId: 'our-user-pool-id',
      loginWith: {
        oauth: {
          domain: 'our-domain,
          scopes: ['openid', 'email'],
          redirectSignIn: ['https://api.dev.our-domain.com/authSuccess.html'],
          redirectSignOut: ['arbuckle://'],
          responseType: 'code',
        },
        username: 'true',
      },
    },
  },
};

Our configure function (getAmplifyConfig returns rackspaceDevAmplifyConfig object above):


  configure = () => {
    const currentAmplifyConfig = getAmplifyConfig();

    if (
      this.amplifyConfig === null ||
      this.amplifyConfig.Auth.Cognito.userPoolClientId !== currentAmplifyConfig.Auth.Cognito.userPoolClientId
    ) {
      Amplify.configure(currentAmplifyConfig);
    }
    this.amplifyConfig = currentAmplifyConfig;
  };

Log output

``` LOG AuthenticationService.signIn() WARN Possible Unhandled Promise Rejection (id: 0): InvalidRedirectException: signInRedirect or signOutRedirect had an invalid format or was not found. InvalidRedirectException: signInRedirect or signOutRedirect had an invalid format or was not found. at construct (native) at apply (native) at _construct (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:19402:106) at Wrapper (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:19374:64) at construct (native) at _callSuper (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:188852:170) at AmplifyError (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:188863:25) at construct (native) at _callSuper (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:212185:170) at AuthError (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:212192:25) at anonymous (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:212294:130) at loadModuleImplementation (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:252:14) at guardedLoadModule (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:153:47) at metroRequire (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:84:92) at assertAuthTokens (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:212244:26) at ?anon_0_ (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:216772:80) at next (native) at asyncGeneratorStep (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:20398:26) at _next (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:20417:29) at tryCallOne (/Users/distiller/react-native/sdks/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:53:16) at anonymous (/Users/distiller/react-native/sdks/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:139:27) at apply (native) at anonymous (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:25961:26) at _callTimer (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:25880:17) at _callReactNativeMicrotasksPass (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:25910:17) at callReactNativeMicrotasks (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:26073:44) at __callReactNativeMicrotasks (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:2406:46) at anonymous (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:2218:45) at __guard (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:2390:15) at flushedQueue (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:2217:21) at invokeCallbackAndReturnFlushedQueue (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.nestle.us.purina.chekrcat-dev:2211:33) ```

aws-exports.js

No response

Manual configuration

const rackspaceDevAmplifyConfig = {
  Auth: {
    Cognito: {
      userPoolClientId: 'our-user-pool-client-id',
      userPoolId: 'our-user-pool-id',
      loginWith: {
        oauth: {
          domain: 'our-domain,
          scopes: ['openid', 'email'],
          redirectSignIn: ['https://api.dev.our-domain.com/authSuccess.html'],
          redirectSignOut: ['arbuckle://'],
          responseType: 'code',
        },
        username: 'true',
      },
    },
  },
};

Additional configuration

No response

Mobile Device

iPhone 15

Mobile Operating System

iOS 17.0

Mobile Browser

Safari

Mobile Browser Version

No response

Additional information and screenshots

No response

israx commented 10 months ago

hello @mattekelly , if you are using RN your redirect sign-in/out shouldn't start with http or https

cwomack commented 10 months ago

@mattekelly, there's an example of how the Auth configuration in React Native should go (which differs a little from the JS and regular React steps) that you can see here for React Native setup and example redirect sign-in/outs. Like @israx referenced above, can you see if refactoring these resolves the issue?

You'll want to check that both the local config and the Cognito console are aligned as well!

mattekelly commented 10 months ago

@israx @cwomack using a non-http/https endpoint did get us past this error. While the link you point to does show such a link as an example, I'd suggest plainly stating that somewhere in the documentation.

mattekelly commented 10 months ago

One other question, with V6 we are seeing this modal upon calling sign out. We did not see this in V4 which we're upgrading from. Is there something we're doing that is causing the modal to say "to Sign In" ?

Screenshot 2024-01-10 at 11 30 16 AM
cwomack commented 10 months ago

@mattekelly, that's odd and shouldn't be happening if you're calling the signOut API. If you're seeing it during sign out, the code might be calling both signIn and signOut at the same time for some reason. Are you able to share the frontend code that is causing this?

cwomack commented 9 months ago

Closing this issue as we have not heard back from you. If you are still experiencing this, please feel free to reply back and provide any information previously requested and we'd be happy to re-open the issue.

Thank you!

jvgeee commented 5 months ago

One other question, with V6 we are seeing this modal upon calling sign out. We did not see this in V4 which we're upgrading from. Is there something we're doing that is causing the modal to say "to Sign In" ? Screenshot 2024-01-10 at 11 30 16 AM

From what I remember, this happens because Amplify needs to open a web browser to sign out for federated (social sign on) sessions. The naming is wrong in the popup and should be changed to "...wants to use amazoncognito.com to sign out"