[英]Google IOT core- http bridge "request is missing required authentication credential "
I'm trying to get started with google IOT core by posting a simple http request from the command line.我正在尝试通过从命令行发布一个简单的 http 请求来开始使用 google IOT core。
I have set up my registry and device in Console, and added the public key.我已经在控制台中设置了注册表和设备,并添加了公钥。 I set up a telemetry topic.
我设置了一个遥测主题。 I've generated the JWT using a Qt application I found, using the private key.
我已经使用私钥使用我发现的 Qt 应用程序生成了 JWT。 I'm using the procedure specified at https://cloud.google.com/iot/docs/how-tos/http-bridge .
我正在使用https://cloud.google.com/iot/docs/how-tos/http-bridge中指定的程序。 My command is:
我的命令是:
curl -X POST -H 'authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJzeWx2YW4tam91cm5leS0xOTU4MTUiLCJleHAiOiIxNTIwMzU4NjMyIiwiaWF0IjoiMTUxOTc1MzgzMiJ9.kDkwtWvfAE+AOYT2cObgh8Mux2n1DOuek1KR0YrsFSI=' -H 'content-type: application/json' --data '{"binary_data": "SGVsbG8="}' -H 'cache-control: no-cache' ' https://cloudiotdevice.googleapis.com/v1/projects/sylvan-journey-195815/locations/europe-west1/registries/MyDeviceRegistry/devices/FirstDevice:publishEvent ' curl -X POST -H 'authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJzeWx2YW4tam91cm5leS0xOTU4MTUiLCJleHAiOiIxNTIwMzU4NjMyIiwiaWF0IjoiMTUxOTc1MzgzMiJ9.kDkwtWvfAE+AOYT2cObgh8Mux2n1DOuek1KR0YrsFSI=' -H 'content-type: application/json' --data '{"binary_data": "SGVsbG8="}' -H 'cache-控制:无缓存'' https://cloudiotdevice.googleapis.com/v1/projects/sylvan-journey-195815/locations/europe-west1/registries/MyDeviceRegistry/devices/FirstDevice:publishEvent '
When I try to post the command I get error 401 "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential"当我尝试发布命令时出现错误 401“请求缺少必需的身份验证凭据。需要 OAuth 2 访问令牌、登录 cookie 或其他有效的身份验证凭据”
I don't know where to look.我不知道去哪里看。 Is there a problem with my JWT?
我的 JWT 有问题吗? Is the format of the command wrong?
是不是命令格式不对? Do I need to add a public key to the registry or just to the devices.
我需要将公钥添加到注册表还是只添加到设备。 How do I find out what's wrong?
我如何找出问题所在?
Any guidance much appreciated非常感谢任何指导
A few ideas:一些想法:
How did you register your device?你是如何注册你的设备的? If the device was registered with a certificate that has expired, you could encounter authentication issues.
如果设备使用已过期的证书注册,您可能会遇到身份验证问题。
The following Python code is how I generate JWTs from the commandline for Curl-testing the HTTP endpoint assuming an RSA256 key:以下 Python 代码是我如何从命令行生成 JWT,以使用 RSA256 密钥对 HTTP 端点进行 Curl 测试:
import datetime
import jwt
import requests
algorithm = 'RS256'
cloud_region = 'your-cloud-region'
device_id = 'your-device-id'
private_key_file = 'path/to/rsa_private.pem'
project_id = 'your-project-id'
registry_id = 'your-registry-id'
token = {
# The time the token was issued.
'iat': datetime.datetime.utcnow(),
# Token expiration time.
'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=60),
# The audience field should always be set to the GCP project id.
'aud': project_id
}
# Read the private key file.
with open(private_key_file, 'r') as f:
private_key = f.read()
print(jwt.encode(token, private_key,
algorithm=algorithm).decode('ascii'))
The following image shows you the setting in the Cloud Console for enabling HTTP/MQTT that can be found under IoT Core > Registry > Edit Registry.下图显示了Cloud Console中用于启用 HTTP/MQTT 的设置,可以在 IoT Core > Registry > Edit Registry 下找到。 Note that if you disable HTTP, you will not be able to use the HTTP device bridge.
请注意,如果您禁用 HTTP,您将无法使用 HTTP 设备桥。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.