Skip to content

About

ZevAuth for Ruby: verify sessions, call the backend API, check webhooks

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

ZevAuth for Ruby

Verify ZevAuth sessions, call the ZevAuth backend API and check webhook signatures from Rails, Rack apps (Sinatra, Roda, Hanami) or plain Ruby.

gem "zevauth"

Ruby 3.1 or later. One runtime dependency (jwt, to read published keys); Rack and Rails are used when your app has them and never required.

Configure

ZevAuth.configure do |c|
  c.environment_id  = ENV.fetch("ZEVAUTH_ENVIRONMENT_ID")   # env_live_…
  c.secret_key      = ENV.fetch("ZEVAUTH_SECRET_KEY")       # sk_live_…, backend API only
  c.publishable_key = ENV.fetch("ZEVAUTH_PUBLISHABLE_KEY")  # pk_live_…, for the handshake page
  c.webhook_secret  = ENV.fetch("ZEVAUTH_WEBHOOK_SECRET")   # whsec_…
end

Who is signed in

auth = ZevAuth.get_auth(request)   # never raises for a missing or bad token
auth.signed_in?
auth.user_id                       # "user_…"
auth.organization_id
auth.has?(permission: "org:members:manage")
auth.mfa_verified?

require_auth refuses instead, with the same responses in every ZevAuth SDK: 401 unauthorized, 403 session_task_pending, 403 mfa_required.

ZevAuth.require_auth(request, require_mfa: true)   # raises ZevAuth::AuthRefused

Tokens are checked locally against your environment's published keys (RS256 only, keys cached and rotated for you), so this costs no network call per request.

Rails

# config/routes.rb
mount ZevAuth::Engine => "/zevauth"

# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  before_action :require_zevauth!
end

class BillingController < ApplicationController
  require_zevauth only: :update, require_mfa: true
end

Views get zevauth_signed_in?, zevauth_user_id and zevauth_auth.

Rack

use ZevAuth::Rack::Middleware        # env["zevauth.auth"] on every request

map "/api" do
  use ZevAuth::Rack::RequireAuth      # 401 / 403 with the JSON envelope
  run Api
end

Backend API

client = ZevAuth.client
client.users.get("user_123")
client.users.each(metadata: { plan: "pro" }) { |user| puts user["email"] }
client.organizations.add_member("org_123", user_id: "user_123", role: "org:admin")

Errors are ZevAuth::APIError with code, status and request_id. Rate limits and brief outages are retried for you; a 500 never is, so a create cannot run twice.

Webhooks

Verify the raw body, never parsed params:

event = ZevAuth::Webhooks.construct_event(
  payload: request.raw_post,
  signature: request.headers["zevauth-signature"]
)

In a Rails controller, zevauth_webhook_event does the same.

Server-rendered pages

With the session bridge, the browser SDK hands each new access token to your server, which keeps it in its own HttpOnly cookie, so a page knows who is signed in before it renders. Mount the engine (Rails) or the middleware (Rack), and set sessionBridge: { url: "/zevauth/session" } in the browser SDK. Your server never refreshes a token; the browser does.

Documentation

Development

bundle install
bundle exec rake test       # includes the shared conformance fixtures
bundle exec rubocop

test/fixtures is a copy of the shared conformance fixtures from zevauth-sdk. Never edit it by hand: change the fixture in zevauth-sdk, then run script/sync-fixtures here.

Support

Questions and bug reports: open an issue here, or contact ZevAuth support.

License

MIT. Copyright (c) 2026 Zevop Inc.

About

ZevAuth for Ruby: verify sessions, call the backend API, check webhooks

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages