amplify-js icon indicating copy to clipboard operation
amplify-js copied to clipboard

Implementing Cognito Google Authentication with AWS Amplify in Mobile Apps

Open Shubhagj opened this issue 1 year ago • 2 comments

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Authentication

Amplify Version

v6

Amplify Categories

auth

Backend

Amplify CLI

Environment information

 System:
    OS: Windows 10 10.0.19045
    CPU: (4) x64 Intel(R) Core(TM) i3-8100 CPU @ 3.60GHz
    Memory: 1.22 GB / 7.87 GB
  Binaries:
    Node: 20.15.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.98)
    Internet Explorer: 11.0.19041.4355
  npmPackages:
    @aws-amplify/auth: ^6.3.14 => 6.3.14
    @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/core: ^6.3.9 => 6.3.10
    @aws-amplify/core/internals/adapter-core:  undefined ()
    @aws-amplify/core/internals/aws-client-utils:  undefined ()
    @aws-amplify/core/internals/aws-client-utils/composers:  undefined ()
    @aws-amplify/core/internals/aws-clients/cognitoIdentity:  undefined ()
    @aws-amplify/core/internals/aws-clients/pinpoint:  undefined ()
    @aws-amplify/core/internals/providers/pinpoint:  undefined ()
    @aws-amplify/core/internals/utils:  undefined ()
    @aws-amplify/core/server:  undefined ()
    @aws-amplify/react-native: ^1.1.4 => 1.1.4
    @aws-amplify/rtn-web-browser: ^1.0.31 => 1.0.31
    @aws-amplify/ui-react: ^6.1.14 => 6.1.14
    @aws-amplify/ui-react-internal:  undefined ()
    @babel/core: ^7.20.0 => 7.22.10
    @babel/preset-env: ^7.20.0 => 7.22.10
    @babel/runtime: ^7.25.0 => 7.25.0
    @react-native-async-storage/async-storage: ^1.24.0 => 1.24.0
    @react-native-community/google-signin: ^5.0.0 => 5.0.0
    @react-native-community/netinfo: ^11.3.2 => 11.3.2
    @react-native-picker/picker: ^2.7.7 => 2.7.7
    @react-native/eslint-config: ^0.72.2 => 0.72.2
    @react-native/metro-config: ^0.72.11 => 0.72.11
    @react-navigation/bottom-tabs: ^6.5.8 => 6.5.8
    @react-navigation/drawer: ^6.6.3 => 6.6.3
    @react-navigation/native: ^6.1.7 => 6.1.7
    @react-navigation/native-stack: ^6.9.13 => 6.9.13
    @tsconfig/react-native: ^3.0.0 => 3.0.2
    @types/react: ^18.0.24 => 18.2.20
    @types/react-test-renderer: ^18.0.0 => 18.0.0
    HelloWorld:  0.0.1
    amazon-cognito-auth-js: ^1.3.3 => 1.3.3
    amazon-cognito-identity-js: ^6.3.12 => 6.3.12
    amazon-cognito-identity-js/internals:  undefined ()
    aws-amplify: ^6.5.1 => 6.5.1
    aws-amplify-react-native: ^7.0.8 => 7.0.8
    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/data:  undefined ()
    aws-amplify/data/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.6.2
    eslint: ^8.19.0 => 8.47.0
    jest: ^29.2.1 => 29.6.2
    jspdf: ^2.5.1 => 2.5.1
    metro-react-native-babel-preset: 0.76.8 => 0.76.8 (0.76.7)
    prettier: ^2.4.1 => 2.8.8
    react: ^18.2.0 => 18.2.0
    react-native: ^0.72.4 => 0.72.4
    react-native-app-auth: ^7.2.0 => 7.2.0
    react-native-dialog: ^9.3.0 => 9.3.0
    react-native-elements: ^3.4.3 => 3.4.3
    react-native-fs: ^2.20.0 => 2.20.0
    react-native-gesture-handler: ^2.12.1 => 2.12.1
    react-native-gifted-charts: ^1.4.19 => 1.4.19
    react-native-html-to-pdf: ^0.12.0 => 0.12.0
    react-native-image-picker: ^7.1.2 => 7.1.2
    react-native-linear-gradient: ^2.8.3 => 2.8.3
    react-native-onboarding-swiper: ^1.2.0 => 1.2.0
    react-native-paper: ^5.12.3 => 5.12.3
    react-native-responsive-fontsize: ^0.5.1 => 0.5.1
    react-native-safe-area-context: ^4.10.8 => 4.10.8
    react-native-screens: ^3.34.0 => 3.34.0
    react-native-svg: ^12.5.1 => 12.5.1
    react-native-tts: ^4.1.1 => 4.1.1
    react-native-vector-icons: ^10.1.0 => 10.1.0
    react-native-webview: ^13.10.5 => 13.10.5
    react-test-renderer: 18.2.0 => 18.2.0
    rn-fetch-blob: ^0.12.0 => 0.12.0
    typescript: 4.8.4 => 4.8.4
  npmGlobalPackages:
    @aws-amplify/cli: 12.12.5
    npm: 10.8.2
    react-native-cli: 2.0.1


Describe the bug

Prerequisites: JavaScript Framework: React Native Backend Amplify CLI Java Version (JDK): 17.0.11 React Native Version: ^0.72.4 Gradle Version: 8.0.1 or 8.0.2

Describe the bug:

I have installed the AWS CLI and configured AWS Amplify, as well as set up Google authentication. After running amplify push, I received the hosted UI endpoint URL in the format https://<Domain_name>/login?response_type=code&client_id=<client_id>&redirect_uri=myapp://

Upon using this hosted UI endpoint, I was able to see the Google login page. rg1

After entering the credentials (email and password) the user is successfully login, user registered in the backend Cognito user pool. However, after returning to the app's login screen, I want the user to be redirected to the home screen.

To achieve this, I added an intent filter in the AndroidManifest.xml file. Please let me know how to handle the redirect correctly.

image

and this also

image

Expected behavior

after user login successfully redirect to home screen

Reproduction steps

rg1

Code Snippet



Log output

// Put your logs below this line


aws-exports.js

const awsmobile = { "Auth": { "aws_project_region": "ap-south-1", "aws_cognito_identity_pool_id": "ap-south-1xxxxxxxxxx", "aws_cognito_region": "ap-south-1", "aws_user_pools_id": "xxxxxxx", "aws_user_pools_web_client_id": "xxxxxxxxx", "oauth": { "domain": "xxxxxx", "scope": [ "phone", "email", "openid", "profile", "aws.cognito.signin.user.admin" ], "redirectSignIn": "myapp://", even tried the (myapp://Home) "redirectSignOut": "myapp://", even tried the (myapp://Home) "responseType": "code" }, "federationTarget": "COGNITO_USER_POOLS", "aws_cognito_username_attributes": [ "EMAIL" ], "aws_cognito_social_providers": [ "GOOGLE" ], "aws_cognito_signup_attributes": [ "EMAIL" ], "aws_cognito_mfa_configuration": "OFF", "aws_cognito_mfa_types": [ "SMS" ], "aws_cognito_password_protection_settings": { "passwordPolicyMinLength": 8, "passwordPolicyCharacters": [] }, "aws_cognito_verification_mechanisms": [ "EMAIL" ] }};

export default awsmobile;

Manual configuration

No response

Additional configuration

No response

Mobile Device

android

Mobile Operating System

No response

Mobile Browser

chrome

Mobile Browser Version

No response

Additional information and screenshots

No response

Shubhagj avatar Aug 22 '24 10:08 Shubhagj

@robbevan @calavera @dbalmain @undefobj can you help with this?

Shubhagj avatar Aug 22 '24 11:08 Shubhagj

Hello, @Shubhagj 👋. It looks like in the dependencies you provided within the "system information" above, you have the following scoped packages that may cause issues with the Amplify singleton:

  • @aws-amplify/auth: ^6.3.14 => 6.3.14
  • @aws-amplify/core: ^6.3.9 => 6.3.10
  • @aws-amplify/ui-react: ^6.1.14 => 6.1.14

Can you remove these and see if it changes the behavior that you're experiencing? In addition, do you see any error messages or network logs that you can share? Finally, can you confirm that the redirectSignIn URI match what you have specified in your config?

cwomack avatar Aug 22 '24 18:08 cwomack

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!

cwomack avatar Sep 10 '24 20:09 cwomack