- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
以前也有类似的问题,我也找了很多,虽然我找到的答案并没有帮助我解决问题。
我正在尝试为我的 IoT 设备连接到 AWS 的 MQTT 代理,我正在通过 AWS Amplify 的 PubSub 库使用基于 Web 套接字的 MQTT。身份验证也通过 Amplify 处理(是的,用户已成功通过身份验证)。当我尝试连接时,它会立即关闭并显示错误消息:
errorCode: 8, errorMessage: AMQJS0008I Socket closed.
我已经为身份池设置了一个 IAM Angular 色,并将 IoT 策略附加到经过身份验证的用户(使用从 Amplify 检索到的身份 ID)。
用于附加策略的命令:
aws iot attach-principal-policy --policy-name "Air-RME-Users" --principal "ap-northeast-1:4f76a019-9f84-44f0-a23d-48357210016c"
感谢任何帮助,谢谢!
CloudWatch
物联网日志:
{
"timestamp": "2018-07-05 04:00:42.998",
"logLevel": "ERROR",
"traceId": "<removed>",
"accountId": "<removed>",
"status": "Failure",
"eventType": "Connect",
"protocol": "MQTT",
"clientId": "4e900ea4-8f05-4022-98a8-c1b26280b2a2",
"principalId": "<removed>:CognitoIdentityCredentials",
"sourceIp": "<removed>",
"sourcePort": 54641,
"reason": "AUTHORIZATION_FAILURE"
}
Cognito 身份池策略:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:Connect",
"iot:Publish",
"iot:Subscribe",
"iot:Receive",
"iot:GetThingShadow",
"iot:UpdateThingShadow",
"iot:DeleteThingShadow"
],
"Resource": [
"*"
]
}
]
}
物联网政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "iot:*",
"Resource": "arn:aws:iot:ap-northeast-1:<removed>:topic/*"
}
]
}
测试代码:
import Amplify from 'aws-amplify';
import {AWSIoTProvider} from 'aws-amplify/lib/PubSub/Providers';
require('babel-polyfill');
global.app = function () {
let user = null;
const onBtn = document.getElementById("on");
const offBtn = document.getElementById("off");
Amplify.configure({
Auth: {
// REQUIRED only for Federated Authentication - Amazon Cognito Identity Pool ID
identityPoolId: 'ap-northeast-1:<removed>',
// REQUIRED - Amazon Cognito Region
region: 'ap-northeast-1',
// OPTIONAL - Amazon Cognito User Pool ID
userPoolId: 'ap-northeast-1_<removed>',
// OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
userPoolWebClientId: '<removed>',
// OPTIONAL - Enforce user authentication prior to accessing AWS resources or not
mandatorySignIn: true,
}
});
Amplify.addPluggable(new AWSIoTProvider({
aws_pubsub_region: 'ap-northeast-1',
aws_pubsub_endpoint: 'wss://<removed>.iot.ap-northeast-1.amazonaws.com/mqtt',
}));
process();
async function process() {
await Amplify.Auth.signIn("test@test.com", "Test1234567")
.then(user => {
console.log("ログインできました。")
onBtn.style.visibility = "visible";
offBtn.style.visibility = "visible";
console.log(user);
if (user.challengeName === "NEW_PASSWORD_REQUIRED") {
const currentPassword = "Test123456";
const newPassword = "Test1234567"
user.completeNewPasswordChallenge(newPassword)
.then(() => {
// winning
}).catch(error => {
console.log(error);
});
}
})
.catch(err => {
alert("ログインできませんでした。");
console.log(err);
});
Amplify.Auth.currentCredentials().then((info) => {
const cognitoIdentityId = info._identityId;
console.log(cognitoIdentityId);
});
Amplify.PubSub.subscribe('$aws/things/Air-RME-test/shadow/get/accepted').subscribe({
next: data => console.log('Message received', data),
error: error => console.error(error),
close: () => console.log('Done'),
});
Amplify.PubSub.publish('$aws/things/Air-RME-test/shadow/get', '');
}
};
编辑:
在附加策略之前将以下策略添加到经过身份验证的 Cognito 身份 Angular 色解决了我的问题。我使用的 arn 也有问题,所以我将同时使用 * 通配符。一旦我让它工作,将再次更新。
政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:AttachPrincipalPolicy"
],
"Resource": [
"*"
]
}
]
}
最佳答案
因此缺少一项政策。该策略必须附加到每个用户,即 iot:AttachPrincipalPolicy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:AttachPrincipalPolicy"
],
"Resource": [
"*"
]
}
] }
目前有两种方式,一种是通过CLI,一种是通过AWS Lambda Function:
'use strict';
console.log('Loading function');
var AWS = require('aws-sdk');
exports.handler = (event, context, callback) => {
console.log('Received event:', JSON.stringify(event, null, 2))
event.Records.forEach((record) => {
console.log(record.eventName);
if (record.eventName == "INSERT") {
console.log('DynamoDB Record:', JSON.stringify(record));
console.log('DynamoDB Record:', record.dynamodb['Keys']['UserId']['S']);
var user = record.dynamodb['Keys']['UserId']['S'];
const iotMgmt = new AWS.Iot();
return new Promise(function(resolve, reject) {
let params = {
policyName: "basic",
principal: user
};
iotMgmt.attachPrincipalPolicy(params, (err, res) => {
console.log("Attaching IoT policy to " + user);
if (err) {
console.error(err);
reject(err);
}
else {
resolve();
}
});
});
}
});
};
关于javascript - AWS IoT Core 连接被经过身份验证的 Cognito 用户拒绝并附有策略 [MQTT over WSS],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51184006/
我目前在 AWS 上使用 Cognito 进行用户管理, 我希望能够与我的用户一起导入 CSV 以添加到项目中。有了基本信息我就可以成功添加用户了。 不过,我想直接在 CSV 中添加一个用户和一个关联
我正在使用 Cognito 提供的 Web UI 表单,以便用户通过 OAuth 流程登录我们的网站。 我们有一个用例,用户应该跨浏览器退出所有登录的 session 。 查看文档,似乎是 Admin
一个应用程序正在通过 Open ID Connect 协议(protocol)与 进行通信AWS 认知 , 连接到 ADFS ,通过 SAML 进行通信。 Cognito 本质上是“代理”ADFS 服
我们当前在尝试创建密码中包含空格字符的用户时遇到 InvalidParameterException。 有什么方法可以更新密码策略以启用此功能,这是错误还是预期行为? 最佳答案 Cognito 的密码
Cognito 用户池配置为用户使用他们的“电子邮件地址”来注册和登录。 如果用户使用其他人的电子邮件注册,那么该电子邮件将陷入未确认状态,所有者将无法正确使用它。 话虽如此,让我提供一个具有以下场景
我在 AWS Cognito 用户池中设置了一个 OpenID Connect 身份提供商。在浏览器中尝试此 URL 时: https:///oauth2/authorize?redirect_uri
我正在开发一个应用程序,我在其中使用 AWS Cognito 来存储用户数据。我正在努力了解如何管理 Cognito 的备份和灾难恢复方案! 以下是我的主要问题: 我想知道这些存储的用户数据的可用性如
用户在 Cognito 中更新电子邮件,Cognito 将电子邮件验证标志翻转为 false 并发送验证电子邮件。如果 Cognito 无法发送电子邮件或代码已过期,我将如何强制 Cognito 重新
有没有一种方法可以对Amazon Cognito用户池中的用户强制执行密码过期策略? 最佳答案 password policy似乎没有内置过期功能。您可以通过添加passwordUpdatedAt字段
我已使用连接到 Google 身份提供商的应用客户端设置了 Cognito 授权方。 “回调 URL”为 http://localhost而“退出 URL”是 http://localhost/log
我正在使用 Aws Cognito,但无法找到从 Cognito 登录页面中删除“注册”按钮的解决方案。谢谢。 Cognito 用户池提供了默认登录页面,其中包含忘记密码、登录和注册。但我想从该页面隐
这个问题在这里已经有了答案: Reference - What does this regex mean? (1 个回答) 4年前关闭。 我正在使用 AWS Cognito 对我的应用程序进行身份验证
我们正在使用 Cognito。一切都很好。我使用 AdminCreateUser API 添加了一个用户,他们收到了他们的临时密码。不幸的是,他们等了一个多月才登录,现在当他们尝试使用临时密码登录时,
我们使用 Cognito 托管 UI 和本地帐户登录以及少数 SAML 提供商。有一个选项可以自定义一些样式,但我正在寻找一些额外的东西。 添加自定义文本和指向外部网站的链接 - 例如条款和条件 SA
Amazon Cognito 会针对忘记密码请求发送一封验证电子邮件。如何使用个性化参数更新此验证电子邮件,使其包含以下参数:(用户名/电子邮件)。 最佳答案 您可以为自定义消息使用类似于下面的 la
我想创建一个允许用户注册的服务,但这些用户可以是团队或组织的一部分;就像任何其他服务一样,例如Slack、Trello、Google Apps 等。因此,这些用户需要从他们注册的上级团队或组织继承设置
如果激活验证功能,Amazon Cognito 会自动发送验证码。在我的项目中,有时我会添加用户(AWS Java SDK 中的注册功能)并通过 AdminConfirmSignup 自己验证它们,所
我正在使用 AWS Cognito 通过向用户的电子邮件发送验证链接来验证用户的电子邮件。用户点击链接后,默认的确认信息“您的注册已被确认!”显示。有没有办法自定义此消息? 谢谢! 最佳答案 目前(2
Cypress 有没有办法与 Cognito 集成?我有一个没有登录页面的应用程序,但使用来自另一个具有 Cognito 登录名的网站的 cookie。 (使用cookies) 无论如何,是否可以在不
每当我使用除以下内容之外的任何redirect_uri 将浏览器定向到 Cognito 注销端点时: http://localhost:63882/signin-oidc 我收到“redirect_m
我是一名优秀的程序员,十分优秀!