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.43k stars 2.13k forks source link

Signing with google returns redirect mismatch the first time, but succeeds the second time. #8093

Closed jesuscovam closed 3 years ago

jesuscovam commented 3 years ago

Before opening, please confirm:

I have searched for duplicate or closed issues and discussions. I have read the guide for submitting bug reports. I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

JavaScript Framework

React

Amplify APIs

Authentication

Amplify Categories

auth

Environment information

``` # Put output below this line System: OS: macOS Mojave 10.14.6 CPU: (4) x64 Intel(R) Core(TM) i5-5250U CPU @ 1.60GHz Memory: 67.77 MB / 4.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 14.15.3 - /usr/local/bin/node Yarn: 1.22.5 - /usr/local/bin/yarn npm: 7.8.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Browsers: Chrome: 89.0.4389.114 Safari: 13.1.1 npmPackages: @aws-sdk/client-cognito-identity-provider: ^3.7.0 => 3.7.0 @babel/core: ^7.12.3 => 7.12.3 @babel/preset-env: ^7.12.1 => 7.12.1 @babel/preset-typescript: ^7.13.0 => 7.13.0 @hookform/resolvers: ^1.3.0 => 1.3.0 @sentry/browser: ^6.2.1 => 6.2.1 @sentry/integrations: ^6.2.1 => 6.2.1 @sentry/node: ^6.2.1 => 6.2.1 @sentry/webpack-plugin: ^1.14.1 => 1.14.1 @stripe/react-stripe-js: ^1.2.0 => 1.2.0 @stripe/stripe-js: ^1.11.0 => 1.11.0 @tailwindcss/jit: ^0.1.3 => 0.1.3 @testing-library/jest-dom: ^5.11.10 => 5.11.10 @testing-library/react: ^11.2.6 => 11.2.6 @testing-library/user-event: ^13.1.1 => 13.1.1 @types/jest: ^26.0.22 => 26.0.22 @types/node: ^14.11.8 => 14.11.8 @types/ramda: ^0.27.29 => 0.27.29 @types/react: ^16.9.52 => 16.9.52 @types/react-datepicker: ^3.1.1 => 3.1.1 @types/react-modal: ^3.10.6 => 3.10.6 @types/react-radio-group: ^3.0.2 => 3.0.2 @types/react-select: ^3.0.28 => 3.0.28 @types/react-star-rating-component: ^1.4.0 => 1.4.0 @types/uuid: ^8.3.0 => 8.3.0 @types/yup: ^0.29.8 => 0.29.8 @typescript-eslint/eslint-plugin: ^4.4.1 => 4.4.1 @typescript-eslint/parser: ^4.4.1 => 4.4.1 @xstate/react: ^1.3.1 => 1.3.1 autoprefixer: ^10.2.5 => 10.2.5 aws-amplify: ^3.3.13 => 3.3.23 aws-sdk: ^2.771.0 => 2.771.0 axios: ^0.21.1 => 0.21.1 babel-jest: ^26.6.3 => 26.6.3 balloon-css: ^1.2.0 => 1.2.0 dayjs: ^1.9.6 => 1.9.6 eslint: ^7.11.0 => 7.11.0 eslint-config-prettier: ^6.13.0 => 6.13.0 eslint-plugin-jsx-a11y: ^6.3.1 => 6.3.1 eslint-plugin-prettier: ^3.1.4 => 3.1.4 eslint-plugin-react: ^7.21.4 => 7.21.4 eslint-plugin-react-hooks: ^4.1.2 => 4.1.2 formik: ^2.2.0 => 2.2.0 framer-motion: ^4.0.3 => 4.0.3 fuse.js: ^6.4.2 => 6.4.2 graphql-request: ^3.4.0 => 3.4.0 identity-obj-proxy: ^3.0.0 => 3.0.0 jest: ^26.6.3 => 26.6.3 next: ^10.0.9 => 10.0.9 postcss: ^8.2.8 => 8.2.8 postcss-flexbugs-fixes: 4.2.1 => 4.2.1 postcss-preset-env: ^6.7.0 => 6.7.0 prettier: ^2.1.2 => 2.1.2 pure-react-carousel: ^1.27.6 => 1.27.6 ramda: ^0.27.1 => 0.27.1 react: ^16.13.1 => 16.13.1 react-bnb-gallery: ^1.4.4 => 1.4.4 react-day-picker: ^7.4.8 => 7.4.8 react-dom: ^16.13.1 => 16.13.1 react-hook-form: ^6.15.4 => 6.15.4 react-hot-toast: ^1.0.1 => 1.0.1 react-icons: ^3.11.0 => 3.11.0 react-intersection-observer: ^8.31.0 => 8.31.0 react-radio-group: ^3.0.3 => 3.0.3 react-responsive: ^8.2.0 => 8.2.0 react-select: ^3.1.1 => 3.1.1 react-star-rating-component: ^1.4.1 => 1.4.1 react-switch: ^6.0.0 => 6.0.0 react-verification-code-input: ^1.2.6 => 1.2.6 remove: ^0.1.5 => 0.1.5 stripe: ^8.130.0 => 8.130.0 swr: ^0.4.2 => 0.4.2 tailwindcss: ^2.0.3 => 2.0.3 ts-jest: ^26.5.4 => 26.5.4 typescript: ^4.0.3 => 4.0.3 uuid: ^8.3.1 => 8.3.1 xstate: ^4.16.2 => 4.16.2 yup: ^0.29.3 => 0.29.3 npmGlobalPackages: @aws-amplify/cli: 4.47.1 aws-cdk: 1.92.0 babel-eslint: 10.1.0 create-next-app: 10.1.3 expo-cli: 4.3.4 ganache-cli: 6.12.2 http-server: 0.12.1 n: 7.0.0 nodemon: 2.0.6 npm: 7.8.0 prettier: 2.1.2 react-native-cli: 2.0.1 remove: 0.1.5 stable: 0.1.8 truffle: 5.1.63 ts-prune: 0.8.8 ```

Describe the bug

When I do a federated signing with Google it returns a redirect mismatch the first time and succeeds if a return the page and try again.

Expected behavior

It should show the list of google accounts to do sign in in the first try

Reproduction steps

I'm sorry the project is private

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

aws-exports.js

const awsmobile = {
    "aws_project_region": "us-east-1",
    "aws_cognito_identity_pool_id": "XXXXXXXXX,
    "aws_cognito_region": "us-east-1",
    "aws_user_pools_id": "XXXXXXXXXX",
    "aws_user_pools_web_client_id": "XXXXXXX",
    "oauth": {
        "domain": "XXXXXXXXXX",
        "scope": [
            "phone",
            "email",
            "openid",
            "profile",
            "aws.cognito.signin.user.admin"
        ],
        "redirectSignIn": "http://localhost:3000/,https://www.slissto.com/,exp://192.168.1.198:19000/",
        "redirectSignOut": "http://localhost:3000/,https://www.slissto.com/,exp://192.168.1.198:19000/",
        "responseType": "code"
    },
    "federationTarget": "COGNITO_USER_POOLS",
    "aws_appsync_graphqlEndpoint": "XXXXXXX",
    "aws_appsync_region": "us-east-1",
    "aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS",
    "aws_appsync_apiKey": "XXXXXXX",
    "aws_user_files_s3_bucket": "XXXXXX",
    "aws_user_files_s3_bucket_region": "us-east-1"
};

export default awsmobile;

Manual configuration


Amplify.configure({
  ...awsconfig,
  ssr: true,
  oauth: {
    ...awsconfig.oauth,
    redirectSignIn: 'http://localhost:3000/',
    redirectSignOut: 'http://localhost:3000/',
  },
})```

### Additional configuration

_No response_

### Mobile Device

_No response_

### Mobile Operating System

_No response_

### Mobile Browser

_No response_

### Mobile Browser Version

_No response_

### Additional information and screenshots

This error occurs in a NextJS app, I also have the same aws environment in an Expo app where at the moment it works fine.

This is the Expo app configuration 
```json
Amplify.configure({
  ...awsconfig,
  oauth: {
    ...awsconfig.oauth,
    redirectSignIn: "exp://192.168.1.198:19000/",
    redirectSignOut: "exp://192.168.1.198:19000/",
    urlOpener,
  },
});
jesuscovam commented 3 years ago

Manage to fix my error by directly mutating the awsconfig.oauth instead of spreading the object


awsconfig.oauth.redirectSignIn = 'http://localhost:3000/'
awsconfig.oauth.redirectSignOut = 'http://localhost:3000/'

Amplify.configure({
  ...awsconfig,
  ssr: true,
})
github-actions[bot] commented 2 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.