prooflink_connect 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +13 -13
- data/lib/prooflink_connect.rb +8 -6
- data/lib/prooflink_connect/assertion.rb +16 -11
- data/lib/prooflink_connect/configuration.rb +14 -2
- data/lib/prooflink_connect/invite.rb +19 -20
- data/lib/prooflink_connect/share.rb +13 -0
- data/lib/prooflink_connect/share_button.rb +2 -1
- data/lib/prooflink_connect/version.rb +1 -1
- data/prooflink_connect.gemspec +4 -2
- data/spec/prooflink_connect/share_spec.rb +16 -0
- data/spec/spec_helper.rb +2 -11
- metadata +40 -10
data/Gemfile.lock
CHANGED
@@ -1,25 +1,21 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
prooflink_connect (0.0.
|
5
|
-
|
4
|
+
prooflink_connect (0.0.14)
|
5
|
+
activesupport
|
6
|
+
httparty
|
6
7
|
json
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: http://rubygems.org/
|
10
11
|
specs:
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
i18n (~> 0.5.0)
|
15
|
-
activeresource (3.0.7)
|
16
|
-
activemodel (= 3.0.7)
|
17
|
-
activesupport (= 3.0.7)
|
18
|
-
activesupport (3.0.7)
|
19
|
-
builder (2.1.2)
|
12
|
+
activesupport (3.0.9)
|
13
|
+
addressable (2.2.6)
|
14
|
+
crack (0.1.8)
|
20
15
|
diff-lcs (1.1.2)
|
21
|
-
|
22
|
-
|
16
|
+
httparty (0.7.8)
|
17
|
+
crack (= 0.1.8)
|
18
|
+
json (1.5.3)
|
23
19
|
rspec (2.4.0)
|
24
20
|
rspec-core (~> 2.4.0)
|
25
21
|
rspec-expectations (~> 2.4.0)
|
@@ -28,6 +24,9 @@ GEM
|
|
28
24
|
rspec-expectations (2.4.0)
|
29
25
|
diff-lcs (~> 1.1.2)
|
30
26
|
rspec-mocks (2.4.0)
|
27
|
+
webmock (1.6.2)
|
28
|
+
addressable (>= 2.2.2)
|
29
|
+
crack (>= 0.1.7)
|
31
30
|
|
32
31
|
PLATFORMS
|
33
32
|
ruby
|
@@ -36,3 +35,4 @@ DEPENDENCIES
|
|
36
35
|
bundler (>= 1.0.0)
|
37
36
|
prooflink_connect!
|
38
37
|
rspec
|
38
|
+
webmock
|
data/lib/prooflink_connect.rb
CHANGED
@@ -4,27 +4,29 @@ module ProoflinkConnect
|
|
4
4
|
autoload :PortableContacts, "prooflink_connect/portable_contacts"
|
5
5
|
autoload :ShareButton, "prooflink_connect/share_button"
|
6
6
|
autoload :Invite, "prooflink_connect/invite"
|
7
|
+
autoload :Share, "prooflink_connect/share"
|
7
8
|
|
8
9
|
def self.config
|
9
|
-
Configuration.
|
10
|
+
@configuration ||= Configuration.new
|
10
11
|
end
|
11
12
|
|
12
13
|
def self.configure
|
13
14
|
yield config
|
14
15
|
end
|
15
16
|
|
16
|
-
def self.embedded(options = {})
|
17
|
+
def self.embedded(options = {}, config = ProoflinkConnect.config)
|
17
18
|
options = {
|
18
|
-
:subdomain =>
|
19
|
+
:subdomain => config.subdomain,
|
19
20
|
:token_url => 'https://example.com/auth/callbacks',
|
20
21
|
:forced_connect => '0',
|
21
22
|
:embed_forms => '0',
|
22
23
|
:width => 520,
|
23
24
|
:height => 250}.merge(options)
|
24
|
-
domain_part = [options[:subdomain],
|
25
|
+
domain_part = [options[:subdomain], config.provider_endpoint].compact.join(".")
|
25
26
|
path_part = [options[:locale], 'authentications', 'embedded'].compact.join("/")
|
26
27
|
query_part = "token_url=#{options[:token_url]}&forced_connect=#{options[:forced_connect]}&embed_forms=#{options[:embed_forms]}"
|
27
|
-
frame_url = "#{
|
28
|
-
"<iframe src='#{frame_url}' style='width: #{options[:width]}px; height: #{options[:height]}px; border: 0;display: block' frameborder='0' allowTransparency='true'></iframe>"
|
28
|
+
frame_url = "#{config.protocol}://#{domain_part}/#{path_part}?#{query_part}"
|
29
|
+
html = "<iframe src='#{frame_url}' style='width: #{options[:width]}px; height: #{options[:height]}px; border: 0;display: block' frameborder='0' allowTransparency='true'></iframe>"
|
30
|
+
html.respond_to?(:html_safe) ? html.html_safe : html
|
29
31
|
end
|
30
32
|
end
|
@@ -1,19 +1,28 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
1
3
|
module ProoflinkConnect
|
2
4
|
class Assertion
|
3
5
|
require 'net/http'
|
4
|
-
|
6
|
+
attr_reader :token
|
5
7
|
|
6
8
|
def initialize(token)
|
7
9
|
@token = token
|
8
10
|
end
|
9
11
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
12
|
+
def auth_info(configuration = ProoflinkConnect.config)
|
13
|
+
PortableContacts::Person.new(request_auth_info(configuration)['entry'])
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def request_auth_info(configuration)
|
19
|
+
configuration.validate!.inspect
|
20
|
+
|
21
|
+
url = URI.parse(configuration.base_uri + "/client_assertions/auth_info/")
|
13
22
|
query = {}
|
14
23
|
query['format'] = 'json'
|
15
|
-
query['token'] =
|
16
|
-
query['api_key'] =
|
24
|
+
query['token'] = token
|
25
|
+
query['api_key'] = configuration.api_key
|
17
26
|
|
18
27
|
http = Net::HTTP.new(url.host, url.port)
|
19
28
|
|
@@ -29,17 +38,13 @@ module ProoflinkConnect
|
|
29
38
|
begin
|
30
39
|
data = JSON.parse(resp.body)
|
31
40
|
rescue JSON::ParserError => err
|
32
|
-
raise AuthinfoException.new(resp),
|
41
|
+
raise AuthinfoException.new(resp), "Unable to parse JSON response: #{resp.body.inspect}"
|
33
42
|
end
|
34
43
|
else
|
35
44
|
raise AuthinfoException, "Unexpected HTTP status code from server: #{resp.code}"
|
36
45
|
end
|
37
46
|
end
|
38
47
|
|
39
|
-
def auth_info
|
40
|
-
return PortableContacts::Person.new(request_auth_info['entry'])
|
41
|
-
end
|
42
|
-
|
43
48
|
class AuthinfoException < ::StandardError
|
44
49
|
end
|
45
50
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
1
3
|
module ProoflinkConnect
|
2
4
|
class Configuration
|
3
|
-
include Singleton
|
4
5
|
|
5
6
|
@@defaults = {
|
6
|
-
:provider_endpoint => "prooflink.
|
7
|
+
:provider_endpoint => "prooflink.com",
|
7
8
|
:subdomain => "example",
|
8
9
|
:protocol => "https"
|
9
10
|
}
|
@@ -13,5 +14,16 @@ module ProoflinkConnect
|
|
13
14
|
end
|
14
15
|
|
15
16
|
attr_accessor :provider_endpoint, :subdomain, :api_key, :protocol
|
17
|
+
|
18
|
+
def validate!
|
19
|
+
raise InvalidConfigurationError if [:provider_endpoint, :subdomain, :api_key, :protocol].any?{|option|send(option).blank?}
|
20
|
+
end
|
21
|
+
|
22
|
+
def base_uri
|
23
|
+
"#{protocol}://#{[subdomain, provider_endpoint].compact.join(".")}"
|
24
|
+
end
|
25
|
+
|
26
|
+
class InvalidConfigurationError < ::StandardError
|
27
|
+
end
|
16
28
|
end
|
17
29
|
end
|
@@ -1,29 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
attr_accessor :api_key
|
1
|
+
require 'httparty'
|
2
|
+
require "active_support/core_ext/hash/keys"
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
class ProoflinkConnect::Invite
|
5
|
+
attr_reader :configuration, :attributes
|
6
|
+
attr_accessor :locale
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
def initialize(attributes, configuration = ProoflinkConnect.config)
|
9
|
+
@attributes = attributes.stringify_keys
|
10
|
+
@configuration = configuration
|
12
11
|
end
|
13
12
|
|
14
|
-
|
13
|
+
def save
|
14
|
+
uri = configuration.base_uri + "/invites"
|
15
|
+
params = { "invite" => attributes, "api_key" => configuration.api_key, "locale" => locale || 'nl' }
|
16
|
+
response = HTTParty.post(uri, :body => params)
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
if response.headers["status"] == "200"
|
19
|
+
self.attributes.merge! JSON.parse(response.body)["entry"].stringify_keys
|
20
|
+
end
|
19
21
|
|
20
|
-
|
21
|
-
ProoflinkConnect::PortableContacts::Person.new(self.entry.attributes)
|
22
|
+
return !attributes["id"].nil?
|
22
23
|
end
|
23
24
|
|
24
|
-
def
|
25
|
-
|
26
|
-
prefix_options[:locale] = self.locale||"nl"
|
27
|
-
super
|
25
|
+
def person
|
26
|
+
ProoflinkConnect::PortableContacts::Person.new(attributes)
|
28
27
|
end
|
29
|
-
end
|
28
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module ProoflinkConnect
|
4
|
+
class Share
|
5
|
+
def self.post(transaction, message)
|
6
|
+
uri = ProoflinkConnect.config.base_uri + "/shares/post_share_transaction"
|
7
|
+
api_key = ProoflinkConnect.config.api_key
|
8
|
+
params = {"api_key" => api_key, "transaction" => transaction,
|
9
|
+
"message" => message, "format" => "json"}
|
10
|
+
response = HTTParty.post(uri, :body => params)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -9,7 +9,8 @@ module ProoflinkConnect
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def to_html
|
12
|
-
"<iframe src='#{ProoflinkConnect.config.protocol}://#{[ProoflinkConnect.config.subdomain, ProoflinkConnect.config.provider_endpoint].compact.join(".")}/#{@options[:locale]||"en"}/shares/button?message=#{CGI.escape @message}' style='width:
|
12
|
+
html = "<iframe src='#{ProoflinkConnect.config.protocol}://#{[ProoflinkConnect.config.subdomain, ProoflinkConnect.config.provider_endpoint].compact.join(".")}/#{@options[:locale]||"en"}/shares/button?message=#{CGI.escape @message}' style='width: 102px; height: 100px; border: 0;display: block' frameborder='0'></iframe>"
|
13
|
+
html.respond_to?(:html_safe) ? html.html_safe : html
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
data/prooflink_connect.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.authors = ["Chiel Wester", "Jeroen Bulters"]
|
9
9
|
s.email = ["chiel.wester@holder.nl", "jeroen@bulte.rs"]
|
10
|
-
s.homepage = "https://github.com/
|
10
|
+
s.homepage = "https://github.com/prooflink/prooflink_connect"
|
11
11
|
s.summary = "Make a connection to the prooflink connect api"
|
12
12
|
s.description = "Make a connection to the prooflink connect api for single sign on authentication"
|
13
13
|
|
@@ -15,10 +15,12 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.rubyforge_project = "prooflink_connect"
|
16
16
|
|
17
17
|
s.add_dependency 'json'
|
18
|
-
s.add_dependency '
|
18
|
+
s.add_dependency 'httparty'
|
19
|
+
s.add_dependency 'activesupport'
|
19
20
|
|
20
21
|
s.add_development_dependency "bundler", ">= 1.0.0"
|
21
22
|
s.add_development_dependency "rspec"
|
23
|
+
s.add_development_dependency "webmock"
|
22
24
|
|
23
25
|
s.files = `git ls-files`.split("\n")
|
24
26
|
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ProoflinkConnect::Share do
|
4
|
+
before do
|
5
|
+
ProoflinkConnect.configure do |config|
|
6
|
+
config.api_key = "1234"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "posts a message to Prooflink" do
|
11
|
+
stub_request(:post, "https://example.prooflink.com/shares/post_share_transaction").
|
12
|
+
with(:body => "format=json&api_key=1234&message=This%20is%20pretty%20awesome&transaction=pl1").
|
13
|
+
to_return(:status => 200, :body => "", :headers => {})
|
14
|
+
ProoflinkConnect::Share.post("pl1", "This is pretty awesome")
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,3 @@
|
|
1
|
-
require '
|
1
|
+
require File.expand_path('../../lib/prooflink_connect', __FILE__)
|
2
2
|
require 'rspec'
|
3
|
-
require 'rspec
|
4
|
-
# require 'rack/test'
|
5
|
-
# require 'webmock/rspec'
|
6
|
-
|
7
|
-
# include Rack::Test::Methods
|
8
|
-
# include WebMock
|
9
|
-
|
10
|
-
require 'prooflink_connect'
|
11
|
-
|
12
|
-
# WebMock.disable_net_connect!
|
3
|
+
require 'webmock/rspec'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prooflink_connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 15
|
10
|
+
version: 0.0.15
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Chiel Wester
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-08-08 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
type: :runtime
|
35
35
|
version_requirements: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
37
|
+
name: httparty
|
38
38
|
prerelease: false
|
39
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
@@ -48,9 +48,23 @@ dependencies:
|
|
48
48
|
type: :runtime
|
49
49
|
version_requirements: *id002
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
|
-
name:
|
51
|
+
name: activesupport
|
52
52
|
prerelease: false
|
53
53
|
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
type: :runtime
|
63
|
+
version_requirements: *id003
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: bundler
|
66
|
+
prerelease: false
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
54
68
|
none: false
|
55
69
|
requirements:
|
56
70
|
- - ">="
|
@@ -62,11 +76,11 @@ dependencies:
|
|
62
76
|
- 0
|
63
77
|
version: 1.0.0
|
64
78
|
type: :development
|
65
|
-
version_requirements: *
|
79
|
+
version_requirements: *id004
|
66
80
|
- !ruby/object:Gem::Dependency
|
67
81
|
name: rspec
|
68
82
|
prerelease: false
|
69
|
-
requirement: &
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
70
84
|
none: false
|
71
85
|
requirements:
|
72
86
|
- - ">="
|
@@ -76,7 +90,21 @@ dependencies:
|
|
76
90
|
- 0
|
77
91
|
version: "0"
|
78
92
|
type: :development
|
79
|
-
version_requirements: *
|
93
|
+
version_requirements: *id005
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: webmock
|
96
|
+
prerelease: false
|
97
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
version: "0"
|
106
|
+
type: :development
|
107
|
+
version_requirements: *id006
|
80
108
|
description: Make a connection to the prooflink connect api for single sign on authentication
|
81
109
|
email:
|
82
110
|
- chiel.wester@holder.nl
|
@@ -100,13 +128,15 @@ files:
|
|
100
128
|
- lib/prooflink_connect/portable_contacts.rb
|
101
129
|
- lib/prooflink_connect/portable_contacts/collection.rb
|
102
130
|
- lib/prooflink_connect/portable_contacts/person.rb
|
131
|
+
- lib/prooflink_connect/share.rb
|
103
132
|
- lib/prooflink_connect/share_button.rb
|
104
133
|
- lib/prooflink_connect/version.rb
|
105
134
|
- prooflink_connect.gemspec
|
135
|
+
- spec/prooflink_connect/share_spec.rb
|
106
136
|
- spec/prooflink_connect_spec.rb
|
107
137
|
- spec/spec_helper.rb
|
108
138
|
has_rdoc: true
|
109
|
-
homepage: https://github.com/
|
139
|
+
homepage: https://github.com/prooflink/prooflink_connect
|
110
140
|
licenses: []
|
111
141
|
|
112
142
|
post_install_message:
|