I was trying to use the access manager for client authorization. Unfortunately, I'm unable to use it.
I have already tried this procedure:
Note: Used C# SDK for Server side & js SDK for Client-side
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("AdminUserId"))
{
SubscribeKey = _pubNubSubscribeKey,
PublishKey = _pubNubPublishKey,
SecretKey = _pubNubSecretKey
};
_pubNubClient = new Pubnub(pnConfiguration);
PNResult<PNAccessManagerTokenResult> grantTokenResponse = await _pubNubClient.GrantToken()
//.AuthorizedUserId("my-authorized-userId")
.AuthorizedUuid("my-authorized-userId")
.TTL(60)
.Resources(new PNTokenResources()
{
Spaces = new Dictionary<string, PNTokenAuthValues>() {
{ "messenger", new PNTokenAuthValues() { Read = true, Write = true } }
})
.ExecuteAsync();
Using "AuthorizedUserId" I'm not getting authorized-userId inside the generated token. but using obsolete "AuthorizedUuid" I'm getting this. I checked it by parsing the generated access token.
After that I passed it to the client side & tried to set this token. procedure was:
let pubNubOptions = {
publishKey: _pubNubPublishKey,
subscribeKey: _pubNubSubscribeKey,
userId: "my-authorized-userId"
//uuid: "my-authorized-userId",
//authKey: "returned token"
};
let pubnub = new PubNub(pubNubOptions);
pubnub.setToken("returned token");
pubnub.subscribe({
channels: ['messenger'],
//spaces: ['messenger'],
});
Note: It is returning the "403 status code" access is forbidden.
So, how can I use Access manager for client authorization?
Spaces are an up-and-coming feature of PubNub and will become the recommended way to use PubNub (over channels and channel groups). But channels and channel groups aren't going anywhere.
Please refer to the docs for granting permissions on the channel.
PNResult<PNAccessManagerTokenResult> grantTokenResponse = await pubnub.GrantToken()
.TTL(15)
.AuthorizedUuid("my-authorized-uuid")
.Resources(new PNTokenResources()
{
Channels = new Dictionary<string, PNTokenAuthValues>() {
{ "my-channel", new PNTokenAuthValues() { Read = true } } }
})
.ExecuteAsync();