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

Receiving {"AppCognitoWebDomain":"invalid"} when trying to authenticate #1183

Closed
AlbertoSinigaglia opened this issue Feb 19, 2021 · 3 comments
Labels
auth Related to the Auth category/plugins question General question

Comments

@AlbertoSinigaglia
Copy link

AlbertoSinigaglia commented Feb 19, 2021

I've already followed this issue #1066 but it still not work.
Whenever I try to configure Amplify, i get:

E/ContentValues: Could not initialize Amplify
    AuthException{message=Failed to instantiate AWSMobileClient, cause=java.lang.RuntimeException: Failed to initialize OAuth, please check your awsconfiguration.json, recoverySuggestion=See attached exception for more details}
        at com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin.configure(AWSCognitoAuthPlugin.java:240)
        at com.amplifyframework.core.category.Category.configure(Category.java:91)
        at com.amplifyframework.core.Amplify.configure(Amplify.java:150)
        at com.amplifyframework.core.Amplify.configure(Amplify.java:120)
        at com.example.aerofighters.MainActivity.onCreate(MainActivity.kt:27)
        at android.app.Activity.performCreate(Activity.java:7009)
        at android.app.Activity.performCreate(Activity.java:7000)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: java.lang.RuntimeException: Failed to initialize OAuth, please check your awsconfiguration.json
        at com.amazonaws.mobile.client.AWSMobileClient$2.run(AWSMobileClient.java:596)
        at com.amazonaws.mobile.client.internal.InternalCallback$1.run(InternalCallback.java:101)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthInvalidParameterException: validation failed
        at com.amazonaws.mobileconnectors.cognitoauth.Auth$Builder.validateCognitoAuthParameters(Auth.java:546)
        at com.amazonaws.mobileconnectors.cognitoauth.Auth$Builder.build(Auth.java:486)
        at com.amazonaws.mobile.client.AWSMobileClient._initializeHostedUI(AWSMobileClient.java:647)
        at com.amazonaws.mobile.client.AWSMobileClient.access$400(AWSMobileClient.java:165)
        at com.amazonaws.mobile.client.AWSMobileClient$2.run(AWSMobileClient.java:593)
        at com.amazonaws.mobile.client.internal.InternalCallback$1.run(InternalCallback.java:101) 
        at java.lang.Thread.run(Thread.java:764) 
     Caused by: com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthInvalidParameterException: {"AppCognitoWebDomain":"invalid"}
        at com.amazonaws.mobileconnectors.cognitoauth.Auth$Builder.validateCognitoAuthParameters(Auth.java:543)
        at com.amazonaws.mobileconnectors.cognitoauth.Auth$Builder.build(Auth.java:486) 
        at com.amazonaws.mobile.client.AWSMobileClient._initializeHostedUI(AWSMobileClient.java:647) 
        at com.amazonaws.mobile.client.AWSMobileClient.access$400(AWSMobileClient.java:165) 
        at com.amazonaws.mobile.client.AWSMobileClient$2.run(AWSMobileClient.java:593) 
        at com.amazonaws.mobile.client.internal.InternalCallback$1.run(InternalCallback.java:101) 
        at java.lang.Thread.run(Thread.java:764) 

And there is no way to take this exception away...

Goal:
Enable authentication using Amplify connected to Cognito, without socials, with username and password

What I've done:
So looking through the web, I've found that if I'm using Amplify, the file awsconfiguration.json is useless, and I should only care about amplifyconfiguration.json.
For this reason, i've run amplify add auth:

amplify add auth   
Using service: Cognito, provided by: awscloudformation
 
 The current configured provider is Amazon Cognito. 
 
 Do you want to use the default authentication and security configuration? Default configuration
 Warning: you will not be able to edit these selections. 
 How do you want users to be able to sign in? Username
 Do you want to configure advanced settings? No, I am done.
Successfully added auth resource XXXXXXXXXXXXX locally

Some next steps:
"amplify push" will build all your local backend resources and provision it in the cloud
"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud

then I've pushed the configuration with amplify push, and using the issue previously linked, I've edited the configuration: like this (this is amplifyconfiguration.json):

{
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify-cli/0.1.0",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "us-east-2:XXXXXXXXXXXXXXXXXXXXXXXXXXX",
                            "Region": "us-east-2"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "us-east-2_XXXXXXXX",
                        "AppClientId": "XXXXXXXXXXXXXXXXX",
                        "AppClientSecret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
                        "Region": "us-east-2"
                    }
                },
                "Auth": {
                    "Default": {
                        "OAuth": {
                            "WebDomain": "https://XXXXXXXXX.auth.us-east-2.amazoncognito.com",
                            "AppClientId": "XXXXXXXXXXXXXXXX",
                            "AppClientSecret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
                            "SignInRedirectURI": "myapp://callback/",
                            "SignOutRedirectURI": "myapp://signout/",
                            "Scopes": [
                                "phone",
                                "email",
                                "openid",
                                "profile",
                                "aws.cognito.signin.user.admin"
                            ]
                        },
                        "authenticationFlowType": "USER_SRP_AUTH"
                    }
                }
            }
        }
    }
}

The information in the amplifyconfiguration.json are been copied by the Cognito console, so they are supposed to correct(?)

Schermata 2021-02-19 alle 12 15 07

Schermata 2021-02-19 alle 12 12 57

Schermata 2021-02-19 alle 12 12 00

Schermata 2021-02-19 alle 12 22 49

EDIT:
With the same credentials that i have in the config, if i use the link that i can find here (https://your_domain/login?response_type=token&client_id=your_app_client_id&redirect_uri=your_callback_url) it shows the login form

@AlbertoSinigaglia AlbertoSinigaglia added the bug Something isn't working label Feb 19, 2021
@richardmcclellan
Copy link
Contributor

Hi @AlbertoSinigaglia, there are 3 supported sign in methods:

  1. signIn (username - password sign in via your own native UI)
  2. signInWithWebUi (username - password sign in through a hosted UI webview)
  3. signInWithSocialWebUi - (sign in with Google, Facebook, etc)

Are you trying to use (1) or (2)?

For (1), you need to choose "Default Configuration". Once complete, run amplify push. At this point, you should expect NOT to have an OAuth object in your amplifyconfiguration.json.
For (2) or (3), you need to choose "Default configuration with Social Provider (Federation)". Admittedly, the wording is probably a little confusing, since (2) is not a social provider. At this point, you SHOULD expect to have an OAuth object in your amplifyconfiguration.json.

Note that we don't currently support (1) AND (2) or (3) in the same app. Please comment or add a reaction on this feature request, if that's something you want.

@richardmcclellan richardmcclellan added auth Related to the Auth category/plugins question General question and removed bug Something isn't working labels Feb 19, 2021
@AlbertoSinigaglia
Copy link
Author

I've literally tried everything, and i've ended up creating my own activity since looks like that nothing worked out

@3dteemu
Copy link

3dteemu commented Aug 31, 2022

I had the same issue and traced it down to this bug: aws-amplify/aws-sdk-android#2842 which should now be fixed in aws-amplify/aws-sdk-android#2946 . I had initially an invalid domain in the amplifyconfiguration.json which was kept in the SharedPreferences and read from there. The domain should be in the following format: xxxx.auth.eu-central-1.amazoncognito.com, not https://xxxx.auth.eu-central-1.amazoncognito.com.

A workaround was to uninstall (to clear the SharedPreferences) and reinstall.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth Related to the Auth category/plugins question General question
Projects
None yet
Development

No branches or pull requests

3 participants