CloudKitJS服务器到服务器configuration
我很难得到这个工作。 我不断收到以下错误:
[Error: No key provided to sign]
这是我的configuration代码:
CloudKit.configure({ services: { fetch: fetch }, containers: [{ containerIdentifier: 'iCloud.io.shakd.Command-Center', environment: 'development', serverToServerKeyAuth: { keyID: "MyKeyId", privateKeyFile: "./eckey.pem", privateKeyPassPhrase: "MyPassPhrase" } }] })
另外,什么是privateKeyPassPhrase? 它是在terminal生成的代码?
Apple CloudKit目录中的示例代码:CloudKit(Cocoa和JavaScript)简介显示, privateKeyFile
所需的语法是将__dirname
(正在执行的Node脚本的目录)预先__dirname
到eckey.pem
文件中。 从config.js
:
serverToServerKeyAuth: { keyID: '<insert key ID>', privateKeyFile: __dirname + '/eckey.pem' }
第二个关键信息是在configurationCloudKit之后,您必须使用setUpAuth()
明确login。 从index.js
:
var container = CloudKit.getDefaultContainer(); var database = container.publicCloudDatabase; // We'll only make calls to the public database. // Sign in using the keyID and public key file. container.setUpAuth().then(function (userInfo) { println("userInfo", userInfo); return database.performQuery({ recordType: 'Test' }); }).then(function (response) { println("Queried Records", response.records); }).catch(function (error) { console.warn(error); });
在我的JavaScript代码中进行了这两个更改之后,我的脚本通过了authentication,可以读写我的CloudKit数据库。
如果您的privateKeyFile使用密码短语进行encryption,则只需要privateKeyPassPhrase。
错误
[Error: No key provided to sign]
直接来自节点的encryption模块。
看起来像你的eckey.pem文件不包含私钥。 您可以尝试以下来validation:
var fs = require('fs'); var crypto = require('crypto'); var privateKey = fs.readFileSync('./eckey.pem', 'utf8'); var signer = crypto.createSign('RSA-SHA256'); signer.update('message'); console.log(signer.sign(privateKey, 'base64'));
如果这样的话,那么你的configuration应该是:
CloudKit.configure({ services: { fetch: fetch }, containers: [{ containerIdentifier: 'iCloud.io.shakd.Command-Center', environment: 'development', serverToServerKeyAuth: { //that looks suspicious, please use the real keyID keyID: "MyKeyId", privateKeyFile: "./eckey.pem" } }] })