问题描述
我正在就如何快速实现pubnub访问管理器进行研发,经过一番研究,我知道了:
I am doing R&D on how to implement a pubnub access manager in swift, and after some research, I come to know :
- Swift SDK不包含pubnub.grant
- 我需要使用pubnub函数实现无服务器计算
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并获取成功代码来调用上述函数,但这如何反映我的iOS应用程序.
I am calling this above function by copying URL from function and getting success code, But how this can reflect my iOS application.
无论如何,请让我知道我可以在我的应用中使用访问管理器.
推荐答案
用于Swift Apps的PubNub访问管理器
PubNub Swift SDK(访问管理器教程)没有授予权限方法,因为您需要使用您的密钥来初始化PubNub,并且永远不要在客户端应用程序中这样做.您只应在安全的服务器上这样做.您的服务器授予对传递回客户端(例如Swift应用程序)的auth-key的权限,并且该auth-key用于通过您的订阅密钥和可选的发布密钥来初始化PubNub.
PubNub Access Manager for Swift Apps
The PubNub Swift SDK (Access Manager Tutorial) does not have grant method because you need to init PubNub with your secret key and you should never do so in a client application. You should only do so in a secure server. Your server grants permissions to an auth-key that is passed back to your clients, like a Swift app, and that auth-key is used to init PubNub with your subscribe key and optionally your publish key.
- Access Manager Getting Started Guide
- PubNub Access Manager - How It Works
- Node SDK Docs - Security with Access Manager Tutorial
这篇关于如何快速实现Pubnub Access Manager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!