Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Apple Open CloudKit to Server-to-Server Requests

Apple Open CloudKit to Server-to-Server Requests

Apple has recently announced that CloudKit, OS X and iOS framework that provides access to Apple’s cloud platform, is now open to server-to-server web requests. This removes the previous restriction that limited access to the CloudKit public database only from iOS and Mac apps and through Apple’s web site.

CloudKit server-to-server requests adds to the previously existing features that allowed developers to providing a web interface so users could access their iCloud data. Server-to-server requests aim to give access to iCloud public database and could partially provide an alternative to Parse DBaaS, whose shutdown has been recently announced.

In order to read or write to the public CloudKit database from a server-side process or script, developers need to first generate a key pair using OpenSSL:

openssl ecparam -name prime256v1 -genkey -noout -out eckey.pem

Then, they should associate the public key with a CloudKit container by going to the CloudKit dashboard and then to API Access/Server-to-Server Keys. Once the public key has been stored, a keyID is generated that shall be included in the subpath of web services requests. Apple provides some JavaScript sample code that shows how developers can use the new method to authenticate against CloudKit. In particular, developers should build a string that concatenates three parameters:

[Current date]:[Request body]:[Web Service URL]

to be used in the request, as the following Apple-provided curl example shows:

curl -X POST -H "content-type: text/plain" -H "X-Apple-CloudKit-Request-KeyID: [keyID]” -H "X-Apple-CloudKit-Request-ISO8601Date: [date]" -H "X-Apple-CloudKit-Request-SignatureV1: [signature]" -d '{"users":[{"emailAddress":"[user email]"}]}'[container ID]/development/public/users/lookup/email

Several users on Stack Overflow have provided alternative implementation in JavaScript, PHP, and Python.

CloudKit provides several services to developers, including authentication, a private and a public database, and structured, e.g. plist-based, asset storage.

Rate this Article