gpt4 book ai didi

javascript - 如何在 swift 中实现 Pubnub Access Manager

转载 作者:行者123 更新时间:2023-11-29 05:37:34 26 4
gpt4 key购买 nike

我正在研发如何在 swift 中实现 pubnub 访问管理器,经过一些研究,我了解到:

  • Swift SDK 不包含 pubnub.grant
  • 我需要使用 pubnub 函数进行无服务器计算来实现此目的

I have created one function in the pubnub dashboard and created a module PubNub, also created a function with event type "On Request" and added code of grant.

  export default (request, response) => {
const pubnub = require('pubnub');
const kvstore = require('kvstore');

let headersObject = request.headers;
let paramsObject = request.params;
let methodString = request.method;
let bodyString = request.body;

response.headers['Access-Control-Allow-Origin'] = '*';
response.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept';
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, OPTIONS, PUT, DELETE';
response.headers['Content-Type'] = 'application/json';

var uuid = 'aartisagarvadgama'

return pubnub.grant({
channels: ['channel_atts_pubnub'],
read: true, // false to disallow
write: false, // false to disallow,
authKeys: [uuid],
ttl: 0
}).then(() => {
console.log('grant success')
response.status = 200;
return response.send(uuid);
}).catch((error) => {
console.log(error);
response.status = 400;
return response.send();
});
};

我通过从函数复制 URL 并获取成功代码来调用上面的函数,但这如何反射(reflect)我的 iOS 应用程序。

无论如何,请告诉我如何在我的应用程序中实现访问管理器。

As per my understanding, I need to create a function and by calling that function I can grant the user. After that When I will try to subscribe or publish, I will get 200 instead of 403. Any help will be appreciated. Please help me.

最佳答案

Swift 应用程序的 PubNub 访问管理器

PubNub Swift SDK (Access Manager Tutorial)没有 grant 方法,因为您需要使用 key 初始化 PubNub,并且永远不应该在客户端应用程序中这样做。您应该只在安全服务器中执行此操作。您的服务器向传回客户端的身份验证 key 授予权限,例如 Swift 应用程序,并且该身份验证 key 用于使用您的订阅 key 和(可选)您的发布 key 来初始化 PubNub。

另请参阅

关于javascript - 如何在 swift 中实现 Pubnub Access Manager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56889108/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com