我在浏览器脚本中获取凭据时遇到问题。
身份验证服务器返回 cognito_identityId 和 cognito_token。
然后我设置一个Cookie:
我尝试在浏览器上通过 4 种方式获取凭据,但都失败了:
CognitoIdentityCredentials
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'us-east-1:xxxxxxxxxxxx'
IdentityId: $.cookie('cognito_identityId'),
Logins: {
'myauth': $.cookie('cognito_token')
}
});
//=> 错误:参数中缺少必需的键“IdentityId”
assumeRoleWithWebIdentity
var params = {
RoleArn: 'arn:aws:iam::xxxxxxxxxxxx:role/Cognito_xxxxxxxAuth_Role',
RoleSessionName: 'xxxxxxxxxxx',
WebIdentityToken: $.cookie('cognito_token'),
DurationSeconds: 900,
ProviderId: 'myauth'
};
var sts = new AWS.STS({apiVersion: '2011-06-15'});
sts.assumeRoleWithWebIdentity(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
//=> AccessDenied: 未授权执行 sts:AssumeRoleWithWebIdentity
政策文件
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Federated": "cognito-identity.amazonaws.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"cognito-identity.amazonaws.com:aud": "us-east-1:xxxxxxxxxxxxx"
},
"ForAnyValue:StringLike": {
"cognito-identity.amazonaws.com:amr": "authenticated"
}
}
}
]
}
GetCredentialsForIdentity
var params = {
IdentityId: $.cookie('cognito_identityId'),
Logins: {
"myauth": $.cookie('oauth.io_token')
}
};
var cognitoidentity = new AWS.CognitoIdentity({apiVersion: '2014-06-30'});
cognitoidentity.getCredentialsForIdentity(params, function(err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
}
else {
console.log(data); // successful response
}
});
//=> InvalidParameterException: 请提供有效的公共(public)提供者
WebIdentityCredentials
AWS.config.credentials = new AWS.WebIdentityCredentials({
RoleArn: 'arn:aws:iam::xxxxxxxx:role/Cognito_xxxxxxxxxxAuth_Role',
WebIdentityToken: $.cookie('cognito_token')
});
//=> 错误:有 2 个验证错误: //* MissingRequiredParameter:参数中缺少必需的键“IdentityPoolId” //* MissingRequiredParameter:参数中缺少必需的键“IdentityId”
问题:
我做错了什么?
正确的使用方法是什么?
谢谢。
谢谢你的好意。
我接受了你的建议,但没有改变。
错误信息。
POST https://cognito-identity.us-east-1.amazonaws.com/ 400 (Bad Request)
POST https://cognito-identity.us-east-1.amazonaws.com/ 400 (Bad Request)
Error: Missing required key 'IdentityId' in params
at fail (chrome-extension://hmjdjbikinkmjbilihjibcihbkbjdgjf/bower_components/aws-sdk-js/dist/aws-sdk.js:2163:37)
at validateStructure (chrome-extension://hmjdjbikinkmjbilihjibcihbkbjdgjf/bower_components/aws-sdk-js/dist/aws-sdk.js:2084:14)
at validateMember (chrome-extension://hmjdjbikinkmjbilihjibcihbkbjdgjf/bower_components/aws-sdk-js/dist/aws-sdk.js:2110:21)
at validate (chrome-extension://hmjdjbikinkmjbilihjibcihbkbjdgjf/bower_components/aws-sdk-js/dist/aws-sdk.js:2059:10)
at Request.VALIDATE_PARAMETERS (chrome-extension://hmjdjbikinkmjbilihjibcihbkbjdgjf/bower_components/aws-sdk-js/dist/aws-sdk.js:800:32)
at Request.callListeners (chrome-extension://hmjdjbikinkmjbilihjibcihbkbjdgjf/bower_components/aws-sdk-js/dist/aws-sdk.js:3913:20)
at callNextListener (chrome-extension://hmjdjbikinkmjbilihjibcihbkbjdgjf/bower_components/aws-sdk-js/dist/aws-sdk.js:3903:12)
at chrome-extension://hmjdjbikinkmjbilihjibcihbkbjdgjf/bower_components/aws-sdk-js/dist/aws-sdk.js:787:9
at finish (chrome-extension://hmjdjbikinkmjbilihjibcihbkbjdgjf/bower_components/aws-sdk-js/dist/aws-sdk.js:126:7)
at chrome-extension://hmjdjbikinkmjbilihjibcihbkbjdgjf/bower_components/aws-sdk-js/dist/aws-sdk.js:142:9
链接下方有源码
https://github.com/bisque33/my-custom-dictionary
服务器端是 AWS Lambda 函数。
var aws = require('aws-sdk');
aws.config.region = 'us-east-1';
var cognitoidentity = new aws.CognitoIdentity();
var identityPoolId = 'us-east-1:0dccff0d-5fd7-4d14-b38f-d27204feaecc';
console.log('Loading function');
exports.handler = function(event, context) {
console.log('token: %s', event.token);
var params = {
IdentityPoolId: identityPoolId,
Logins: {
'oauth.io': event.token
}
};
cognitoidentity.getOpenIdTokenForDeveloperIdentity(params,function(err,data){
if(err){
console.log(err);
context.fail('Something went wrong');
}else{
context.succeed(data);
}
});
};
这个程序是 Google-Chrome-Extension。
我是不是用错了?
感谢您提供更多信息。
background.js 104行出现错误
AWS.config.credentials.get(function(){
和 background.js 上的 115 行
dataset.synchronize(
而且,我的解释还不够。 Facebook 身份验证需要域(例如 http://example.com)。但是,Google-Chrome-Ext 没有域。它有一个域“chrome-extension://xxxxxxxxxxxxxxxxxxxx”。然后,我使用 https://oauth.io .它代理任何身份验证并接受 chrome-extension 域。
Popup.js 通过 oauth.io sdk 进行 Facebook 身份验证。它获取一个 facebook token ,并提供给 getOpenIdTokenForDeveloperIdentity。我认为 facebook token.substr(0,14) 是独一无二的。但是,如果它是错误的,我会使用另一个唯一标识符(例如电子邮件地址。)
对不起,我错了。 AWS.config.credentials.get 给出错误:
Error: Invalid login token.
并且,dataset.synchronize 显示此错误:
Error: Missing required key 'IdentityId' in params
最佳答案
第一种方法,使用 CognitoIdentityCredentials , 很可能是您可以采用的最佳方法。我无法准确找出导致错误的原因,但让我们尝试一些操作:
'cognito-identity.amazonaws.com' 并确保该值是从后端调用 getOpenIdTokenForDeveloperIdentity 返回的 token 。如果您在使用 CognitoIdentityCredentials 方法时仍然遇到问题,请在此处回复并提供更多信息,例如您在收到错误消息时调用的确切方法/代码,以及跟踪输出(即使用 console.log( '%o',..)) 在您调用 CognitoIdentityCredentials 构造函数之前输入的参数。
我仍然需要确切地知道您在哪一行代码中收到错误,但根据提供的信息,我认为我仍然可以提供帮助...
根据我在 background.js 中看到的内容,看起来您正在尝试使用开发人员身份验证提供程序来初始化 CognitoIdentityCredentials。这是我猜你收到错误的地方。
然而,在Popup.js ,看起来您正在尝试通过 Facebook 对用户进行身份验证。如果您使用 Facebook 对用户进行身份验证,则在使用 Cognito 时,您应该只将 facebook 访问 token 传递到您的登录映射中。只需使用 graph.facebook.com 作为登录映射中的键和来自 Facebook 的访问 token 。有关如何执行此操作的更多详细信息,请参阅 Facebook Integration topic of the Amazon Cognito developer guide .
我们可以让 Developer Authenticated Identities 为您工作,但在这种情况下,它看起来不是适合您的解决方案,因为您实际上并没有对 Lambda 函数中的身份进行任何额外的身份验证,并且唯一您传递给 getOpenIdTokenForDeveloperIdentity 操作的用户标识符似乎是 facebook token ,顺便说一句,这并不好,因为即使对于同一用户, token 本身也会在用户 session 之间发生变化。通常一个好的唯一标识符是内部系统使用的电子邮件地址或用户 ID。
由于您最终尝试使用 Facebook 进行登录,而 Amazon Cognito 具有 built-in integration for Facebook ,您最好的做法是从 Facebook 获取访问 token ,然后将 Facebook token 直接传递给 Cognito 的登录映射。我不确定这是否适用于 Auth.io(我只是不熟悉它),但只要 Auth.io 为您的 JavaScript 代码提供一个可靠的 facebook token ,并且您将相同的 Facebook App ID 添加到Auth.io 和 Amazon Cognito 的控制台,它应该可以工作。但是,您提到您想使用 Auth.io 来避免 Facebook 重定向到登录页面。我可能弄错了,但我很确定你是否使用 Facebook's JavaScript SDK您不需要重定向页面。如果你正在做 Facebook's Manually Build a Login Flow,你应该只需要重定向页面.
关于javascript - AWS Cognito - JavaScript 中的开发人员身份验证(浏览器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31976873/
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
我正在编写一个包含C扩展的gem。通常当我写一个gem时,我会遵循TDD的过程,我会写一个失败的规范,然后处理代码直到它通过,等等......在“ext/mygem/mygem.c”中我的C扩展和在gemspec的“扩展”中配置的有效extconf.rb,如何运行我的规范并仍然加载我的C扩展?当我更改C代码时,我需要采取哪些步骤来重新编译代码?这可能是个愚蠢的问题,但是从我的gem的开发源代码树中输入“bundleinstall”不会构建任何native扩展。当我手动运行rubyext/mygem/extconf.rb时,我确实得到了一个Makefile(在整个项目的根目录中),然后当
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
我注意到像bundler这样的项目在每个specfile中执行requirespec_helper我还注意到rspec使用选项--require,它允许您在引导rspec时要求一个文件。您还可以将其添加到.rspec文件中,因此只要您运行不带参数的rspec就会添加它。使用上述方法有什么缺点可以解释为什么像bundler这样的项目选择在每个规范文件中都需要spec_helper吗? 最佳答案 我不在Bundler上工作,所以我不能直接谈论他们的做法。并非所有项目都checkin.rspec文件。原因是这个文件,通常按照当前的惯例,只