about summary refs log tree commit diff
path: root/app/controllers/well_known/webfinger_controller.rb
blob: 5cc606808bf7136173702922bbeaa82c62c29b56 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

module WellKnown
  class WebfingerController < ApplicationController
    include RoutingHelper

    def show
      @account = Account.find_local!(username_from_resource)

      respond_to do |format|
        format.any(:json, :html) do
          render json: @account, serializer: WebfingerSerializer, content_type: 'application/jrd+json'
        end

        format.xml do
          render content_type: 'application/xrd+xml'
        end
      end
    rescue ActiveRecord::RecordNotFound
      head 404
    end

    private

    def username_from_resource
      resource_user = resource_param

      username, domain = resource_user.split('@')
      if Rails.configuration.x.alternate_domains.include?(domain)
        resource_user = "#{username}@#{Rails.configuration.x.local_domain}"
      end

      WebfingerResource.new(resource_user).username
    end

    def resource_param
      params.require(:resource)
    end
  end
end