Mastering the Integration of Pubnub Access Manager in Swift

Currently, I am conducting research and development on integrating a pubnub access manager in swift. Upon investigation, I discovered the following:

  • The Swift SDK does not have pubnub.grant functionality.
  • To accomplish this, I must utilize a pubnub function for serverless computing.

I have set up a function in the pubnub dashboard under the module PubNub, with an event type of "On Request", and included the grant code.

  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,
        write: false,
        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();
    });
};

Although I can successfully invoke this function by copying the URL and receiving a success code, I am unsure how to implement this in my iOS application.

Please advise me on any method to incorporate the access manager into my app.

Based on my understanding, establishing a function to grant the user access is necessary. Upon calling this function, I should be able to subscribe or publish content without encountering a 403 error. Any assistance would be highly appreciated. Please offer guidance.

Answer №1

Implementing PubNub Access Manager in Swift Applications

The PubNub Swift SDK (Access Manager Tutorial) does not include a grant method due to security reasons. Instead, it is recommended to initialize PubNub with your secret key on a secure server rather than within a client application. Your server can then grant permissions to an authentication key, which is passed back to clients such as a Swift app. This authentication key is used to initialize PubNub with your subscribe key and optionally your publish key.

Additional Resources

  • Access Manager Getting Started Guide
  • PubNub Access Manager - How It Works
  • Node SDK Docs - Security with Access Manager Tutorial

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to check for a condition within a JSON response in a Swift iOS application

When the server responses come back as "Account Exists", I want to perform a specific action. However, when I try to compare the result, I get an error message stating that "Binary operator '==' cannot be applied to operands of type 'Any&apo ...

Disable automatic playback of HTML video

There is an HTML video with an image that loads initially and then disappears to play the video. I would like the image to always be visible until I click on it. Once clicked, the video should start playing. You can view the code on JSFiddle: http://jsf ...

Combining Two Arrays in a Customized Sequence Using Swift

After creating this code snippet in a playground and seeing it work successfully, I can't help but think it's a bit messy. Is there a more succinct way to achieve the same result in Swift? The desired output string should appear as follows: 1, 1 ...

Is it possible to extract a specific value from JSON data by making an AJAX call or applying a filter to the fetched JSON data?

I have been utilizing a treeview template and successfully displaying all the data. However, I am facing an issue where I need to pass a value from index.php to getdata.php. I attempted using an AJAX filter on the index.php page and also tried sending a v ...

Issue encountered while creating Google Chart with a CSV file stored locally

I am working on an HTML project where I am uploading a local CSV file, and my goal is to utilize the Google Charts API to create a chart from the data. However, I am encountering an error that states: script.js:29 Uncaught TypeError: Cannot read property ...

Utilizing jQuery UI for Autocomplete Functionality with Objects

Currently, I am utilizing jQuery version 1.11.2 and attempting to implement the autocomplete widget to interpret a data array. The array consists of two individuals - Will Smith and Willem Dafoe. I anticipated that upon typing 'Wi' in the text fi ...

Incorporating transitions within a styled component using @emotion/core

I'm currently working on adding a smooth transition effect when a button is clicked. The code that adjusts the isOpen property is functioning correctly. However, I'm facing an issue where instead of animating, the content just flips abruptly. I a ...

Switch a Class Component to a Functional Component

Let me explain the task first and then address my problem. The goal is to incorporate a webcam component that can capture an image and then upload it with the click of a button. I am utilizing the react-webcam library, which can be found at this link: htt ...

Merging audio files using Node Stream

Currently facing an issue with joining 2 .wav files together, as my output file only contains the first item in the array: const writeStream = fs.createWriteStream('server/playback.wav'); const inputFiles = [ `${path.resolve(__dirname, 'r ...

Arrange list items dynamically using ajax

I am attempting to adjust the positioning of the scrollable list item depending on whether a message was sent by a user or another party. However, my current method is not yielding the desired results. I have experimented with adding .css('position&a ...

Navigating in Vue.js with the back button

I have already implemented a Vue.js Routing example application found on GitHub. You can check it out here: https://github.com/chrisvfritz/vue-2.0-simple-routing-example In my src/main.js, I am managing a lot of data values. const app = new Vue({ el: ...

Submit the form by pressing the "Enter" key within the textarea field

I am attempting to submit a form by pressing the Enter key in a textarea. Here is what I have so far: $('.chatMessage').on('keyup', function(e) { if (e.which == 13 && ! e.shiftKey) { $.ajax({ url: "/index.php", type: " ...

Having trouble identifying whether a file is a picture or video based solely on its extension

My current challenge involves determining whether an uploaded file is a video or a photo. This distinction is crucial as it dictates whether the file should be sent to my telegram bot as a video or photo attachment. Despite having what seems like a logica ...

Firestore data displaying as null values

Recently, I encountered CORS errors while polling the weather every 30 seconds in my program. Upon investigating, I discovered that the city and country were being interpreted as undefined. To fetch user data from my users' table, I utilize an Axios ...

Looking to retrieve particular data using axios and React JS from an API?

1 I'm a newcomer to ReactJS and I'm trying to retrieve an image with specific text in the caption from the Instagram graph API. For instance, if an Instagram post has the word "yes" in its caption, it should be displayed on the homepage. I attem ...

Is it possible for the ".filter" function to verify if the target contains multiple attributes?

I'm currently working on a checkbox filter setup and using Jquery's .filter to sort through some divs. Below is the snippet of Jquery code that I am using: $(document).ready(function(){ var checkboxes = $('div.filter-groups').find(&ap ...

Similar to LINQ's Enumerable.First(predicate) method but with a slightly different syntax, this

When working with JavaScript, we often encounter situations where we need to find the first matching element based on certain conditions. Take for example this code snippet: function process() { var firstMatch = ['a', 'b', 'c&ap ...

Unlocking the Secrets to Adding a Hamburger Icon to Your iOS Application

As a beginner in ios development, I am embarking on creating an ios app with a Hamburger menu. My query revolves around the availability of a Unicode for this specific icon, or whether it is advisable to incorporate it as an image. ...

``How can I easily navigate to the top of the page when changing routes in React Router DOM v6?

What is the best way to scroll to the top when a route changes in react router dom v6? In the past, I used a solution from this StackOverflow post to make my page automatically scroll to the top every time a route changed with react-router-dom v5. However ...

Get alerted when a subview is added

Hi there, I'm curious about detecting when a subview is added to a scrollview without subclassing the UIScrollView and overriding the method didAddSubview:. Is it possible to receive notifications when the number of subviews changes on a scrollview ...