Home > other >  Help: about browser JavaScript not authenticate the access problem
Help: about browser JavaScript not authenticate the access problem

Time:10-01

I want to use Cognito temporarily get AWS certification to access some resources, to find the relevant information, found that although the official support JavaScript, but may be because the main use case is a mobile device, information is not complete, though I still think I have found the right start program, as follows:

First: to create large pools of Cognito identity (including the creation of authentication and verification role)
And then: run AWS. CognitoIdentityCredentials. Get ()

First step fails, because Cognito AWS endpoint CORS no response headers, for the mobile/desktop app is not the problem, but in the browser is a obstacle, how to solve this problem?

Base generated file attached in the end, I removed the AWS account ID, if you want to use the sample files in the attachment, in the AWS console using default Settings to create a new identity pool and from a file copy/paste region, the account ID, identity pool ID and rolearn,

I received from the browser console information is as follows:

XMLHttpRequest always load https://cognito-identity.eu-west-1.amazonaws.com/. No 'Access - Control - Allow - Origin' header is present on the requested resource. The Origin of 'http://inncognito.s3-website-eu-west-1.amazonaws.com' is therefore not allowed Access. The response had HTTP status code 404.
.
Attach my code:

Incognito error: error: Network Failure {message: "the Network Failure", code \ : "NetworkingError", time, Thu 27 Nov 2014 09:55:26 GMT + 0100 (Central European Standard time), the region: "the eu - west - 1", the hostname: "cognito-identity.eu-west-1.amazonaws.com"... }

Finally enclosing base generated file:





AWS Cognito Unauthorized access in the Browser
<script SRC="https://sdk.amazonaws.com/js/aws-sdk-2.0.29.min.js" & gt; </script>

<body>
AWS. Config. Region='eu - west - 1;
AWS. Config. Credentials=new AWS. CognitoIdentityCredentials ({
AccountId: '123456789012',
IdentityPoolId: 'the eu - west - 1: fd1 b5dbefe5 - c991-4 - b17b - aef2e1e5964f',
RoleArn: 'arn: aws: iam: : 123456789012: role/Cognito_rudimentaryUnauth_DefaultRole'
});
AWS. Config. Credentials. Get (function (err) {
if (! Err) {
The console. The log (" Cognito Identity Id: "+ AWS. Config. Credentials. IdentityId);
} else {
The console. The log (' Incognito error: ', err);
}
});
</script>



Who have encountered similar problems can help me solve? Thank you very much!
  •  Tags:  
  • AWS
  • Related