如何快速实现Pubnub Access Manager [英] How to implement Pubnub Access Manager in swift

查看:122
本文介绍了如何快速实现Pubnub Access Manager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在就如何快速实现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函数实现无服务器计算

我已经在pubnub信息中心中创建了一个函数,并创建了一个 模块PubNub,还创建了一个事件类型为"On Request"的函数 并添加了授权代码.

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并获取成功代码来调用上述函数,但这如何反映我的iOS应用程序.

I am calling this above function by copying URL from function and getting success code, But how this can reflect my iOS application.

无论如何,请让我知道我可以在我的应用中使用访问管理器.

据我了解,我需要创建一个函数并通过调用 该功能我可以授予用户.之后,当我尝试 订阅或发布,我将得到200而不是403.任何帮助都将是 赞赏.请帮助我.

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 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆