2017-05-03 18:02:18 +03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class VerifySalmonService < BaseService
|
|
|
|
include AuthorExtractor
|
|
|
|
|
|
|
|
def call(payload)
|
|
|
|
body = salmon.unpack(payload)
|
|
|
|
|
|
|
|
xml = Nokogiri::XML(body)
|
|
|
|
xml.encoding = 'utf-8'
|
|
|
|
|
2017-09-19 19:08:08 +03:00
|
|
|
account = author_from_xml(xml.at_xpath('/xmlns:entry', xmlns: OStatus::TagManager::XMLNS))
|
2017-05-03 18:02:18 +03:00
|
|
|
|
|
|
|
if account.nil?
|
|
|
|
false
|
|
|
|
else
|
|
|
|
salmon.verify(payload, account.keypair)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def salmon
|
|
|
|
@salmon ||= OStatus2::Salmon.new
|
|
|
|
end
|
|
|
|
end
|