我正在研究 Apple 的CloudKit Catalog 示例,我只是想让身份验证正常工作。我想在浏览器窗口(而不是 Node JS)中运行此 JS 代码。我从他们的网站上获取了他们的代码,如下所示:
\n\n<!DOCTYPE html>\n<html lang="en">\n <head></head>\n <body>\n <script>\n window.addEventListener(\'cloudkitloaded\', function() {\n\n CloudKit.configure({\n containers: [{\n containerIdentifier: \'iCloud.com.example.CloudKitCatalog\',\n apiToken: \'b86f0b5db29f04f45badba0366f39b7130a505f07765b5ba3a2ceb0cb3d96c0c\',\n persist: true,\n environment: \'production\',\n signInButton: { id: \'sign-in-button\', theme: \'black\' },\n signOutButton: { id: \'sign-out-button\', theme: \'black\' }\n }]\n })\n\n var container = CloudKit.getDefaultContainer()\n\n //-----\n function gotoAuthenticatedState(userIdentity) {\n var name = userIdentity.nameComponents\n if(name) {\n displayUserName(name.givenName + \' \' + name.familyName)\n } else {\n displayUserName(\'User record name: \' + userIdentity.userRecordName)\n }\n container\n .whenUserSignsOut()\n …Run Code Online (Sandbox Code Playgroud) 所以我通读了苹果给我们的例子(CloudKit 目录),我注意到每次你想写或读的时候,你都需要把你的 API 令牌放入脚本中。
现在 Javascript 是基于客户端的,这意味着每个用户都可以读取 API 令牌并可以读取和写入我的容器?!
此代码将位于其中一个 Javascript 文件中
CloudKit.configure({
locale: 'en-us',
containers: [{
// Change this to a container identifier you own.
containerIdentifier: 'com.example.apple-samplecode.cloudkit-catalog',
apiTokenAuth: {
// And generate a web token through CloudKit Dashboard.
apiToken: '<insert your token here>',
persist: true, // Sets a cookie.
signInButton: {
id: 'apple-sign-in-button',
theme: 'black' // Other options: 'white', 'white-with-outline'.
},
signOutButton: {
id: 'apple-sign-out-button',
theme: 'black'
}
},
environment: 'development'
}]
});
Run Code Online (Sandbox Code Playgroud)
现在的问题是:我是否遗漏了什么,或者是用户通过 Node 进行服务器到服务器通信的解决方案?
使用CloudKit.js,如何构建一个匹配字段为零的项的查询?我尝试过的每个排列都失败了 - 要么它在字符串值上明显匹配(即"null"或"nil"),要么我实际尝试传递'null'时会抛出错误.
有任何想法吗?以下都不起作用.
filterBy: [{
fieldName: 'customerNumber',
comparator: 'EQUALS',
fieldValue: { value: "nil" }
}]
filterBy: [{
fieldName: 'customerNumber',
comparator: 'EQUALS',
fieldValue: { value: null }
}]
filterBy: [{
fieldName: 'customerNumber',
comparator: 'EQUALS',
fieldValue: { value: "null" }
}]
filterBy: [{
fieldName: 'customerNumber',
comparator: 'EQUALS',
fieldValue: { value: "" }
}]
Run Code Online (Sandbox Code Playgroud) 我对网络开发非常陌生。我已经下载了 CloudKit JS 并在 script 标签中添加了 index.html 。我确保它在我的 React-Redux 包 JS 之前加载。
<script src="/cloudkit.js"></script>
<script src="/bundle.js"></script>
Run Code Online (Sandbox Code Playgroud)
我已经制作了单类组件,并且正在组件上运行身份验证,安装如下。
componentWillMount() {
CloudKit.configure({
containers: [{
containerIdentifier: '<container ID>',
apiToken: '<secret api token>',
environment: 'development'
}]
});
var container = CloudKit.getDefaultContainer();
container.setUpAuth().then(function(userInfo) {
if(userInfo) {
console.log(userInfo);
} else {
console.log('need to login');
}
});
}
Run Code Online (Sandbox Code Playgroud)
cloudkit ×3
javascript ×2
cloudkit-js ×1
node.js ×1
react-redux ×1
reactjs ×1
redux ×1
security ×1