Thanos Thanos - 1 year ago 78
Javascript Question

Message: 'Forbidden' when trying to add channel to channel group in PubNub

I am trying to add a channel to a channel group and associate an auth_key for pub/sub to this channel using this code:

callback: function(success) {
channel: channelName,
auth_key: userAuthKeyForChannel,
read: true,
write: true,
callback: function(response){
res.status(200).json({response: {ChatChannel: createdRecord}, token:req.token});

error: function(err) { return hlprs.sendResWithErr(res,err,500,true,'Error while trying to add channel to group in our messaging platform'); },
channel: channelName,
channel_group: channelGroupName

But I always get the response

{ message: 'Forbidden',
payload: { 'channel-groups': [ ':90c977bbc169b12054706b0de07dd9f2' ] }

When I disable Access Manager in PubNub admin panel, it (obviously) works perfectly. I'd also like to mention that this request takes place in a server backend where pubnub is initialized with subscriber_key, publish_key and secret_key. There are no other pubnub requests prior to this one and there's no one subscribed in other environments.

EDIT: I suppose I need to grant permissions to the backend at the application level before proceeding with adding the channel in a group, however I am unsure how to properly do this.

Answer Source

How do I secure my Channel Groups and Namespaces?

Read more about PubNub JavaScript Stream Controller documentation.

Grant access to manage Channel Group

    channel_group : "90c977bbc169b12054706b0de07dd9f2",
    auth_key      : "SUPER_SECRET",
    channel       : channel,
    read          : true,
    write         : true,
    manage        : true,      // <-- Manage Permission TRUE
    callback      : success,
    error         : errorback
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download