Commit c5f8d13ba068f49ada1ff9e96e1895b2aeb2beb3
1 parent
6e7384c3
Exists in
federation-webfinger
External user now using webfinger endpoint
Showing
1 changed file
with
10 additions
and
10 deletions
Show diff stats
app/models/concerns/external_user.rb
1 | require 'ostruct' | 1 | require 'ostruct' |
2 | +require 'rails/commands/server' | ||
2 | 3 | ||
3 | module ExternalUser | 4 | module ExternalUser |
4 | extend ActiveSupport::Concern | 5 | extend ActiveSupport::Concern |
@@ -18,11 +19,11 @@ module ExternalUser | @@ -18,11 +19,11 @@ module ExternalUser | ||
18 | module ClassMethods | 19 | module ClassMethods |
19 | def webfinger_lookup(login, domain, environment) | 20 | def webfinger_lookup(login, domain, environment) |
20 | if login && domain && environment.has_federated_network?(domain) | 21 | if login && domain && environment.has_federated_network?(domain) |
21 | - # Ask if network at <domain> has user with login <login> | ||
22 | - # FIXME: Make an actual request to the federated network, which should return nil if not found | ||
23 | - { | ||
24 | - login: login | ||
25 | - } | 22 | + rails = Rails::Server.new |
23 | + url = URI.parse('https://'+rails.options[:Host]+':'+rails.options[:Port].to_s+'/.well-known/webfinger?resource=acct:'+login+'@'+domain) | ||
24 | + req = Net::HTTP::Get.new(url.to_s) | ||
25 | + res = Net::HTTP.start(url.host, url.port) { |http| http.request(req) } | ||
26 | + JSON.parse(res.body) | ||
26 | else | 27 | else |
27 | nil | 28 | nil |
28 | end | 29 | end |
@@ -75,11 +76,10 @@ module ExternalUser | @@ -75,11 +76,10 @@ module ExternalUser | ||
75 | u = User.new | 76 | u = User.new |
76 | u.email = user['user']['email'] | 77 | u.email = user['user']['email'] |
77 | u.login = login | 78 | u.login = login |
78 | - # FIXME: Instead of the struct below, we should use the "webfinger" object returned by the webfinger_lookup method | ||
79 | - webfinger = OpenStruct.new( | ||
80 | - identifier: user['user']['person']['identifier'], | ||
81 | - name: user['user']['person']['name'], | ||
82 | - created_at: user['user']['person']['created_at'], | 79 | + webfinger = OpenStruct.new( |
80 | + identifier: webfinger['properties']['identifier'], | ||
81 | + name: webfinger['titles']['name'], | ||
82 | + created_at: webfinger['properties']['created_at'], | ||
83 | domain: domain, | 83 | domain: domain, |
84 | email: user['user']['email'] | 84 | email: user['user']['email'] |
85 | ) | 85 | ) |