Question:
I am trying to put login credentials like access token of auth0 login to amazon cognito and then try to upload a profile picture in my app. I am getting error from amazon like:
1 2 |
Logins don't match. Please include at least one valid login for this identity or identity pool. (Service: AmazonCognitoIdentity; Status Code: 400; Error Code: NotAuthorizedException; Request ID: 0fafe672-2863-11e9-8f0e-cdc8b612afa1) |
UploadImageTask.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
private class UploadImageTask extends AsyncTask final ConditionVariable conditionVariable = new ConditionVariable(false); Demo demo = new Demo(); File compressImage; private User user; UploadImageTask(User user) { this.user = user; } @Override protected Demo doInBackground(Void... params) { compressImage = new File(compressImage(user.getProfileUrl())); String uniqueId = UUID.randomUUID().toString(); final String keyName = "user/" + uniqueId + Global.IMAGE_JPG_EXTENSION; CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider( SettingsAccountActivity.this, BuildConfig.AMAZON_POOL_ID, Regions.fromName(BuildConfig.AMAZON_REGION)); ClientConfiguration configuration = new ClientConfiguration(); SessionManager sessionManager = new SessionManager(SettingsAccountActivity.this); String accessToken = sessionManager.getAuthToken().getAccess_Token(); Map logins.put("myname.auth0.com", "Bearer "+ accessToken); AppLogger.d(getTag(), logins.toString()); credentialsProvider.setLogins(logins); configuration.setMaxErrorRetry(3); configuration.setConnectionTimeout(501000); configuration.setSocketTimeout(501000); configuration.setProtocol(Protocol.HTTP); AmazonS3Client s3Client = new AmazonS3Client(credentialsProvider, configuration); if (BuildConfig.FLAVOR == Global.FLAVOR_PRO) { s3Client.setRegion(Region.getRegion(Regions.fromName("us-east-2"))); } TransferUtility transferUtility = new TransferUtility(s3Client, SettingsAccountActivity.this); ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); TransferObserver observer = transferUtility.upload(BuildConfig.BUCKET_NAME, keyName, compressImage, objectMetadata); observer.setTransferListener(new TransferListener() { @Override public void onStateChanged(int id, TransferState state) { if (state == TransferState.COMPLETED) { user.setProfileUrl(keyName); demo.setShow(true); demo.setKeyName(keyName); FutureTarget .load(BuildConfig.AMAZON_URL + BuildConfig.BUCKET_NAME + "/" + keyName) .downloadOnly(1024, 1024); new Thread(() -> { try { File file = futureTarget.get(); String path = file.getAbsolutePath(); AppLogger.d(getTag(), "----------------- cache Image: " + path); } catch (InterruptedException | ExecutionException e) { AppLogger.e(getTag(), e.getMessage(), e); } conditionVariable.open(); }).start(); } } @Override public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) { AppLogger.d(getTag(), "--- is Uploading"); } @Override public void onError(int id, Exception ex) { AppLogger.e(getTag(), ex.getMessage(), ex); conditionVariable.open(); demo.setKeyName(keyName); demo.setShow(false); } }); conditionVariable.block(); return demo; } @Override protected void onPostExecute(Demo demo) { super.onPostExecute(demo); if (compressImage.exists() && compressImage.delete()) { AppLogger.d(getTag(), "Compress image deleted"); } if (demo.isShow()) { String keyName = demo.getKeyName(); AppLogger.d("Key name is:", keyName); if (user.getProfileUrl().startsWith(Global.FIELD_HTTP) || user.getProfileUrl().startsWith(Global.FIELD_HTTPS)) { url = user.getProfileUrl(); user.setProfileUrl(url); } else { url = BuildConfig.AMAZON_URL + BuildConfig.BUCKET_NAME + "/" + user.getProfileUrl(); user.setProfileUrl(url); AppLogger.e("AMAZON URL:::", "url is:" + url); } Glide.with(getApplicationContext()) .load(url) .transform(new GlideCircleTransform(getApplicationContext())) .override(100, 200) .diskCacheStrategy(DiskCacheStrategy.ALL) .listener(new RequestListener @Override public boolean onException(Exception e, String model, Target mProgressView.setVisibility(View.GONE); return false; } @Override public boolean onResourceReady(GlideDrawable resource, String model, Target mProgressView.setVisibility(View.GONE); return false; } }) .into(userAccountImage); SessionManager manager = new SessionManager(SettingsAccountActivity.this); manager.getAuthToken().getUser().setProfileUrl(url); AuthToken token = manager.getAuthToken(); manager.startSession(token); ApiClient apiClient = new ApiClient(SettingsAccountActivity.this); apiClient.changeProfile(keyName, imageApiCallback); } else { showProgress(false); mProgressView.setVisibility(View.GONE); //Toast.makeText(SettingsAccountActivity.this, getResources().getString(R.string.string_java_toast_error_in_adding_task), Toast.LENGTH_SHORT).show(); } } } |
I am doing this to upload image and try to put accesstoken to amazon cognito. But I am getting error and image is not getting upload.
ErrrLog:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
2019-02-04 15:25:53.776 23419-25377/com.visualogyx.app.dev E/CognitoCachingCredentialsProvider: Failure to get credentials com.amazonaws.services.cognitoidentity.model.NotAuthorizedException: Logins don't match. Please include at least one valid login for this identity or identity pool. (Service: AmazonCognitoIdentity; Status Code: 400; Error Code: NotAuthorizedException; Request ID: 0fafe672-2863-11e9-8f0e-cdc8b612afa1) at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:729) at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:405) at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:212) at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.invoke(AmazonCognitoIdentityClient.java:559) at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.getId(AmazonCognitoIdentityClient.java:445) at com.amazonaws.auth.AWSAbstractCognitoIdentityProvider.getIdentityId(AWSAbstractCognitoIdentityProvider.java:172) at com.amazonaws.auth.AWSEnhancedCognitoIdentityProvider.refresh(AWSEnhancedCognitoIdentityProvider.java:76) at com.amazonaws.auth.CognitoCredentialsProvider.startSession(CognitoCredentialsProvider.java:601) at com.amazonaws.auth.CognitoCredentialsProvider.getCredentials(CognitoCredentialsProvider.java:388) at com.amazonaws.auth.CognitoCachingCredentialsProvider.getCredentials(CognitoCachingCredentialsProvider.java:442) at com.amazonaws.auth.CognitoCachingCredentialsProvider.getCredentials(CognitoCachingCredentialsProvider.java:76) at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4619) at com.amazonaws.services.s3.AmazonS3Client.getBucketRegionViaHeadRequest(AmazonS3Client.java:5377) at com.amazonaws.services.s3.AmazonS3Client.fetchRegionFromCache(AmazonS3Client.java:5352) at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4616) at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1728) at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.uploadSinglePartAndWaitForCompletion(UploadTask.java:214) at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.call(UploadTask.java:88) at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.call(UploadTask.java:47) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761) |
can someone help me to resolve this issue?
I have already visit the amazon forums ans and try this:
https://forums.aws.amazon.com/thread.jspa?threadID=243850 but didn’t work.
Thanks.
Answer:
This should be a configuration problem. As solution You have to create a new identity pool from scratch and added during the creation, cognito user pool as authentication provider.
if above solution doesn’t work, then workaround