discourse/app/controllers/users/discourse_id_controller.rb
Penar Musaraj d45ebd746c
DEV: Add Discourse ID authenticator (#33186)
Adds a Discourse ID authenticator. Not available for use in production
just yet, but soon communities will be able to use this service to let
users authenticate using a central Discourse ID account.

Includes a support for a `/revoke` action, allowing users to log out of
multiple client instances from a central auth service.

Internal ticket: t/155397
---------

Co-authored-by: Loïc Guitaut <loic@discourse.org>
2025-06-17 09:47:00 -04:00

21 lines
792 B
Ruby

# frozen_string_literal: true
class Users::DiscourseIdController < ApplicationController
skip_before_action :verify_authenticity_token, only: [:revoke]
def revoke
RateLimiter.new(nil, "discourse_id_revoke_#{params[:identifier]}", 5, 1.minute).performed!
DiscourseId::Revoke.call(service_params) do |result|
on_success { render json: { success: true } }
on_failed_contract do |contract|
logger.warn(result.inspect_steps) if SiteSetting.discourse_id_verbose_logging
render json: { error: contract.errors.full_messages.join(", ") }, status: 400
end
on_failure do
logger.warn(result.inspect_steps) if SiteSetting.discourse_id_verbose_logging
render json: { error: "Invalid request" }, status: 400
end
end
end
end