From fedb0d62112cd6962ea2a738ff3ce544408e7166 Mon Sep 17 00:00:00 2001 From: Thiago Ribeiro Date: Thu, 28 Apr 2016 17:53:19 -0300 Subject: [PATCH] Federation webfinger --- lib/noosfero/api/api.rb | 14 ++++++-------- lib/noosfero/api/federation/webfinger.rb | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 lib/noosfero/api/federation/webfinger.rb diff --git a/lib/noosfero/api/api.rb b/lib/noosfero/api/api.rb index de2024d..86eb4a0 100644 --- a/lib/noosfero/api/api.rb +++ b/lib/noosfero/api/api.rb @@ -5,14 +5,12 @@ Dir["#{Rails.root}/lib/noosfero/api/*.rb"].each {|file| require file unless file module Noosfero module API - class Federation < Grape::API + class NoosferoFederation < Grape::API + before { detect_stuff_by_domain } format :json - content_type :txt, "text/plain" - - #REMOVE ME - testing routes only - get "/me" do - present_partial current_person, :with => Entities::Person, :current_person => current_person - end + content_type :json, "application/jrd+json" + prefix ".well-known" + mount Federation::Webfinger end class BaseAPI < Grape::API @@ -70,7 +68,7 @@ module Noosfero end mount Noosfero::API::BaseAPI - mount Noosfero::API::Federation + mount Noosfero::API::NoosferoFederation # hook point which allow plugins to add Grape::API extensions to API::API #finds for plugins which has api mount points classes defined (the class should extends Grape::API) diff --git a/lib/noosfero/api/federation/webfinger.rb b/lib/noosfero/api/federation/webfinger.rb new file mode 100644 index 0000000..9b592c6 --- /dev/null +++ b/lib/noosfero/api/federation/webfinger.rb @@ -0,0 +1,48 @@ +module Noosfero + module API + module Federation + class Webfinger < Grape::API + get "webfinger" do + result = generate_jrd + present result, :with => Grape::Presenters::Presenter + end + end + end + end +end + +def extract_person_identifier + person = params[:resource].split("@")[0].split(":")[1] + person +end + +def valid_domain? + #validate domain if resource have acct + if request_acct? + domain = params[:resource].split("@")[1] + environment.domains.map(&:name).include? domain + else + #please validate domain with http + false + end +end + +def generate_jrd + if valid_domain? && request_acct? + result = {} + result = acct_hash + else + "This Domain this not exist in this envinronment" + end +end + +def request_acct? + params[:resource].include? "acct:" +end + +def acct_hash + acct = {} + acct[:subject] = params[:resource] + acct[:properties] = Person.find_by_identifier(extract_person_identifier) + acct +end -- libgit2 0.21.2