简体   繁体   English

Google IOT 核心-http 桥“请求缺少必需的身份验证凭据”

[英]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:一些想法:

  • (Update) Check the JWT is valid on JWT.io (更新)检查 JWT 在JWT.io上是否有效
  • Regenerate your EC public / private key and register the device again重新生成您的 EC 公钥/私钥并重新注册设备
  • Note the maximum lifetime of a token is 24 hours .请注意令牌的最长生命周期为 24 小时
  • Make sure that your device was registered with the correct credentials, region, and Cloud project.确保您的设备已使用正确的凭据、区域和 Cloud 项目注册。
  • Ensure that HTTP is enabled for your registry确保为您的注册表启用了 HTTP

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.

相关问题 com.google.cloud.datastore.DatastoreException:请求缺少必需的身份验证凭据 - com.google.cloud.datastore.DatastoreException: Request is missing required authentication credential iOS“请求缺少必需的身份验证凭据。需要 OAuth 2 访问令牌、登录 cookie 或其他有效的身份验证凭据 - iOS "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential 没有 jwt 的谷歌物联网核心设备认证 - Google IOT Core device authentication without jwt 调用 firebase.messaging.getToken() 时出现“请求缺少身份验证凭据”错误 - "Request is missing authentication credential" error when calling firebase.messaging.getToken() Lambda 事件缺失数据的 AWS IoT Core - AWS IoT Core for Lambda event missing data authorize() 缺少 1 个必需的位置参数:运行 Google Cloud SDK 示例时的“http” - authorize() missing 1 required positional argument: 'http' when running Google Cloud SDK example Chrome 扩展程序中的 Firebase 谷歌身份验证 - 获取凭据时出错 - Firebase google authentication in Chrome Extension - Error getting credential 请求缺少身份验证密钥,错误 401 - The request was missing an Authentication Key, Error 401 谷歌云 http 身份验证函数到函数 - Google cloud http authentication function-to-function 收到错误:AWS API 请求后缺少身份验证令牌 - Getting error: Missing Authentication Token after AWS API request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM