AWS Cognito user: Device confirmation failed - android

I am using CognitoAuth library from Amazon to manage user authentication.
In the AWS console, the "Do you want to remember your user's devices?" option is set to 'Always'.
But when I call getSession method on a CognitoUse object, in onSuccess callback, I always do get 'newDevice' param as null. It is supposed to be not null because the option to remember device is enabled. Because of that I cannot refresh the token and getting the exception below:
Device confirmation failed:
com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException: User is not authenticated
at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.getCachedSession(CognitoUser.java:981)
at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.confirmDevice(CognitoUser.java:3287)
at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.handleChallenge(CognitoUser.java:2607)
at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.respondToChallenge(CognitoUser.java:2409)
at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser$24.run(CognitoUser.java:2480)
at com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationContinuation.continueTask(AuthenticationContinuation.java:124)
at com.amazonaws.mobile.client.AWSMobileClient$6$1.getAuthenticationDetails(AWSMobileClient.java:1177)
at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.getSession(CognitoUser.java:778)
at com.amazonaws.mobile.client.AWSMobileClient$6.run(AWSMobileClient.java:1137)
at com.amazonaws.mobile.client.internal.InternalCallback$1.run(InternalCallback.java:101)
at java.lang.Thread.run(Thread.java:764)
Caused by: com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException: Invalid Refresh Token. (Service: AmazonCognitoIdentityProvider; Status Code: 400; Error Code: NotAuthorizedException; Request ID: ed2f2501-7a36-447f-ac29-c4ab4741958e)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:730)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:405)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:212)
at com.amazonaws.services.cognitoidentityprovider.AmazonCognitoIdentityProviderClient.invoke(AmazonCognitoIdentityProviderClient.java:6292)
at com.amazonaws.services.cognitoidentityprovider.AmazonCognitoIdentityProviderClient.initiateAuth(AmazonCognitoIdentityProviderClient.java:4277)
at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.refreshSession(CognitoUser.java:2378)
at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.getCachedSession(CognitoUser.java:976)
at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.confirmDevice(CognitoUser.java:3287) 
at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.handleChallenge(CognitoUser.java:2607) 
at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.respondToChallenge(CognitoUser.java:2409) 
at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser$24.run(CognitoUser.java:2480) 
at com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationContinuation.continueTask(AuthenticationContinuation.java:124) 
at com.amazonaws.mobile.client.AWSMobileClient$6$1.getAuthenticationDetails(AWSMobileClient.java:1177) 
at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.getSession(CognitoUser.java:778) 
at com.amazonaws.mobile.client.AWSMobileClient$6.run(AWSMobileClient.java:1137) 
at com.amazonaws.mobile.client.internal.InternalCallback$1.run(InternalCallback.java:101) 
at java.lang.Thread.run(Thread.java:764) 
Why is no CognitoDevice object received? How to resolve this?

Related

No ChallengeStatusReceiver for transaction id

My React Native app is crashing when some users try to add a payment method in production. This is happening on Android only. I cannot reproduce it in debug. I'm getting this mysterious error report in Sentry and after some Googling I have no idea what this error means:
No ChallengeStatusReceiver for transaction id
d.q.a.g1.i.d: No ChallengeStatusReceiver for transaction id
at d.q.a.g1.l.s.a
at d.q.a.g1.l.q.c
at d.q.a.g1.l.q.b
at d.q.a.g1.l.y$a.onPostExecute
at android.os.AsyncTask.finish(AsyncTask.java:755)
at android.os.AsyncTask.access$900(AsyncTask.java:192)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:772)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
I'm using tipsi-stripe and I'm pretty sure this error is happening when calling stripe.confirmSetupIntent(). This method presents an authentication "challenge" if the user's bank requires it.
The flow I'm using now is:
user enter payment details:
const createPaymentMethodParams = {
"billingDetails":{
"name":"First Last"
},
"card":{
"cvc":"333",
"expMonth":12,
"expYear":23,
"number":"4111111111111111"
}
}
Call the backend, which creates a setup intent with confirmation_method=manual. This returns a client_secret
"Create" the payment method with createPaymentMethod, which returns payment method id.
const paymentMethodData = await
stripe.createPaymentMethod(createPaymentMethodParams)
Finally, confirm the setup intent (this is the step which sometimes crashes):
// confirm the setup intent:
// - if authentication is required user will be redirected to auth flow
// - if no authentication is required this directly returns paymentMethodId
const { status, paymentMethodId } = await stripe.confirmSetupIntent({
clientSecret: intent.client_secret, // previously obtained from backend
paymentMethodId: paymentMethodData.id,
})
The most relevant result I found on Google was this https://adyen.github.io/adyen-3ds2-android/com/adyen/threeds2/ChallengeStatusReceiver.html
It refers to a 3DS sdk (as in "3-D Secure"), which would make sense to see at this stage when the user is required to authenticate. However I'm really not sure I'm on the right track...
Has anyone encountered this issue and can help me understand it, or point me in a direction? Any help greatly appreciated!

Invalid Access Token when make getUser Request in cognito

I am integrating AWS cognito authentication with social login (facebook/google).
I am follow all the steps as given in documentation but the end return Invalid Access Token
Service: AmazonCognitoIdentityProvider;
Status Code: 400;
Error Code: NotAuthorizedException;
Request ID: 58fc3cfc-1649-11e9-91bc-3fb47a1bd404
Put facebook login in to the crendential provider this code generate identity in my identity pool :
Map<String, String> logins = new HashMap<String, String>();
logins.put("graph.facebook.com",
AccessToken.getCurrentAccessToken().getToken());
credentialsProvider.setLogins(logins);
for creating user in user pool i am using this url:
val url = "https://<my-domain-name>.auth.ca-central-1.amazoncognito.com/oauth2/authorize?redirect_uri=myapp://&response_type=token&client_id=<my-ClientId>&identity_provider=Facebook"
That url creating my user in user pool and return access token and id token in result below :
access_token=eyJraWQiOiJyUXpaTDRUVGt6UDdoU3ZDbVB0NktpTVZDcXB4Z2ZFT3pJckpCWFB0WXZVPSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI2OTIwZDUwZC0zMTU4LTQwMTYtOTgyMi0wNDc0Yzc1MDFjYjIiLCJ0b2tlbl91c2UiOiJhY2Nlc3MiLCJzY29wZSI6ImF3cy5jb2duaXRvLnNpZ25pbi51c2VyLmFkbWluIHBob25lIG9wZW5pZCBwcm9maWxlIGVtYWlsIiwiYXV0aF90aW1lIjoxNTQ3Mjg4NDc0LCJpc3MiOiJodHRwczpcL1wvY29nbml0by1pZHAuY2EtY2VudHJhbC0xLmFtYXpvbmF3cy5jb21cL2NhLWNlbnRyYWwtMV9DSFVMbDV5c2wiLCJleHAiOjE1NDcyOTIwNzQsImlhdCI6MTU0NzI4ODQ3NCwidmVyc2lvbiI6MiwianRpIjoiNDE4MjNmNzUtMGFkMC00MTdjLThhOTYtM2JjZDM0NWNlZDQ3IiwiY2xpZW50X2lkIjoiN244Z25tdXFuM3NzZWFnaGNoOGQ2OWRibTIiLCJ1c2VybmFtZSI6IkZhY2Vib29rXzE5NDkyNzI0OTg1MDM3ODcifQ.GhaV996dFl7vx-tdkhhuq5HeSG0K5Tn20arF4M2i6YyRdm12mGJBWfmStOLLTzvYzz9ABRcIRmvy8imTSblafKMEqfDoRXn475g3xt0qs-omQTF2aFO_fi1wCCAMqT2Tb7LNG0CnGrcVXyutf3xB6vRg7ge7u6WPOEZqkLqf5bq2e5MMYCFSdqPIVMwnfV0AH6lGROCPr8GqHz8vPM3tdvSGMQYVL7PcL9I3IXgA354qt91RcqrX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YslIGwikH3Dm1QiNKzoqkkUy1-fjwLRSJ5CiH9eUO8DvzB6VomNOHHN0A5F-EJbIAZFXiD3z9N86TsRyEKSpaR7JhmO20VVVLp_YvpUuY9Nagiknkx3gp08vYCBBro0dTnDDQSsOqfVTlNTI5QZz_7AQXrUl7iyAMcw91mfajw
&token_type=Bearer
&expires_in=3600
In last step I am make get user request and send accessToken as a parameter.
After hitting this API, I have got Invalid Access Token
Service: AmazonCognitoIdentityProvider;
Status Code: 400;
Error Code: NotAuthorizedException;
Request ID: 58fc3cfc-1649-11e9-91bc-3fb47a1bd404)
Invalid Access Token (Service: AmazonCognitoIdentityProvider;
Status Code: 400;
Error Code: NotAuthorizedException;
Request ID: 58fc3cfc-1649-11e9-91bc-3fb47a1bd404)
Can you try deleting your app from facebook settings and try login again.
Finally got the solution just adding endpoint manually according to my region in my request.Now Facebook and google login working fine with 'AWS Cognito'.

Events subscription via webhooks using MS graph Android SDK

I am implementing events subscription using MS graph android SDK. Below is the code.
IGraphServiceClient mGraphServiceClient = GraphServiceClientManager.getInstance(context).getGraphServiceClient();
mGraphServiceClient.getSubscriptions().buildRequest().post(getSubscription(email, expirationDate), subscriptionICallback);
private Subscription getSubscription(String email, Calendar expirationDate) {
Subscription subscription = new Subscription();
subscription.expirationDateTime = expirationDate;
subscription.notificationUrl = "<Webhook link>";
subscription.changeType = "created,updated";
subscription.resource = "me/events";
subscription.clientState = Base64.encodeToString(email.getBytes(), Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP);
return subscription;
}
The request body generated through this always throws the error:
Error during http request Error code: InvalidRequest
Error message: Could not process subscription creation payload. Are all property names spelled and camelCased properly?
POST https://graph.microsoft.com/v1.0/subscriptions
SdkVersion : graph-android-v1.0.0
Authorization : Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI[...]
{"#odata.context":"https://graph.microsoft.com/v1.[...]
400 : Bad Request
E/DefaultHttpProvider[sendRequestInternal] - 286: [...]
E/DefaultHttpProvider[sendRequestInternal] - 286: [Some information was truncated for brevity, enable debug logging for more details]
E/DefaultHttpProvider[sendRequestInternal] - 286: Throwable detail:
com.microsoft.graph.http.GraphServiceException: Error code: InvalidRequest
Error message: Could not process subscription creation payload. Are all property names spelled and camelCased properly?
POST https://graph.microsoft.com/v1.0/subscriptions
SdkVersion : graph-android-v1.0.0
Authorization : Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI[...]
{"#odata.context":"https://graph.microsoft.com/v1.[...]
400 : Bad Request
[...]
[Some information was truncated for brevity, enable debug logging for more details]
at com.microsoft.graph.http.DefaultHttpProvider.handleErrorResponse(DefaultHttpProvider.java:310)
at com.microsoft.graph.http.DefaultHttpProvider.sendRequestInternal(DefaultHttpProvider.java:246)
at com.microsoft.graph.http.DefaultHttpProvider.access$000(DefaultHttpProvider.java:47)
at com.microsoft.graph.http.DefaultHttpProvider$1.run(DefaultHttpProvider.java:129)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
E/agenday.com.pgi.agenday.ui.BaseActivity: create Subscription exceptionError code: InvalidRequest
Error message: Could not process subscription creation payload. Are all property names spelled and camelCased properly?
POST https://graph.microsoft.com/v1.0/subscriptions
SdkVersion : graph-android-v1.0.0
Authorization : Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI[...]
{"#odata.context":"https://graph.microsoft.com/v1.[...]
400 : Bad Request
[...]
[Some information was truncated for brevity, enable debug logging for more details]
but the same request body is working fine in graph explorer,
I have tried many things now but unable to resolve it. How can I get this to work for subscriptions in Android, I can't find any resources for this online.
The issue was due to the BaseSubscription model in Microsoft graph SDK where it is setting "#odata.type":"microsoft.graph.subscription" by default and subscription api is not supporting this in request body and throwing the error: 400
So I resolved it by explicitly making "#odata.type" to null in the subscription model and pass it to post request which worked successfully for me.
Thanks!

Cordova/Phonegap facebook plugin An active access token must be used to query information

I am using https://github.com/Wizcorp/phonegap-facebook-plugin to connect my cordova Android app to Facebook.
I can login with:
facebookConnectPlugin.login(["email"],
fbLoginSuccess,
function (error) { alert("ERROR:" + JSON.stringify(error)); }
);
, logout even call facebookConnectPlugin.getLoginStatus and get:
userID
accessToken
expiresIn
sig
status
but when FB.api('/me', function(response){...}) is called, I receive
{error:
{
message: An active access token must be used to query information about the current user,
type: OAuthException,
code: 2500
}
}
Also this only happens when the app is built, not tested in browser.
Solved issue by manually giving FB.apicall a token with:
FB.api('/me?access_token='+userdata.authResponse.accessToken, function(response) {...
where userdata is the response of facebookConnectPlugin.getLoginStatus
I just don't understand why doesn't it provide token automatically in android app like it does in browser.
Send the access token and the data retrieving fields with the apiString
const fields = ['email', 'first_name', 'last_name', 'gender', 'birthday', 'picture.type(large)'];
const apiString = `me?access_token=${accessToken}&fields=${fields.join(',')}`;

Android : Get the token using GoogleAuthUtils. Invalid Client ID

I am trying to get authenticated token from GoogleAuthUtils. Keep having Invalid Client ID message like this.
GLS error: INVALID_CLIENT_ID myEmailAddress audience:server:client_id:NUM.apps.googleusercontent.com:api_scope:https://picasaweb.google.com/data
The NUM = xxxxxxx-yyyyyyyy.apps.googleusercontent.com where I used xxxxxxx part. I even tried using the y parts or both but none works. Am I missing something here?
String token = GoogleAuthUtil.getToken(PicassaFragment.this.getActivity(),
Plus.AccountApi.getAccountName(client),
scope
);
This is the code i received the error message.

Categories

Resources