diff options
author | Azul <azul@leap.se> | 2013-01-25 11:46:22 +0100 |
---|---|---|
committer | Azul <azul@leap.se> | 2013-01-25 11:46:22 +0100 |
commit | dac578781baf73a006cc78e29588dd1f6fdc0fd3 (patch) | |
tree | a56ecff398a87efdd4840a8fc897d6471fbdaa69 /users/lib | |
parent | 75442ad26f3d30519f747bc98bc83cdc76aff750 (diff) | |
parent | 9d053b6c9b61c68bf11f95bcb37631a518f1fba4 (diff) |
Merge branch 'feature/webfinger' of https://github.com/leapcode/leap_web
Conflicts:
users/app/views/users/edit.html.haml
Diffstat (limited to 'users/lib')
-rw-r--r-- | users/lib/leap_web_users/engine.rb | 2 | ||||
-rw-r--r-- | users/lib/webfinger.rb | 6 | ||||
-rw-r--r-- | users/lib/webfinger/host_meta_presenter.rb | 30 | ||||
-rw-r--r-- | users/lib/webfinger/user_presenter.rb | 35 |
4 files changed, 73 insertions, 0 deletions
diff --git a/users/lib/leap_web_users/engine.rb b/users/lib/leap_web_users/engine.rb index 7033576..f8ed71c 100644 --- a/users/lib/leap_web_users/engine.rb +++ b/users/lib/leap_web_users/engine.rb @@ -7,6 +7,8 @@ require "ruby-srp" require "warden/session_serializer" require "warden/strategies/secure_remote_password" +require "webfinger" + module LeapWebUsers class Engine < ::Rails::Engine diff --git a/users/lib/webfinger.rb b/users/lib/webfinger.rb new file mode 100644 index 0000000..dd49b41 --- /dev/null +++ b/users/lib/webfinger.rb @@ -0,0 +1,6 @@ +module Webfinger + + autoload :HostMetaPresenter, 'webfinger/host_meta_presenter' + autoload :UserPresenter, 'webfinger/user_presenter' + +end diff --git a/users/lib/webfinger/host_meta_presenter.rb b/users/lib/webfinger/host_meta_presenter.rb new file mode 100644 index 0000000..84ab7a9 --- /dev/null +++ b/users/lib/webfinger/host_meta_presenter.rb @@ -0,0 +1,30 @@ +require 'uri' + +class Webfinger::HostMetaPresenter + def initialize(request) + @request = request + end + + def to_json(options = {}) + { + subject: subject, + links: links + }.to_json(options) + end + + def subject + url = URI.parse(@request.url) + url.path = '' + url.to_s + end + + def links + { lrdd: { type: 'application/xrd+xml', template: webfinger_template } } + end + + protected + + def webfinger_template(path = 'webfinger', query_param='q') + "#{subject}/#{path}?#{query_param}={uri}" + end +end diff --git a/users/lib/webfinger/user_presenter.rb b/users/lib/webfinger/user_presenter.rb new file mode 100644 index 0000000..329f477 --- /dev/null +++ b/users/lib/webfinger/user_presenter.rb @@ -0,0 +1,35 @@ +class Webfinger::UserPresenter + include Rails.application.routes.url_helpers + attr_accessor :user + + def initialize(user, request) + @user = user + @request = request + end + + def to_json(options = {}) + { + subject: subject, + links: links + }.to_json(options) + end + + def subject + "acct:#{@user.email_address}" + end + + def links + links = {} + links[:public_key] = { type: 'PGP', href: key } if key + return links + end + + protected + + def key + if @user.public_key.present? + Base64.encode64(@user.public_key.to_s) + end + end + +end |