Skip to content

PubNub Ruby SDK: PAM v3 Token Generation Issue #166

@sunnybogawat

Description

@sunnybogawat

I am migrating from Access Manager (PAM) v2 to PAM v3 using the guide provided by PubNub: PAM v3 Migration Guide. As part of this migration, I updated my Ruby code for token generation. However, I’m encountering a 403 Forbidden error on the frontend when a heartbeat call is initiated using the token generated by this code.

Below is the sample code I’m using for token generation

pubnub = Pubnub.new(
  subscribe_key: Settings.pubnub.subscribe_key,
  publish_key: Settings.pubnub.publish_key,
  secret_key: Settings.pubnub.secret_key,
  user_id: user.id.to_s,
)

token_future = pubnub.grant_token(
  ttl: 15,
  authorized_uuid: user.uuid,
  channels: {
    "#{entity_id}#{PUBNUB_CHANNEL_DELIMETER}#{PUBNUB_WILDCARD}": Pubnub::Permissions.res(
      read: true,
      write: true,
      manage: false
    )
  }
)

token_response = token_future.value
if token_response.is_a?(Pubnub::Envelope) && token_response.status[:code] == 200
  token = token_response.result[:data]["token"]
end
return token

Key Issues:

  • Forbidden Error: The frontend encounters a 403 Forbidden error during heartbeat calls made using the token generated with the above code.

  • Token Validation: How can I validate if the token generated through this code is valid?

  • Documentation and Examples: Is there more specific documentation or a code sample available for generating tokens using the Ruby SDK with PAM v3?

Questions:

  • Is the provided code snippet the correct way to generate a token for PAM v3 using the PubNub Ruby SDK?

  • Are there additional configurations or steps required to ensure the generated token works correctly for heartbeat calls?

  • Are there any available tools or methods to debug or validate the generated token?

Environment Details:

  • PubNub gem version: [5.3.5]

  • Ruby Version: [3.0.7]

  • Rails Version: [6.1]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions