长话短说
为什么没有authenticate(或)与 AWS Cognito/AWS Cognito 身份提供商中的或login相同?SignUpChangePassword
--
我正在努力了解如何将 AWS Cognito 实施到 API 流程中。我对此进行了广泛的研究,感觉功能是如此明显,我一定是误解了某些东西。
该 API 将服务于 Android、iOS 和 SPA。我想象通过我的 api 的基本流程,端点如下:
/v1.0/authenticate/
Run Code Online (Sandbox Code Playgroud)
它会接受用户/密码,然后服务器上的 PHP 会执行如下操作:
require 'vendor/autoload.php';
$sdk = new Aws\Sdk([
'region' => 'us-east-1',
'version' => 'latest'
]);
$client = $sdk->createCognitoIdentity(['profile' => 'app-test-cognito']);
$result = $client->login([
'ClientId' => '6p16oao60fvakje31lexabcmplgecliecd99ntid',
'Username' => $user,
'Password' => $pwd]);
Run Code Online (Sandbox Code Playgroud)
并且$result会是一个 json 字符串,类似于
{
"result": "success",
"token": "<the token>"
}
Run Code Online (Sandbox Code Playgroud)
并且token将返回给客户端,客户端将其存储在 localStorage/内存中,并在每次其他 API 调用时返回它,直到它过期,使用Authorization: …
我正在使用 React Native 构建一个移动应用程序。借助这个库https://github.com/AirLabsTeam/react-native-aws-cognito-js,我可以通过应用程序注册和登录用户,并且 Cognito 返回访问令牌到应用程序。
现在,应用程序将使用此令牌对 Rails 后端进行 api 调用。(对于每个 API 调用。)
1)Rails方如何验证token是否良好?
2)如何获取用户的电子邮件?
3)AWS有API端点吗?
4)有类似的例子吗?
谢谢
我尝试在 cognito + Node Js 应用程序中自动确认我的用户。我尝试将此代码作为 Util,并在函数内部;并且无法让它发挥作用
我尝试查看 aws 文档,但代码不明确并且没有解释太多。
这是我的代码:
userPool.signUp(req.body.email, req.body.password, attributeList,
null, function (err, result) {
event = {
request: {
"userAttributes": {
"email": req.body.email
},
"validationData": {
"Name": "email",
"Value": req.body.email
}
},
response: {
autoVerifyEmail: true
}
}
// Confirm the user
// Set the email as verified if it is in the request
if (event.request.userAttributes.hasOwnProperty("email")) {
event.response.autoVerifyEmail = 'true';
}
// Return to Amazon Cognito
callback(null, event);
if (err) {
console.log("Error aws: ", err.message); …Run Code Online (Sandbox Code Playgroud) 我正在尝试调用 Lambda 的突变,该突变由计时器定期触发。这就是我正在做的
const params = {
AccountId: "XXXXXXX",
RoleArn: "arn:aws:iam::XXXX:role/appsync_lamda_role", // tried removing this too
IdentityPoolId: "ap-southeast-1:xxxx-xxxx-xxx-xxxx-xxx",
LoginId: "demo_access" // tried with and without this
};
AWS.config.update({
region: "ap-southeast-1",
credentials: new AWS.CognitoIdentityCredentials(params)
});
Run Code Online (Sandbox Code Playgroud)
现在,我打电话
AWS.config.credentials.get(err => {
const signer = new AWS.Signers.V4(httpRequest, "appsync", true);
signer.addAuthorization(AWS.config.credentials, AWS.util.date.getDate());
const options = {
method: httpRequest.method,
body: httpRequest.body,
headers: httpRequest.headers
};
fetch(uri.href, options)
.then(res => res.json())
.then(json => {
console.log(`JSON Response = ${JSON.stringify(json, null, 2)}`);
callback(null, event);
})
.catch(err => {
console.error(`FETCH ERROR: …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建 Lambda 并从 Cognito 预注册触发器触发它。lambda 应该保持注册正常工作,但它应该在 Cognito 中创建用户后立即禁用用户!
禁用用户的代码工作正常,但问题是我不能先创建用户然后再禁用!
在下面的代码中,Disableuser 函数出现错误,提示“用户不存在”!
PS:我不需要自动确认用户是真是假,我只需要用户以禁用状态存在于 Cognito 中!
请帮助!我已经被这个问题困扰三天了!!
谢谢
exports.handler = (event, context, callback) => {
// Confirm the user
event.response.autoConfirmUser = false;
// Set the email as verified if it is in the request
if (event.request.userAttributes.hasOwnProperty("email")) {
event.response.autoVerifyEmail = false;
event.request.userAttributes.adminDisableUser= false;
console.log('---------trying-222--------'+ event.request.userAttributes.adminDisableUser)
console.log('event.response= '+ JSON.stringify(event.response));
}
// Return to Amazon Cognito
callback(null, event);
/////Disable user code !!
var AWS = require('aws-sdk');
var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
AWS.config.update({
region: 'eu-west-1'
}); …Run Code Online (Sandbox Code Playgroud)我不明白我的授权有什么问题。
我有一个 Hello 函数,它只返回一条简单的静态消息。如果我在没有设置“Authorizer”的情况下部署,它就可以工作。我已经在邮递员上进行了测试。当我尝试添加授权者时,问题就出现了。
我的 Cognito 已完全正常工作。在我的前端,我可以注册,然后登录,然后从此登录会话获取令牌。
当我去邮差测试时,我总是得到“未经授权”的答案。在 Postman 上,我测试了 GET 方法,在“标头”选项卡上,我添加了“授权”属性,并粘贴了我从登录会话中获得的令牌值。我还在一些地方推荐的前缀“bearer”的值字段上对此进行了测试。没有成功。
过去一周我一直在努力解决这个问题。请,任何帮助都将非常有用。
serverless.yml
provider:
name: aws
runtime: nodejs10.x
stage: dev
region: eu-west-1
environment:
MY_TABLE: ${self:custom.myStage}_${self:custom.settings.tb_items}
MY_STAGE: ${self:custom.myStage}
MY_DOMAIN: ${self:custom.myDomain}
iamRoleStatements:
- Effect: "Allow"
Action:
- "dynamodb:GetItem"
- "dynamodb:PutItem"
- "dynamodb:UpdateItem"
- "dynamodb:DeleteItem"
- "dynamodb:Scan"
Resource: "*"
functions:
hello:
handler: ${self:custom.pathFunc}/phraseOption.hello
events:
- http:
method: GET
path: hello
cors: true
integration: lambda-proxy
authorizer:
type: COGNITO_USER_POOLS
authorizerId:
Ref: ApiGatewayAuthorizer
resources:
Resources:
CognitoUserPool:
Type: "AWS::Cognito::UserPool"
DeletionPolicy: Retain
Properties:
MfaConfiguration: OFF
UserPoolName: ${self:custom.myStage}_aePool …Run Code Online (Sandbox Code Playgroud) unauthorized amazon-cognito aws-lambda aws-api-gateway serverless-framework
我的任务是完成一项我知识有限的任务。我的任务是获取包含用户数据的 csv 并使用 python 中的 boto3 将其导入到 aws cognito 中。到目前为止我有这个:
import boto3
client = boto3.client('cognito-idp')
response = client.create_user_import_job(
JobName='TestImport',
UserPoolId=<My unique string pool id>
CloudWatchLogsRoleArn= <My unique stringrole arn id>
)
Run Code Online (Sandbox Code Playgroud)
本节工作并response输出一个字典,其中有一个名为 presignedurl 的键,我想用它来将 csv 上传到 cognitio 中。我只是不知道如何编写一个 python 函数,获取该响应字典并将 csv 上传到 cognito。任何帮助或指导表示赞赏。
谢谢你!
python authentication amazon-web-services amazon-cognito boto3
Auth.signIn({
username, // Required, the username
password, // Optional, the password
validationData, // Optional, a random key-value pair map which can contain any key and will be passed to your PreAuthentication Lambda trigger as-is. It can be used to implement additional validations around authentication
}).then(user => console.log(user))
.catch(err => console.log(err));
Run Code Online (Sandbox Code Playgroud)
所以我使用 AWS Amplify Auth.signIn
我成功登录并获取 id 令牌,看到正确的用户名和池
但会话为空...
这阻止我使用...Auth.VerifyCurrentUser
// To initiate the process of verifying the attribute like 'phone_number' or 'email'
Auth.verifyCurrentUserAttribute(attr)
.then(() => {
console.log('a verification code is …Run Code Online (Sandbox Code Playgroud) 我在我的项目中使用 React Native。在我的旧机器上,当我运行 amplify status 时,我列出了Auth和Api服务Storage。
我搬到我的新机器,安装了节点、watchman、brew 等...然后导航到我的 React Native 项目并运行:react-native run-ios,瞧,我的应用程序正在运行。对我的 AWS Api、Auth 和 Storage 的所有调用都运行良好。
现在我可以发出一些放大命令。例如amplify status。我试过:amplify env add这就是我得到的:
Users-MBP-2:projectname username$ amplify env add\nNote: It is recommended to run this command from the root of your app directory\n? Do you want to use an existing environment? Yes\n? Choose the environment you would like to use: dev\nUsing default provider awscloudformation\n\xe2\x9c\x96 There was an error …Run Code Online (Sandbox Code Playgroud) I'm trying to get a Quicksight embed URL in a lambda function,
The lambda function receives a jwtToken from the frontend created on a react app using aws amplify, all the cognito setup works well (userpool and identity pool), the user receives the role "arn:aws:iam::xx:role/Cognito_qa1_Admin" when logging in,
The role has permissions to quicksight:registerUser and quicksight:getDashboardEmbedUrl
var cognitoIdentity = new AWS.CognitoIdentity();
var params = {
IdentityPoolId: "eu-west-2:xxx-291d-xx-b9a7-8b27c73c796c", // your identity pool id here
Logins: {
// your logins here
"cognito-idp.eu-west-2.amazonaws.com/eu-west-2_xxx": …Run Code Online (Sandbox Code Playgroud) amazon-web-services amazon-cognito amazon-quicksight quicksight-embedding
amazon-cognito ×10
aws-amplify ×2
aws-appsync ×2
aws-lambda ×2
api ×1
boto3 ×1
javascript ×1
lambda ×1
node.js ×1
python ×1
ruby ×1
unauthorized ×1