解析服务器:REST-API-密钥验证不起作用

Parse Server: REST-API-Key Authentication does not work

我将解析服务器配置如下:

var api = new ParseServer({
    databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
    cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
    appId: process.env.APP_ID || 'XXXXXXXXXXXXXXX',
    clientKey: process.env.CLIENT_KEY || 'XXXXXXXXXXXXXXX',
    restAPIKey: process.env.RESTAPI_KEY || 'XXXXXXXXXXXXXXX',
    masterKey: process.env.MASTER_KEY || 'XXXXXXXXXXXXXXX', //Add your master key here. Keep it secret!

    ...

    serverURL: process.env.SERVER_URL || 'https://myserver.com:1337'  // Don't forget to change to https if needed
});

使用指定的主密钥发送推送消息有效:

curl -X POST \
  -H "X-Parse-Application-Id: XXXXXXXXXXXXXXX" \
  -H "X-Parse-Master-Key: XXXXXXXXXXXXXXX" \
  -H "Content-Type: application/json" \
  -d '{
        "where": {
          "deviceType": {
            "$in": [
              "ios"
            ]
          }
        },
        "data": {
          "title": "The Shining",
          "alert": "All work and no play makes Jack a dull boy."
        }
      }'\   https://myserver.com/parse/push

但是,如果我只提供其余的 api 键,它不起作用。

curl -X POST \
  -H "X-Parse-Application-Id: XXXXXXXXXXXXXXX" \
  -H "X-Parse-REST-API-Key": XXXXXXXXXXXXXXX \
  -H "Content-Type: application/json" \
  -d '{
        "where": {
          "deviceType": {
            "$in": [
              "ios"
            ]
          }
        },
        "data": {
          "title": "The Shining",
          "alert": "All work and no play makes Jack a dull boy."
        }
      }'\   https://myserver.com/parse/push

我的服务器配置有什么问题?我认为它应该在我定义后立即与其余 API 键一起使用?

您可以从您的配置中删除 RESTAPI 密钥,因为它不是必需的,此时 您必须使用主密钥来发送推送 通知。您可以定义您将从 REST 运行 获得的云代码功能,这样您就不必通过网络发送主密钥 Answer on Github

你一定要试试/类/

https://myserver.com/parse//push

请求这个URL,不要错过添加

  • "X-Parse-Application-Id: XXXXXXXXXXXXXXX"
  • "X-Parse-Master-Key:XXXXXXXXXXXXXXX"
  • "Content-Type: application/json"

headers 并检查您使用的是 http 还是 https。