- Newest
- Most votes
- Most comments
To address your issues with Google sign-in and Amazon Cognito integration in your React Native application, I can provide some guidance on your questions:
-
Yes, creating a new App Client with the client secret generation disabled is a valid approach to bypass the "NotAuthorizedException" error you're encountering. When you create an App Client without a client secret, you won't need to provide the SECRET_HASH in your authentication requests. This can simplify the process, especially for mobile applications where securely storing and managing a client secret can be challenging.
-
For social provider authentication, you can use both Cognito User Pools and Identity Pools, but they serve different purposes. Cognito User Pools is primarily for user management and authentication, while Identity Pools is for providing temporary AWS credentials to access other AWS services. In your case, since you want to manage user sign-up and sign-in, using a Cognito User Pool is appropriate. You're already on the right track with this approach.
-
While you can accomplish social provider authentication using the libraries you've mentioned (@react-native-google-sign-in/google-signin, amazon-cognito-identity-js, and aws-sdk), using AWS Amplify can significantly simplify the process. Amplify provides a higher-level abstraction and handles many of the complexities of federation and token management for you. It can make your implementation more straightforward and less error-prone.
However, if you prefer to continue with your current setup, you'll need to ensure you're correctly handling the Google ID token and using it to authenticate with Cognito. After obtaining the Google ID token, you should use it to get Cognito tokens rather than trying to sign up or sign in the user manually.
To improve your current implementation:
- Remove the manual sign-up and sign-in logic (signUpUser and signInUser functions).
- After getting the Google ID token, use it directly with Cognito to authenticate the user.
- Configure your Cognito User Pool to automatically create user profiles for federated users if they don't exist.
This approach will let Cognito handle the user creation and authentication process based on the Google ID token, simplifying your code and reducing potential errors.
Sources
Setting up Google as an identity pool IdP - Amazon Cognito
Does Cognito provide the Id token that is returned by Google ? | AWS re:Post
User pool sign-in with third party identity providers - Amazon Cognito
