Sha256: 9a5436929382d72362ede82748d8edb04d6e695560003fc78240e81c748e0046

Contents?: true

Size: 1.2 KB

Versions: 44

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Decidim
  module Doorkeeper
    # A controller to expose a simple JSON API so OAuth clients can get the user's information.
    class CredentialsController < ApplicationController
      before_action :doorkeeper_authorize!
      respond_to :json

      def me
        respond_with public_data
      end

      private

      def public_data
        {
          id: current_resource_owner.id,
          email: current_resource_owner.email,
          name: current_resource_owner.name,
          nickname: current_resource_owner.nickname,
          image: avatar_url
        }
      end

      def current_resource_owner
        @current_resource_owner ||= Decidim::User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
      end

      def avatar_url
        avatar_url = current_resource_owner.attached_uploader(:avatar).url(host: current_resource_owner.organization.host)
        return unless avatar_url

        unless %r{^https?://}.match? avatar_url
          request_uri = URI.parse(request.url)
          request_uri.path = avatar_url
          request_uri.query = nil
          avatar_url = request_uri.to_s
        end

        avatar_url
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.28.4 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.27.9 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.29.0 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.28.3 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.27.8 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.29.0.rc4 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.29.0.rc3 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.29.0.rc2 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.29.0.rc1 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.28.2 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.27.7 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.28.1 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.27.6 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.26.10 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.26.9 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.28.0 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.27.5 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.28.0.rc5 app/controllers/decidim/doorkeeper/credentials_controller.rb
decidim-core-0.28.0.rc4 app/controllers/decidim/doorkeeper/credentials_controller.rb