UPDATE - OFFICIAL PHP PAM SDK NOW HERE - https://github.com/pubnub/php
require('pam.php');
$manager = new access(
"pub-c-e132b7b4-0c2c-4d36-a828-1de1ea50d167",
"sub-c-f95db694-6ff9-11e3-9291-02ee2ddab7fe",
"sec-c-OWFkNWQ1NDctN2JiNy00NzJmLTk3Y2ItN2ExODZlYzkyNzY0"
);
Grant access to user with authkey
of gZW5jb2RlZCBmaWx
with read
and write
access for 5
minute ttl
.
print_r($manager->grant(
"my_channel", // CHANNEL
"gZW5jb2RlZCBmaWx", // STRING (AUTH KEY)
true, // READ
true, // WRITE
5 // TTL in MINUTES
));
Also grant access to the presence channel (required for PubNub Dev Console).
print_r($manager->grant(
"my_channel-pnpres", // CHANNEL
"gZW5jb2RlZCBmaWx", // STRING (AUTH KEY)
true, // READ
true, // WRITE
5 // TTL in MINUTES
));
Exclude the authkey
and you can global grant access to all.
print_r($manager->grant_global(
"my_channel", // CHANNEL
true, // READ
true, // WRITE
5 // TTL in MINUTES
));
You can grant access forever by setting the ttl
param to 0
.
print_r($manager->grant_global(
"my_channel", // CHANNEL
true, // READ
true, // WRITE
0 // FOREVER GRANT!!!
));
Instantly revoke access to a user.
print_r($manager->revoke(
"some-other-channel", // CHANNEL
"gZW5jb2RlZCBmaWx" // STRING (AUTH KEY)
));
You can also revoke Global Access by excluding the authkey
param.
print_r($manager->revoke(
"some-other-channel" // CHANNEL
));
WARNING: PubNub Dev Console Requires Grant on Presence Channel too! You can set the presence access by granting on the suffix of -pnpres
channel name.
This doesn't work. I am using php 5.5.12 and WAMP server.
When I do print_r($manager->grant(...)); it doesn't do anything. My app keeps getting a 403 error. I checked my dev console as well.
{"status":403,"service":"Access Manager","error":true,"message":"Forbidden","payload":{"channels":["my_channel"]}}
I also get
{"status":403,"service":"Access Manager","error":true,"message":"Forbidden","payload":{"channels":["pn_myUserID"]}}
if I do a pubnub init with the public key, sub key, auth key and my own uuid in my javscript file.
If i grant permission through the dev console, everything works fine. Therefore, I think the php grant doesn't work. Unless I am running it in the wrong place.
Please fix it!