Commit f79340a477c9356827bb5caca0f1dc310dc09429
Committed by
Larissa Reis
1 parent
e2857886
Exists in
oauth_external_login
and in
1 other branch
External user now using webfinger endpoint
Showing
1 changed file
with
9 additions
and
10 deletions
Show diff stats
app/models/concerns/external_user.rb
... | ... | @@ -18,11 +18,11 @@ module ExternalUser |
18 | 18 | module ClassMethods |
19 | 19 | def webfinger_lookup(login, domain, environment) |
20 | 20 | 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 | - } | |
21 | + url = URI.parse('https://'+ domain +'/.well-known/webfinger?resource=acct:'+ | |
22 | + login+'@'+Environment.default.federated_networks.find_by_url(domain)) | |
23 | + req = Net::HTTP::Get.new(url.to_s) | |
24 | + res = Net::HTTP.start(url.host, url.port) { |http| http.request(req) } | |
25 | + JSON.parse(res.body) | |
26 | 26 | else |
27 | 27 | nil |
28 | 28 | end |
... | ... | @@ -75,11 +75,10 @@ module ExternalUser |
75 | 75 | u = User.new |
76 | 76 | u.email = user['user']['email'] |
77 | 77 | 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'], | |
78 | + webfinger = OpenStruct.new( | |
79 | + identifier: webfinger['properties']['identifier'], | |
80 | + name: webfinger['titles']['name'], | |
81 | + created_at: webfinger['properties']['created_at'], | |
83 | 82 | domain: domain, |
84 | 83 | email: user['user']['email'] |
85 | 84 | ) | ... | ... |