3
votes

I just started using Amazon cognito web services. I followed this sample app [https://github.com/awslabs/aws-sdk-android-samples/tree/master/AmazonCognitoAuthDemo] but after running the application its giving:

AuthInvalidParameterException

Does anyone have a solution for this one? Searched myself but could not find a solution.

Auth.Builder builder = new Auth.Builder().setAppClientId(getString(R.string.cognito_client_id))
            .setAppClientSecret(getString(R.string.cognito_client_secret))
            .setAppCognitoWebDomain(getString(R.string.cognito_web_domain))
            .setApplicationContext(getApplicationContext())
            .setAuthHandler(new callback())
            .setSignInRedirect(getString(R.string.app_redirect))
            .setSignOutRedirect(getString(R.string.app_redirect));
    this.auth = builder.build();
    appRedirect = Uri.parse(getString(R.string.app_redirect));
}

i am also add this in but i am cofused about that one can having idea for using below

 <!-- TODO: Add your Cognito pool details here -->
<string name="cognito_web_domain">domain</string>
<string name="cognito_client_id">client id</string>
<string name="cognito_client_secret">client secret</string>
<string name="app_redirect">redicrec</string>

Exception:

Caused by: com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthInvalidParameterException: validation failed at com.amazonaws.mobileconnectors.cognitoauth.Auth$Builder.validateCognitoAuthParameters(Auth.java:341) at com.amazonaws.mobileconnectors.cognitoauth.Auth$Builder.build(Auth.java:288) at com.example.ivissw.amzoncognito.MainActivity.initCognito(MainActivity.java:105) at com.example.ivissw.amzoncognito.MainActivity.onCreate(MainActivity.java:31) at android.app.Activity.performCreate(Activity.java:6975) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)  at android.app.ActivityThread.-wrap11(Unknown Source:0)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)  at android.os.Handler.dispatchMessage(Handler.java:105)  at android.os.Looper.loop(Looper.java:164)  at android.app.ActivityThread.main(ActivityThread.java:6541)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)  Caused by: com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthInvalidParameterException: {"AppCognitoWebDomain":"invalid"} at com.amazonaws.mobileconnectors.cognitoauth.Auth$Builder.validateCognitoAuthParameters(Auth.java:338) at com.amazonaws.mobileconnectors.cognitoauth.Auth$Builder.build(Auth.java:288)  at com.example.ivissw.amzoncognito.MainActivity.initCognito(MainActivity.java:105)  at com.example.ivissw.amzoncognito.MainActivity.onCreate(MainActivity.java:31)  at android.app.Activity.performCreate(Activity.java:6975)  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)  at android.app.ActivityThread.-wrap11(Unknown Source:0)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)  at android.os.Handler.dispatchMessage(Handler.java:105)  at android.os.Looper.loop(Looper.java:164)  at android.app.ActivityThread.main(ActivityThread.java:6541)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

1
You have to put your account corresponding credentials on that xml file.fernandospr
@fernandospr agree with you but i am confused about here :<string name="app_redirect">demoapp://www.loginactivity.com/mainactivity</string> what is that and where we can find it. can you please specify that.ashish

1 Answers

2
votes

First, you need to open Cognito Console. Then select here option User Pools and go ahead. If you haven't any User Pool, you must create it. Second, look to the left menu and enter "App clients". Also add one for your App or use existing. If all doing right, you'll see this picture below.

enter image description here

Next, check your Domain Name at the left Console menu and create it if need. If done, return to you project and find file strings.xml . Change this section:

<!-- Here below need your Domain Name -->
<string name="cognito_web_domain">yourDomainName.amazoncognito.com</string>
<!-- Write below your App Client ID -->
<string name="cognito_client_id">_id</string>
<!-- Write below your App Client Secret -->
<string name="cognito_client_secret">_secret</string>
<!-- This not influences on validate, may leave as is -->
<string name="app_redirect">demoapp://www.loginactivity.com/mainactivity</string> 

Hope it helps!