If you need to pass data safely between Rails and Node, you can use the built-in Rails encryption.
The script below wraps ActiveSupport::MessageEncryptor
, allowing to create expiring JSON tokens that can be decoded in Node using a shared secret.
secret = "866b914a169d3969849966febafe8057bec6b82ea477e64682a11a2e61096797"
payload = { user_id: 1, name: "John Doe", role: "admin" }
EncryptedToken.encode(payload: payload, expires_at: 10.minutes.from_now, secret: secret)
# => "OGIwM2FkYjZjMzNkNGUyOGVjZGE2NWY1OGVlZDdhYWYwY2VlODcxMTE1MDRkZTE3NTFmMDU4MzMxZDU3NzUwMg==--bAliRJeMe0AL5qR5w6eWxCthlia2UQZgBlO9+EqPL6zevnNqzZesEt6NignGmf3hiE7b7490OWWqNKjqcuS8--GcrE9Y1djaPyS4Bv--iGnyNEuZXazbSrn7/p2JUg=="
node node-decrypt.js "OGIwM2FkYjZjMzNkNGUyOGVjZGE2NWY1OGVlZDdhYWYwY2VlODcxMTE1MDRkZTE3NTFmMDU4MzMxZDU3NzUwMg==--bAliRJeMe0AL5qR5w6eWxCthlia2UQZgBlO9+EqPL6zevnNqzZesEt6NignGmf3hiE7b7490OWWqNKjqcuS8--GcrE9Y1djaPyS4Bv--iGnyNEuZXazbSrn7/p2JUg=="
{"exp":1591005069,"user_id":1,"name":"John Doe","role":"admin"}