Ruby

This guide takes you through signing Vizzly's auth tokens (JWTs) using the ruby programming language using the ruby-jwt (opens in a new tab) package.

Install

Run the following command in your terminal

gem install jwt

Usage example

# Build the claims for the dashboard access token
dashboard_jwt_claims = {
  userReference: "<<a unique ID to refer to one or more users who share the same dashboards>>", # https://docs.vizzly.co/identity/properties/user-reference
  scope: "read_write", # "read_write" or "read" - see https://docs.vizzly.co/identity/properties/scope,
  projectId: 'prj_...', # Your project ID, copied from your project on app.vizzly.co
  expires: (Time.now + 3600).utc.iso8601
}
 
# Build the claims for the data access token
data_jwt_claims = {
  projectId: 'prj_...', # Your project ID, copied from your project on app.vizzly.co
  dataSetIds: "*", # https://docs.vizzly.co/identity/properties/data-sets
  secureFilters: {}, # https://docs.vizzly.co/identity/properties/secure-filters
  expires: (Time.now + 3600).utc.iso8601
}
 
# Load in the vizzly-private.pem from an environment variable. This will begin with and must include "-----BEGIN PRIVATE KEY-----"
# More information about loading your private key here https://docs.vizzly.co/identity/private-key-as-environment-variable
hmac_secret = OpenSSL::PKey::EC.new(ENV["VIZZLY_PRIVATE_KEY"])
 
# Sign the claims for both tokens using the private key we have just loaded.
identity_token = JWT.encode dashboard_jwt_claims, hmac_secret, 'ES256'
data_token = JWT.encode data_jwt_claims, hmac_secret, 'ES256'
 
puts "identity_token: #{identity_token}"
puts "data_token: #{data_token}"