---
title: "sdk/ruby"
description: "Ruby-Server-SDK für netzwerklose JWT-Prüfung,Rack/Rails-Anfrage-Authentifizierung und Webhook-Signaturvalidierung."
locale: "de"
---

> Documentation Index
> Fetch the locale documentation index at: https://xid.dev/de/llms.txt
> Use this file to discover all available pages before exploring further.

# sdk/ruby

## Zustand

Implementiert und lokal verifiziert. Die echteIdP-Round-Trip-Verifizierung (JWKS-Abruf, Token-Signierung/Prüfung gegeneine Live-XID-Instanz) wurde noch nicht durchgeführt und muss vor demProduktionseinsatz abgeschlossen werden.

## Installieren

```ruby
# Gemfile
gem "xid"

bundle install
```

## Schnellstart

```ruby
require "xid"

Xid.configure do |c|
  c.issuer         = "https://xid.dev"
  c.audience       = "your_client_id"
  c.webhook_secret = "whsec_AbCdEf..."
end

# Verify a token
begin
  claims = Xid.verify_token(raw_token)
  puts claims.sub    # => "usr_abc123"
  puts claims.scope  # => "openid profile email"
rescue Xid::TokenVerificationError => e
  puts "Token invalid: #{e.message}"
end
```

## Rack/Rails-Anfrage authentifizieren

```ruby
# Sinatra before-filter
before do
  auth = Xid.authenticate_request(request)
  halt 401, "Unauthorized" unless auth.signed_in?
  @current_user_id = auth.claims.sub
end

# Rack middleware (env-based)
auth = Xid.authenticate_request(env)
unless auth.signed_in?
  return [401, { "Content-Type" => "application/json" },
      [JSON.generate({ error: auth.reason })]]
end
```

## Webhook prüfen

```ruby
# Rails controller action
def receive
  raw_body = request.raw_post
  payload = Xid.verify_webhook(request.headers.to_h, raw_body)
  handle_event(payload["type"], payload["data"])
  head :ok
rescue Xid::WebhookVerificationError
  head :bad_request
end
```

## Multi-Issuer-Einrichtung

```ruby
config_a = Xid::Configuration.new
config_a.issuer   = "https://tenant-a.xid.dev"
config_a.audience = "client_a"
client_a = Xid::Client.new(config_a)
claims = client_a.verify_token(token)
```

## Konfigurationsoptionen

| Schlüssel | Standard | Beschreibung |
| --- | --- | --- |
| `issuer` | `https://xid.dev` | OIDC-Issuer-URL |
| `audience` | `nil` | Erwarteter aud-Claim; nil überspringt die Validierung |
| `jwks_ttl` | `3600` | Lokale JWKS-Cache-TTL in Sekunden |
| `leeway` | `60` | JWT-Taktversatztoleranz in Sekunden |
| `webhook_secret` | `nil` | Webhook-Signing-Secret mit `whsec_`-Prefix |
| `webhook_tolerance` | `300` | Webhook-Replay-Fenster in Sekunden |
| `cookie_name` | `__xid_token` | Cookie-Schlüssel für die Access-Token-Extraktion |

## Plattformhinweise

- Setzt das `jwt`-Gem (ES256/RS256-Unterstützung) voraus. Ruby 3.1+erforderlich.
- `Xid.authenticate_request` akzeptiert sowohl einen Rack-Env-Hash alsauch ein Rack-`Request`-Objekt.
- Ausnahmehierarchie: `Xid::Error` -&gt; `ConfigurationError`,`JwksError`, `TokenVerificationError`,`WebhookVerificationError`.

Source: https://xid.dev/de/sdks/ruby/index.mdx
