Adds three OAuth surfaces to the OIDC provider so CLIs, terminal agents, and MCP connectors can authenticate as real users instead of using static API keys. Device Authorization Grant (RFC 8628): - OidcDeviceCode model (HMAC device_code, short plaintext user_code, nullable user until approval, slow_down polling state), mirroring OidcAuthorizationCode - POST /oauth/device_authorization issues the code pair + verification URIs - device_code grant on /oauth/token returns authorization_pending / slow_down / access_denied / expired_token, then the standard token triple; single-use - Authenticated /device approval page, gated by Application#user_allowed? Token Introspection (RFC 7662): - POST /oauth/introspect: confidential-caller-authenticated; returns active, scope, and the user's groups so resource servers can authorize on membership Dynamic Client Registration (RFC 7591): - POST /oauth/register creates public/confidential clients (PKCE required) - Runtime toggle via a new Setting store + admin switch on the Applications page; off by default, env var CLINCH_DCR_ENABLED as bootstrap fallback - New clients are default-deny (no allowed_groups) until an admin grants access - RFC 8414 metadata alias at /.well-known/oauth-authorization-server; registration_endpoint advertised only while the window is open Discovery advertises all three grants/endpoints. Seeds add a clinch-cli public client and a c2a2-introspection confidential client. ADRs in docs/decisions record the opaque-vs-JWT, device-flow, and DCR-security decisions. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F7cwhwDJp3MJJDoNPVE6zq
26 lines
776 B
Ruby
26 lines
776 B
Ruby
# Small persisted key/value store for runtime-togglable configuration that an
|
|
# admin can flip from the UI without a redeploy (e.g. the dynamic client
|
|
# registration window). Values are stored as strings; use the typed helpers.
|
|
class Setting < ApplicationRecord
|
|
validates :key, presence: true, uniqueness: true
|
|
|
|
def self.get(key)
|
|
find_by(key: key.to_s)&.value
|
|
end
|
|
|
|
def self.set(key, value)
|
|
record = find_or_initialize_by(key: key.to_s)
|
|
record.value = value.to_s
|
|
record.save!
|
|
value
|
|
end
|
|
|
|
# Returns nil if the key has never been set, so callers can distinguish
|
|
# "unset" (fall back to a default) from an explicit false.
|
|
def self.boolean(key)
|
|
raw = get(key)
|
|
return nil if raw.nil?
|
|
ActiveModel::Type::Boolean.new.cast(raw)
|
|
end
|
|
end
|