I'm having trouble getting this to work. I keep getting the following error:
[Error: No key provided to sign]
Here is my config code:
CloudKit.configure({
services: {
fetch: fetch
},
containers: [{
containerIdentifier: 'iCloud.io.shakd.Command-Center',
environment: 'development',
serverToServerKeyAuth: {
keyID: "MyKeyId",
privateKeyFile: "./eckey.pem",
privateKeyPassPhrase: "MyPassPhrase"
}
}]
})
Also, what is the privateKeyPassPhrase? Is it the code that was generated in the terminal?
Apple's sample code at CloudKit Catalog: An Introduction to CloudKit (Cocoa and JavaScript), shows that the required syntax for privateKeyFile is to prepend __dirname (the directory of the executing Node script) to the eckey.pem file. From config.js:
serverToServerKeyAuth: {
keyID: '<insert key ID>',
privateKeyFile: __dirname + '/eckey.pem'
}
The second critical piece of information is that after configuring CloudKit, you have to explicitly sign in using setUpAuth(). From 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);
});
After making these two changes in my JavaScript code, my script was authenticated for reading and writing to my CloudKit database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With