Reputation: 854
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:
pubnub.channel_group_add_channel({
callback: function(success) {
pubnub.grant({
channel: channelName,
auth_key: userAuthKeyForChannel,
read: true,
write: true,
ttl:0,
callback: function(response){
console.log(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.
Upvotes: 2
Views: 1269
Reputation: 6834
Read more about PubNub JavaScript Stream Controller documentation.
pubnub.grant({
channel_group : "90c977bbc169b12054706b0de07dd9f2",
auth_key : "SUPER_SECRET",
channel : channel,
read : true,
write : true,
manage : true, // <-- Manage Permission TRUE
callback : success,
error : errorback
});
Upvotes: 3