Developer
Ruby
Mint Reqio HS256 identity tokens on a Ruby server using the jwt gem. Compatible with Rails, Sinatra, and any Ruby 2.7+ framework.
The snippet below is exactly what the dashboard generates under Project > Settings > Identity when you choose Ruby. Copy it from the dashboard to get your real project ID and audience URL pre-filled.
Before you start
- A Reqio project
- A signing secret generated at Project > Settings > Identity
Install the jwt gem
Install
gem install jwtOr add to your
Gemfile:gem "jwt"Mint a token
# gem install jwt require "jwt" now = Time.now.to_i payload = { sub: current_user.id, email: current_user.email, traits: { # amount in cents; interval is "month" | "year" plan: current_user.plan, amount: current_user.plan_amount, interval: current_user.billing_interval, # optional CRM enrichment: 0-100 health, CRM account id, ISO renewal # date -- keys stay camelCase on the wire healthScore: account.health_score, accountId: account.crm_id, renewalAt: account.renewal_at, }, aud: "https://reqio.app/p/YOUR_PROJECT_ID", iat: now, exp: now + 300, } token = JWT.encode(payload, ENV["REQIO_SECRET"], "HS256")Replace
YOUR_PROJECT_IDwith your project ID, or copy the full snippet from the dashboard where the audience URL is pre-filled.Traits keys must stay camelCase
Reqio's verifier reads camelCase keys (
healthScore,accountId,renewalAt). Use camelCase symbols in thetraitshash,JWT.encodeserializes symbol keys by their literal name, so a snake_case symbol produces a snake_case JSON key the verifier will not recognize.Framework-specific examples:
# app/controllers/application_controller.rb require "jwt" class ApplicationController < ActionController::Base before_action :set_reqio_token, if: :user_signed_in? private def set_reqio_token now = Time.now.to_i @reqio_token = JWT.encode( { sub: current_user.id.to_s, email: current_user.email, traits: { plan: current_user.plan }, aud: ENV["REQIO_AUDIENCE"], iat: now, exp: now + 300, }, ENV["REQIO_SECRET"], "HS256" ) end end<%# app/views/layouts/application.html.erb %> <% if @reqio_token %> <script src="https://reqio.app/widget.js" data-project-id="<%= ENV['REQIO_PROJECT_ID'] %>" data-identity-token="<%= @reqio_token %>" async ></script> <% end %>Store the audience URL in
REQIO_AUDIENCEso you do not hardcode it.require "sinatra" require "jwt" get "/dashboard" do halt 401 unless session[:user_id] now = Time.now.to_i @reqio_token = JWT.encode( { sub: session[:user_id].to_s, aud: ENV["REQIO_AUDIENCE"], iat: now, exp: now + 300, }, ENV["REQIO_SECRET"], "HS256" ) erb :dashboard endSet the environment variable
Set
REQIO_SECRETto the signing secret from Project > Settings > Identity > Reveal secret. Store it via Rails credentials,dotenv, or your hosting platform's secret management; never render it into responses.Environment variable
REQIO_SECRET=your-signing-secretPass the token to the widget
For server-rendered templates, pass the token via
data-identity-token:<script src="https://reqio.app/widget.js" data-project-id="<%= ENV['REQIO_PROJECT_ID'] %>" data-identity-token="<%= @reqio_token %>" async ></script>For SPAs where the user authenticates after the initial page load, call
window.Reqio.identify()from JavaScript after login:window.Reqio.identify(token);
Traits reference
planString"pro".amountIntegerinterval"month" | "year"amount.CRM enrichment
healthScoreInteger (0-100)accountIdStringaccountId fallback).renewalAtString (ISO 8601 date)Security
Store REQIO_SECRET in your environment and never render it into responses. The JWT is short-lived and audience-bound to one Reqio project. The signing secret must remain server-side.