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.
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_…
endauth = 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::AuthRefusedTokens 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.
# 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
endViews get zevauth_signed_in?, zevauth_user_id and zevauth_auth.
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
endclient = 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.
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.
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.
- Ruby: https://docs.zevauth.com/sdk/ruby
- Rails: https://docs.zevauth.com/sdk/rails
- The contract every ZevAuth server SDK follows: https://github.com/zevop/zevauth-sdk/tree/main/spec
bundle install
bundle exec rake test # includes the shared conformance fixtures
bundle exec rubocoptest/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.
Questions and bug reports: open an issue here, or contact ZevAuth support.
MIT. Copyright (c) 2026 Zevop Inc.