Wes Thompson Wes Thompson - 1 month ago 18
TypeScript Question

PubNub Presence Repeating 403 Forbidden Error

I'm trying to use PubNub presence in my app and I'm getting a repeating forbidden error. I do have the permissions enabled in the PubNub Admin Portal.

Here is my subscription code:

var initSettings: pubnub.IInitSettings = {
publish_key: "myPubKey",
subscribe_key: "mySubKey",
uuid: "myUUID",
auth_key: "myAuthKey"
};

this.pubnub = PUBNUB(initSettings);
console.log(this.pubnub);

var subscribeSettings: pubnub.ISubscribeSettings = {
channel: "chat",
presence: this.userConnected,
message: this.processMessage
};

this.pubnub.subscribe(subscribeSettings);


This is my
userConnected
callback:

userConnected = (m: any) => {
var hereNowSettings: pubnub.IHereNowSettings = {
channel: this.channelString,
callback: (message: any) => {
this.channelCount++;
}

};

this.pubnub.here_now(hereNowSettings);
};


I get a repeating error that says


pubnub-3.7.14.js:2644 GET http://ps17.pubnub.com/subscribe/mySubKey/chat%2Cchat-pnpres/0/0?uuid=myUUID&pnsdk=PubNub-JS-Web%2F3.7.14 403 (Forbidden)



I don't understand why I'm getting this error. Can anyone explain this?

UPDATE:



I added a secret key and grant to my pubnub config:

createPubNubConnections() {
let initSettings: pubnub.IInitSettings = {
publish_key: publishKey,
subscribe_key: subscribeKey,
uuid: uuid,
auth_key: authKey,
secret_key: secretKey
};

this.pubnub = PUBNUB(initSettings);
console.log(this.pubnub);

let subscribeSettings: pubnub.ISubscribeSettings = {
channel: "chat",
presence: this.userConnected,
message: this.processMessage
};

this.pubnub.subscribe(subscribeSettings);

let grantSettings: pubnub.IGrantSettings = {
read: true,
callback: (message: any) => { console.log(message); }
};

this.pubnub.grant(grantSettings);
}


However, now I'm getting an error that says


Missing Secret Key

Answer

PubNub Access Manager & Granting Permissions

If you have Access Manager enabled then your server must grant permission to read on the channel and the presence channel if you are going to subscribe (with presence) on that channel.

You said:

permissions enabled in the PubNub Admin Portal

... but you do not enable (grant) permissions in the Admin Portal, you grant permission in code using the secret key.

See the following links for how to use Access Manager to grant permissions:

Comments