Add OIDC fixes, add prefered_username, add application-user claims
This commit is contained in:
@@ -18,7 +18,25 @@ module Admin
|
||||
end
|
||||
|
||||
def create
|
||||
@group = Group.new(group_params)
|
||||
create_params = group_params
|
||||
|
||||
# Parse custom_claims JSON if provided
|
||||
if create_params[:custom_claims].present?
|
||||
begin
|
||||
create_params[:custom_claims] = JSON.parse(create_params[:custom_claims])
|
||||
rescue JSON::ParserError
|
||||
@group = Group.new
|
||||
@group.errors.add(:custom_claims, "must be valid JSON")
|
||||
@available_users = User.order(:email_address)
|
||||
render :new, status: :unprocessable_entity
|
||||
return
|
||||
end
|
||||
else
|
||||
# If empty or blank, set to empty hash (NOT NULL constraint)
|
||||
create_params[:custom_claims] = {}
|
||||
end
|
||||
|
||||
@group = Group.new(create_params)
|
||||
|
||||
if @group.save
|
||||
# Handle user assignments
|
||||
@@ -39,7 +57,24 @@ module Admin
|
||||
end
|
||||
|
||||
def update
|
||||
if @group.update(group_params)
|
||||
update_params = group_params
|
||||
|
||||
# Parse custom_claims JSON if provided
|
||||
if update_params[:custom_claims].present?
|
||||
begin
|
||||
update_params[:custom_claims] = JSON.parse(update_params[:custom_claims])
|
||||
rescue JSON::ParserError
|
||||
@group.errors.add(:custom_claims, "must be valid JSON")
|
||||
@available_users = User.order(:email_address)
|
||||
render :edit, status: :unprocessable_entity
|
||||
return
|
||||
end
|
||||
else
|
||||
# If empty or blank, set to empty hash (NOT NULL constraint)
|
||||
update_params[:custom_claims] = {}
|
||||
end
|
||||
|
||||
if @group.update(update_params)
|
||||
# Handle user assignments
|
||||
if params[:group][:user_ids].present?
|
||||
user_ids = params[:group][:user_ids].reject(&:blank?)
|
||||
@@ -67,7 +102,7 @@ module Admin
|
||||
end
|
||||
|
||||
def group_params
|
||||
params.require(:group).permit(:name, :description, custom_claims: {})
|
||||
params.require(:group).permit(:name, :description, :custom_claims)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module Admin
|
||||
class UsersController < BaseController
|
||||
before_action :set_user, only: [:show, :edit, :update, :destroy, :resend_invitation]
|
||||
before_action :set_user, only: [:show, :edit, :update, :destroy, :resend_invitation, :update_application_claims, :delete_application_claims]
|
||||
|
||||
def index
|
||||
@users = User.order(created_at: :desc)
|
||||
@@ -27,6 +27,7 @@ module Admin
|
||||
end
|
||||
|
||||
def edit
|
||||
@applications = Application.active.order(:name)
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -35,9 +36,25 @@ module Admin
|
||||
# Only update password if provided
|
||||
update_params.delete(:password) if update_params[:password].blank?
|
||||
|
||||
# Parse custom_claims JSON if provided
|
||||
if update_params[:custom_claims].present?
|
||||
begin
|
||||
update_params[:custom_claims] = JSON.parse(update_params[:custom_claims])
|
||||
rescue JSON::ParserError
|
||||
@user.errors.add(:custom_claims, "must be valid JSON")
|
||||
@applications = Application.active.order(:name)
|
||||
render :edit, status: :unprocessable_entity
|
||||
return
|
||||
end
|
||||
else
|
||||
# If empty or blank, set to empty hash (NOT NULL constraint)
|
||||
update_params[:custom_claims] = {}
|
||||
end
|
||||
|
||||
if @user.update(update_params)
|
||||
redirect_to admin_users_path, notice: "User updated successfully."
|
||||
else
|
||||
@applications = Application.active.order(:name)
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
@@ -63,6 +80,41 @@ module Admin
|
||||
redirect_to admin_users_path, notice: "User deleted successfully."
|
||||
end
|
||||
|
||||
# POST /admin/users/:id/update_application_claims
|
||||
def update_application_claims
|
||||
application = Application.find(params[:application_id])
|
||||
|
||||
claims_json = params[:custom_claims].presence || "{}"
|
||||
begin
|
||||
claims = JSON.parse(claims_json)
|
||||
rescue JSON::ParserError
|
||||
redirect_to edit_admin_user_path(@user), alert: "Invalid JSON format for claims."
|
||||
return
|
||||
end
|
||||
|
||||
app_claim = @user.application_user_claims.find_or_initialize_by(application: application)
|
||||
app_claim.custom_claims = claims
|
||||
|
||||
if app_claim.save
|
||||
redirect_to edit_admin_user_path(@user), notice: "App-specific claims updated for #{application.name}."
|
||||
else
|
||||
error_message = app_claim.errors.full_messages.join(", ")
|
||||
redirect_to edit_admin_user_path(@user), alert: "Failed to update claims: #{error_message}"
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /admin/users/:id/delete_application_claims
|
||||
def delete_application_claims
|
||||
application = Application.find(params[:application_id])
|
||||
app_claim = @user.application_user_claims.find_by(application: application)
|
||||
|
||||
if app_claim&.destroy
|
||||
redirect_to edit_admin_user_path(@user), notice: "App-specific claims removed for #{application.name}."
|
||||
else
|
||||
redirect_to edit_admin_user_path(@user), alert: "No claims found to remove."
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_user
|
||||
@@ -71,7 +123,7 @@ module Admin
|
||||
|
||||
def user_params
|
||||
# Base attributes that all admins can modify
|
||||
base_params = params.require(:user).permit(:email_address, :name, :password, :status, :totp_required, custom_claims: {})
|
||||
base_params = params.require(:user).permit(:email_address, :username, :name, :password, :status, :totp_required, :custom_claims)
|
||||
|
||||
# Only allow modifying admin status when editing other users (prevent self-demotion)
|
||||
if params[:id] != Current.session.user.id.to_s
|
||||
|
||||
@@ -534,9 +534,6 @@ class OidcController < ApplicationController
|
||||
claims[:groups] = user.groups.pluck(:name)
|
||||
end
|
||||
|
||||
# Add admin claim if user is admin
|
||||
claims[:admin] = true if user.admin?
|
||||
|
||||
# Merge custom claims from groups
|
||||
user.groups.each do |group|
|
||||
claims.merge!(group.parsed_custom_claims)
|
||||
@@ -545,6 +542,10 @@ class OidcController < ApplicationController
|
||||
# Merge custom claims from user (overrides group claims)
|
||||
claims.merge!(user.parsed_custom_claims)
|
||||
|
||||
# Merge app-specific custom claims (highest priority)
|
||||
application = access_token.application
|
||||
claims.merge!(application.custom_claims_for_user(user))
|
||||
|
||||
render json: claims
|
||||
end
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class PasswordsController < ApplicationController
|
||||
PasswordsMailer.reset(user).deliver_later
|
||||
end
|
||||
|
||||
redirect_to new_session_path, notice: "Password reset instructions sent (if user with that email address exists)."
|
||||
redirect_to signin_path, notice: "Password reset instructions sent (if user with that email address exists)."
|
||||
end
|
||||
|
||||
def edit
|
||||
@@ -20,7 +20,7 @@ class PasswordsController < ApplicationController
|
||||
def update
|
||||
if @user.update(params.permit(:password, :password_confirmation))
|
||||
@user.sessions.destroy_all
|
||||
redirect_to new_session_path, notice: "Password has been reset."
|
||||
redirect_to signin_path, notice: "Password has been reset."
|
||||
else
|
||||
redirect_to edit_password_path(params[:token]), alert: "Passwords did not match."
|
||||
end
|
||||
@@ -29,6 +29,7 @@ class PasswordsController < ApplicationController
|
||||
private
|
||||
def set_user_by_token
|
||||
@user = User.find_by_token_for(:password_reset, params[:token])
|
||||
redirect_to new_password_path, alert: "Password reset link is invalid or has expired." if @user.nil?
|
||||
rescue ActiveSupport::MessageVerifier::InvalidSignature
|
||||
redirect_to new_password_path, alert: "Password reset link is invalid or has expired."
|
||||
end
|
||||
|
||||
69
app/helpers/claims_helper.rb
Normal file
69
app/helpers/claims_helper.rb
Normal file
@@ -0,0 +1,69 @@
|
||||
module ClaimsHelper
|
||||
include ClaimsMerger
|
||||
|
||||
# Preview final merged claims for a user accessing an application
|
||||
def preview_user_claims(user, application)
|
||||
claims = {
|
||||
# Standard OIDC claims
|
||||
email: user.email_address,
|
||||
email_verified: true,
|
||||
preferred_username: user.username.presence || user.email_address,
|
||||
name: user.name.presence || user.email_address
|
||||
}
|
||||
|
||||
# Add groups
|
||||
if user.groups.any?
|
||||
claims[:groups] = user.groups.pluck(:name)
|
||||
end
|
||||
|
||||
# Merge group custom claims (arrays are combined, not overwritten)
|
||||
user.groups.each do |group|
|
||||
claims = deep_merge_claims(claims, group.parsed_custom_claims)
|
||||
end
|
||||
|
||||
# Merge user custom claims (arrays are combined, other values override)
|
||||
claims = deep_merge_claims(claims, user.parsed_custom_claims)
|
||||
|
||||
# Merge app-specific claims (arrays are combined)
|
||||
claims = deep_merge_claims(claims, application.custom_claims_for_user(user))
|
||||
|
||||
claims
|
||||
end
|
||||
|
||||
# Get claim sources breakdown for display
|
||||
def claim_sources(user, application)
|
||||
sources = []
|
||||
|
||||
# Group claims
|
||||
user.groups.each do |group|
|
||||
if group.parsed_custom_claims.any?
|
||||
sources << {
|
||||
type: :group,
|
||||
name: group.name,
|
||||
claims: group.parsed_custom_claims
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
# User claims
|
||||
if user.parsed_custom_claims.any?
|
||||
sources << {
|
||||
type: :user,
|
||||
name: "User Override",
|
||||
claims: user.parsed_custom_claims
|
||||
}
|
||||
end
|
||||
|
||||
# App-specific claims
|
||||
app_claims = application.custom_claims_for_user(user)
|
||||
if app_claims.any?
|
||||
sources << {
|
||||
type: :application,
|
||||
name: "App-Specific (#{application.name})",
|
||||
claims: app_claims
|
||||
}
|
||||
end
|
||||
|
||||
sources
|
||||
end
|
||||
end
|
||||
@@ -3,6 +3,7 @@ class Application < ApplicationRecord
|
||||
|
||||
has_many :application_groups, dependent: :destroy
|
||||
has_many :allowed_groups, through: :application_groups, source: :group
|
||||
has_many :application_user_claims, dependent: :destroy
|
||||
has_many :oidc_authorization_codes, dependent: :destroy
|
||||
has_many :oidc_access_tokens, dependent: :destroy
|
||||
has_many :oidc_refresh_tokens, dependent: :destroy
|
||||
@@ -186,6 +187,12 @@ class Application < ApplicationRecord
|
||||
duration_to_human(id_token_ttl || 3600)
|
||||
end
|
||||
|
||||
# Get app-specific custom claims for a user
|
||||
def custom_claims_for_user(user)
|
||||
app_claim = application_user_claims.find_by(user: user)
|
||||
app_claim&.parsed_custom_claims || {}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def duration_to_human(seconds)
|
||||
|
||||
31
app/models/application_user_claim.rb
Normal file
31
app/models/application_user_claim.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
class ApplicationUserClaim < ApplicationRecord
|
||||
belongs_to :application
|
||||
belongs_to :user
|
||||
|
||||
# Reserved OIDC claim names that should not be overridden
|
||||
RESERVED_CLAIMS = %w[
|
||||
iss sub aud exp iat nbf jti nonce azp
|
||||
email email_verified preferred_username name
|
||||
groups
|
||||
].freeze
|
||||
|
||||
validates :user_id, uniqueness: { scope: :application_id }
|
||||
validate :no_reserved_claim_names
|
||||
|
||||
# Parse custom_claims JSON field
|
||||
def parsed_custom_claims
|
||||
return {} if custom_claims.blank?
|
||||
custom_claims.is_a?(Hash) ? custom_claims : {}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def no_reserved_claim_names
|
||||
return if custom_claims.blank?
|
||||
|
||||
reserved_used = parsed_custom_claims.keys.map(&:to_s) & RESERVED_CLAIMS
|
||||
if reserved_used.any?
|
||||
errors.add(:custom_claims, "cannot override reserved OIDC claims: #{reserved_used.join(', ')}")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -4,11 +4,31 @@ class Group < ApplicationRecord
|
||||
has_many :application_groups, dependent: :destroy
|
||||
has_many :applications, through: :application_groups
|
||||
|
||||
# Reserved OIDC claim names that should not be overridden
|
||||
RESERVED_CLAIMS = %w[
|
||||
iss sub aud exp iat nbf jti nonce azp
|
||||
email email_verified preferred_username name
|
||||
groups
|
||||
].freeze
|
||||
|
||||
validates :name, presence: true, uniqueness: { case_sensitive: false }
|
||||
normalizes :name, with: ->(name) { name.strip.downcase }
|
||||
validate :no_reserved_claim_names
|
||||
|
||||
# Parse custom_claims JSON field
|
||||
def parsed_custom_claims
|
||||
custom_claims || {}
|
||||
return {} if custom_claims.blank?
|
||||
custom_claims.is_a?(Hash) ? custom_claims : {}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def no_reserved_claim_names
|
||||
return if custom_claims.blank?
|
||||
|
||||
reserved_used = parsed_custom_claims.keys.map(&:to_s) & RESERVED_CLAIMS
|
||||
if reserved_used.any?
|
||||
errors.add(:custom_claims, "cannot override reserved OIDC claims: #{reserved_used.join(', ')}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,7 @@ class User < ApplicationRecord
|
||||
has_many :sessions, dependent: :destroy
|
||||
has_many :user_groups, dependent: :destroy
|
||||
has_many :groups, through: :user_groups
|
||||
has_many :application_user_claims, dependent: :destroy
|
||||
has_many :oidc_user_consents, dependent: :destroy
|
||||
has_many :webauthn_credentials, dependent: :destroy
|
||||
|
||||
@@ -20,10 +21,22 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
normalizes :email_address, with: ->(e) { e.strip.downcase }
|
||||
normalizes :username, with: ->(u) { u.strip.downcase if u.present? }
|
||||
|
||||
# Reserved OIDC claim names that should not be overridden
|
||||
RESERVED_CLAIMS = %w[
|
||||
iss sub aud exp iat nbf jti nonce azp
|
||||
email email_verified preferred_username name
|
||||
groups
|
||||
].freeze
|
||||
|
||||
validates :email_address, presence: true, uniqueness: { case_sensitive: false },
|
||||
format: { with: URI::MailTo::EMAIL_REGEXP }
|
||||
validates :username, uniqueness: { case_sensitive: false }, allow_nil: true,
|
||||
format: { with: /\A[a-zA-Z0-9_-]+\z/, message: "can only contain letters, numbers, underscores, and hyphens" },
|
||||
length: { minimum: 2, maximum: 30 }
|
||||
validates :password, length: { minimum: 8 }, allow_nil: true
|
||||
validate :no_reserved_claim_names
|
||||
|
||||
# Enum - automatically creates scopes (User.active, User.disabled, etc.)
|
||||
enum :status, { active: 0, disabled: 1, pending_invitation: 2 }
|
||||
@@ -182,11 +195,39 @@ class User < ApplicationRecord
|
||||
|
||||
# Parse custom_claims JSON field
|
||||
def parsed_custom_claims
|
||||
custom_claims || {}
|
||||
return {} if custom_claims.blank?
|
||||
custom_claims.is_a?(Hash) ? custom_claims : {}
|
||||
end
|
||||
|
||||
# Get fully merged claims for a specific application
|
||||
def merged_claims_for_application(application)
|
||||
merged = {}
|
||||
|
||||
# Start with group claims (in order)
|
||||
groups.each do |group|
|
||||
merged.merge!(group.parsed_custom_claims)
|
||||
end
|
||||
|
||||
# Merge user global claims
|
||||
merged.merge!(parsed_custom_claims)
|
||||
|
||||
# Merge app-specific claims (highest priority)
|
||||
merged.merge!(application.custom_claims_for_user(self))
|
||||
|
||||
merged
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def no_reserved_claim_names
|
||||
return if custom_claims.blank?
|
||||
|
||||
reserved_used = parsed_custom_claims.keys.map(&:to_s) & RESERVED_CLAIMS
|
||||
if reserved_used.any?
|
||||
errors.add(:custom_claims, "cannot override reserved OIDC claims: #{reserved_used.join(', ')}")
|
||||
end
|
||||
end
|
||||
|
||||
def generate_backup_codes
|
||||
# Generate plain codes for user to see/save
|
||||
plain_codes = Array.new(10) { SecureRandom.alphanumeric(8).upcase }
|
||||
|
||||
35
app/services/concerns/claims_merger.rb
Normal file
35
app/services/concerns/claims_merger.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
module ClaimsMerger
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
# Deep merge claims, combining arrays instead of overwriting them
|
||||
# This ensures that array values (like roles) are combined across group/user/app claims
|
||||
#
|
||||
# Example:
|
||||
# base = { "roles" => ["user"], "level" => 1 }
|
||||
# incoming = { "roles" => ["admin"], "department" => "IT" }
|
||||
# deep_merge_claims(base, incoming)
|
||||
# # => { "roles" => ["user", "admin"], "level" => 1, "department" => "IT" }
|
||||
def deep_merge_claims(base, incoming)
|
||||
result = base.dup
|
||||
|
||||
incoming.each do |key, value|
|
||||
if result.key?(key)
|
||||
# If both values are arrays, combine them (union to avoid duplicates)
|
||||
if result[key].is_a?(Array) && value.is_a?(Array)
|
||||
result[key] = (result[key] + value).uniq
|
||||
# If both values are hashes, recursively merge them
|
||||
elsif result[key].is_a?(Hash) && value.is_a?(Hash)
|
||||
result[key] = deep_merge_claims(result[key], value)
|
||||
else
|
||||
# Otherwise, incoming value wins (override)
|
||||
result[key] = value
|
||||
end
|
||||
else
|
||||
# New key, just add it
|
||||
result[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
@@ -1,4 +1,6 @@
|
||||
class OidcJwtService
|
||||
extend ClaimsMerger
|
||||
|
||||
class << self
|
||||
# Generate an ID token (JWT) for the user
|
||||
def generate_id_token(user, application, consent: nil, nonce: nil)
|
||||
@@ -17,7 +19,7 @@ class OidcJwtService
|
||||
iat: now,
|
||||
email: user.email_address,
|
||||
email_verified: true,
|
||||
preferred_username: user.email_address,
|
||||
preferred_username: user.username.presence || user.email_address,
|
||||
name: user.name.presence || user.email_address
|
||||
}
|
||||
|
||||
@@ -29,16 +31,16 @@ class OidcJwtService
|
||||
payload[:groups] = user.groups.pluck(:name)
|
||||
end
|
||||
|
||||
# Add admin claim if user is admin
|
||||
payload[:admin] = true if user.admin?
|
||||
|
||||
# Merge custom claims from groups
|
||||
# Merge custom claims from groups (arrays are combined, not overwritten)
|
||||
user.groups.each do |group|
|
||||
payload.merge!(group.parsed_custom_claims)
|
||||
payload = deep_merge_claims(payload, group.parsed_custom_claims)
|
||||
end
|
||||
|
||||
# Merge custom claims from user (overrides group claims)
|
||||
payload.merge!(user.parsed_custom_claims)
|
||||
# Merge custom claims from user (arrays are combined, other values override)
|
||||
payload = deep_merge_claims(payload, user.parsed_custom_claims)
|
||||
|
||||
# Merge app-specific custom claims (highest priority, arrays are combined)
|
||||
payload = deep_merge_claims(payload, application.custom_claims_for_user(user))
|
||||
|
||||
JWT.encode(payload, private_key, "RS256", { kid: key_id, typ: "JWT" })
|
||||
end
|
||||
|
||||
185
app/views/admin/users/_application_claims.html.erb
Normal file
185
app/views/admin/users/_application_claims.html.erb
Normal file
@@ -0,0 +1,185 @@
|
||||
<% oidc_apps = applications.select(&:oidc?) %>
|
||||
<% forward_auth_apps = applications.select(&:forward_auth?) %>
|
||||
|
||||
<!-- OIDC Apps: Custom Claims -->
|
||||
<% if oidc_apps.any? %>
|
||||
<div class="mt-12 border-t pt-8">
|
||||
<h2 class="text-xl font-semibold text-gray-900 mb-4">OIDC App-Specific Claims</h2>
|
||||
<p class="text-sm text-gray-600 mb-6">
|
||||
Configure custom claims that apply only to specific OIDC applications. These override both group and user global claims and are included in ID tokens.
|
||||
</p>
|
||||
|
||||
<div class="space-y-6">
|
||||
<% oidc_apps.each do |app| %>
|
||||
<% app_claim = user.application_user_claims.find_by(application: app) %>
|
||||
<details class="border rounded-lg" <%= "open" if app_claim&.custom_claims&.any? %>>
|
||||
<summary class="cursor-pointer bg-gray-50 px-4 py-3 hover:bg-gray-100 rounded-t-lg flex items-center justify-between">
|
||||
<div class="flex items-center gap-3">
|
||||
<span class="font-medium text-gray-900"><%= app.name %></span>
|
||||
<span class="text-xs px-2 py-1 rounded-full bg-blue-100 text-blue-700">
|
||||
OIDC
|
||||
</span>
|
||||
<% if app_claim&.custom_claims&.any? %>
|
||||
<span class="text-xs px-2 py-1 rounded-full bg-amber-100 text-amber-700">
|
||||
<%= app_claim.custom_claims.keys.count %> claim(s)
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<svg class="h-5 w-5 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
|
||||
</svg>
|
||||
</summary>
|
||||
|
||||
<div class="p-4 space-y-4">
|
||||
<%= form_with url: update_application_claims_admin_user_path(user), method: :post, class: "space-y-4", data: { controller: "json-validator" } do |form| %>
|
||||
<%= hidden_field_tag :application_id, app.id %>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-2">Custom Claims (JSON)</label>
|
||||
<%= text_area_tag :custom_claims,
|
||||
(app_claim&.custom_claims.present? ? JSON.pretty_generate(app_claim.custom_claims) : ""),
|
||||
rows: 8,
|
||||
class: "w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm font-mono",
|
||||
placeholder: '{"kavita_groups": ["admin"], "library_access": "all"}',
|
||||
data: {
|
||||
action: "input->json-validator#validate blur->json-validator#format",
|
||||
json_validator_target: "textarea"
|
||||
} %>
|
||||
<div class="mt-2 space-y-1">
|
||||
<p class="text-xs text-gray-600">
|
||||
Example for <%= app.name %>: Add claims that this app specifically needs to read.
|
||||
</p>
|
||||
<p class="text-xs text-amber-600">
|
||||
<strong>Note:</strong> Do not use reserved claim names (<code class="bg-amber-50 px-1 rounded">groups</code>, <code class="bg-amber-50 px-1 rounded">email</code>, <code class="bg-amber-50 px-1 rounded">name</code>, etc.). Use app-specific names like <code class="bg-amber-50 px-1 rounded">kavita_groups</code> instead.
|
||||
</p>
|
||||
<div data-json-validator-target="status" class="text-xs font-medium"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-3">
|
||||
<%= button_tag type: :submit, class: "rounded-md bg-blue-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-blue-500" do %>
|
||||
<%= app_claim ? "Update" : "Add" %> Claims
|
||||
<% end %>
|
||||
|
||||
<% if app_claim %>
|
||||
<%= button_to "Remove Override",
|
||||
delete_application_claims_admin_user_path(user, application_id: app.id),
|
||||
method: :delete,
|
||||
data: { turbo_confirm: "Remove app-specific claims for #{app.name}?" },
|
||||
class: "rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50" %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<!-- Preview merged claims -->
|
||||
<div class="mt-4 border-t pt-4">
|
||||
<h4 class="text-sm font-medium text-gray-700 mb-2">Preview: Final ID Token Claims for <%= app.name %></h4>
|
||||
<div class="bg-gray-50 rounded-lg p-3">
|
||||
<pre class="text-xs font-mono text-gray-800 overflow-x-auto"><%= JSON.pretty_generate(preview_user_claims(user, app)) %></pre>
|
||||
</div>
|
||||
|
||||
<details class="mt-2">
|
||||
<summary class="cursor-pointer text-xs text-gray-600 hover:text-gray-900">Show claim sources</summary>
|
||||
<div class="mt-2 space-y-1">
|
||||
<% claim_sources(user, app).each do |source| %>
|
||||
<div class="flex gap-2 items-start text-xs">
|
||||
<span class="px-2 py-1 rounded <%= source[:type] == :group ? 'bg-blue-100 text-blue-700' : (source[:type] == :user ? 'bg-green-100 text-green-700' : 'bg-amber-100 text-amber-700') %>">
|
||||
<%= source[:name] %>
|
||||
</span>
|
||||
<code class="text-gray-700"><%= source[:claims].to_json %></code>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<!-- ForwardAuth Apps: Headers Preview -->
|
||||
<% if forward_auth_apps.any? %>
|
||||
<div class="mt-12 border-t pt-8">
|
||||
<h2 class="text-xl font-semibold text-gray-900 mb-4">ForwardAuth Headers Preview</h2>
|
||||
<p class="text-sm text-gray-600 mb-6">
|
||||
ForwardAuth applications receive HTTP headers (not OIDC tokens). Headers are based on user's email, name, groups, and admin status.
|
||||
</p>
|
||||
|
||||
<div class="space-y-6">
|
||||
<% forward_auth_apps.each do |app| %>
|
||||
<details class="border rounded-lg">
|
||||
<summary class="cursor-pointer bg-gray-50 px-4 py-3 hover:bg-gray-100 rounded-t-lg flex items-center justify-between">
|
||||
<div class="flex items-center gap-3">
|
||||
<span class="font-medium text-gray-900"><%= app.name %></span>
|
||||
<span class="text-xs px-2 py-1 rounded-full bg-green-100 text-green-700">
|
||||
FORWARD AUTH
|
||||
</span>
|
||||
<span class="text-xs text-gray-500">
|
||||
<%= app.domain_pattern %>
|
||||
</span>
|
||||
</div>
|
||||
<svg class="h-5 w-5 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
|
||||
</svg>
|
||||
</summary>
|
||||
|
||||
<div class="p-4 space-y-4">
|
||||
<div class="bg-blue-50 border border-blue-200 rounded-lg p-3">
|
||||
<div class="flex items-start">
|
||||
<svg class="h-5 w-5 text-blue-400 mr-2 flex-shrink-0 mt-0.5" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h4 class="text-sm font-medium text-gray-700 mb-2">Headers Sent to <%= app.name %></h4>
|
||||
<div class="bg-gray-50 rounded-lg p-3 border">
|
||||
<% headers = app.headers_for_user(user) %>
|
||||
<% if headers.any? %>
|
||||
<dl class="space-y-2 text-xs font-mono">
|
||||
<% headers.each do |header_name, value| %>
|
||||
<div class="flex">
|
||||
<dt class="text-blue-600 font-semibold w-48"><%= header_name %>:</dt>
|
||||
<dd class="text-gray-800 flex-1"><%= value %></dd>
|
||||
</div>
|
||||
<% end %>
|
||||
</dl>
|
||||
<% else %>
|
||||
<p class="text-xs text-gray-500 italic">All headers disabled for this application.</p>
|
||||
<% end %>
|
||||
</div>
|
||||
<p class="mt-2 text-xs text-gray-500">
|
||||
These headers are configured in the application settings and sent by your reverse proxy (Caddy/Traefik) to the upstream application.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<% if user.groups.any? %>
|
||||
<div>
|
||||
<h4 class="text-sm font-medium text-gray-700 mb-2">User's Groups</h4>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<% user.groups.each do |group| %>
|
||||
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
|
||||
<%= group.name %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</details>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if oidc_apps.empty? && forward_auth_apps.empty? %>
|
||||
<div class="mt-12 border-t pt-8">
|
||||
<div class="text-center py-12 bg-gray-50 rounded-lg">
|
||||
<p class="text-gray-500">No active applications found.</p>
|
||||
<p class="text-sm text-gray-400 mt-1">Create applications in the Admin panel first.</p>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -6,10 +6,16 @@
|
||||
<%= form.email_field :email_address, required: true, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm", placeholder: "user@example.com" %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= form.label :username, "Username (Optional)", class: "block text-sm font-medium text-gray-700" %>
|
||||
<%= form.text_field :username, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm", placeholder: "jsmith" %>
|
||||
<p class="mt-1 text-sm text-gray-500">Optional: Short username/handle for login. Can only contain letters, numbers, underscores, and hyphens.</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= form.label :name, "Display Name (Optional)", class: "block text-sm font-medium text-gray-700" %>
|
||||
<%= form.text_field :name, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm", placeholder: "John Smith" %>
|
||||
<p class="mt-1 text-sm text-gray-500">Optional: Name shown in applications. Defaults to email address if not set.</p>
|
||||
<p class="mt-1 text-sm text-gray-500">Optional: Full name shown in applications. Defaults to email address if not set.</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
<div class="max-w-2xl">
|
||||
<div class="max-w-4xl">
|
||||
<h1 class="text-2xl font-semibold text-gray-900 mb-6">Edit User</h1>
|
||||
<p class="text-sm text-gray-600 mb-6">Editing: <%= @user.email_address %></p>
|
||||
<%= render "form", user: @user %>
|
||||
|
||||
<div class="max-w-2xl">
|
||||
<%= render "form", user: @user %>
|
||||
</div>
|
||||
|
||||
<% if @user.persisted? %>
|
||||
<%= render "application_claims", user: @user, applications: @applications %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user