oauth2-aptible 0.9.4.aptible

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ describe OAuth2::Strategy::Base do
4
+ it 'initializes with a Client' do
5
+ expect { OAuth2::Strategy::Base.new(OAuth2::Client.new('abc', 'def')) }.not_to raise_error
6
+ end
7
+ end
@@ -0,0 +1,81 @@
1
+ require 'helper'
2
+
3
+ describe OAuth2::Strategy::ClientCredentials do
4
+ let(:kvform_token) { 'expires_in=600&access_token=salmon&refresh_token=trout' }
5
+ let(:json_token) { '{"expires_in":600,"access_token":"salmon","refresh_token":"trout"}' }
6
+
7
+ let(:client) do
8
+ OAuth2::Client.new('abc', 'def', :site => 'http://api.example.com') do |builder|
9
+ builder.adapter :test do |stub|
10
+ stub.post('/oauth/token', 'grant_type' => 'client_credentials') do |env|
11
+ client_id, client_secret = Base64.decode64(env[:request_headers]['Authorization'].split(' ', 2)[1]).split(':', 2)
12
+ client_id == 'abc' && client_secret == 'def' || fail(Faraday::Adapter::Test::Stubs::NotFound)
13
+ case @mode
14
+ when 'formencoded'
15
+ [200, {'Content-Type' => 'application/x-www-form-urlencoded'}, kvform_token]
16
+ when 'json'
17
+ [200, {'Content-Type' => 'application/json'}, json_token]
18
+ end
19
+ end
20
+ stub.post('/oauth/token', 'client_id' => 'abc', 'client_secret' => 'def', 'grant_type' => 'client_credentials') do |env|
21
+ case @mode
22
+ when 'formencoded'
23
+ [200, {'Content-Type' => 'application/x-www-form-urlencoded'}, kvform_token]
24
+ when 'json'
25
+ [200, {'Content-Type' => 'application/json'}, json_token]
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ subject { client.client_credentials }
33
+
34
+ describe '#authorize_url' do
35
+ it 'raises NotImplementedError' do
36
+ expect { subject.authorize_url }.to raise_error(NotImplementedError)
37
+ end
38
+ end
39
+
40
+ describe '#authorization' do
41
+ it 'generates an Authorization header value for HTTP Basic Authentication' do
42
+ [
43
+ ['abc', 'def', 'Basic YWJjOmRlZg=='],
44
+ ['xxx', 'secret', 'Basic eHh4OnNlY3JldA==']
45
+ ].each do |client_id, client_secret, expected|
46
+ expect(subject.authorization(client_id, client_secret)).to eq(expected)
47
+ end
48
+ end
49
+ end
50
+
51
+ %w(json formencoded).each do |mode|
52
+ %w(default basic_auth request_body).each do |auth_scheme|
53
+ describe "#get_token (#{mode}) (#{auth_scheme})" do
54
+ before do
55
+ @mode = mode
56
+ @access = subject.get_token({}, auth_scheme == 'default' ? {} : {'auth_scheme' => auth_scheme})
57
+ end
58
+
59
+ it 'returns AccessToken with same Client' do
60
+ expect(@access.client).to eq(client)
61
+ end
62
+
63
+ it 'returns AccessToken with #token' do
64
+ expect(@access.token).to eq('salmon')
65
+ end
66
+
67
+ it 'returns AccessToken without #refresh_token' do
68
+ expect(@access.refresh_token).to be_nil
69
+ end
70
+
71
+ it 'returns AccessToken with #expires_in' do
72
+ expect(@access.expires_in).to eq(600)
73
+ end
74
+
75
+ it 'returns AccessToken with #expires_at' do
76
+ expect(@access.expires_at).not_to be_nil
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,28 @@
1
+ require 'helper'
2
+
3
+ describe OAuth2::Strategy::Implicit do
4
+ let(:client) { OAuth2::Client.new('abc', 'def', :site => 'http://api.example.com') }
5
+
6
+ subject { client.implicit }
7
+
8
+ describe '#authorize_url' do
9
+ it 'includes the client_id' do
10
+ expect(subject.authorize_url).to include('client_id=abc')
11
+ end
12
+
13
+ it 'includes the type' do
14
+ expect(subject.authorize_url).to include('response_type=token')
15
+ end
16
+
17
+ it 'includes passed in options' do
18
+ cb = 'http://myserver.local/oauth/callback'
19
+ expect(subject.authorize_url(:redirect_uri => cb)).to include("redirect_uri=#{Rack::Utils.escape(cb)}")
20
+ end
21
+ end
22
+
23
+ describe '#get_token' do
24
+ it 'raises NotImplementedError' do
25
+ expect { subject.get_token }.to raise_error(NotImplementedError)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,57 @@
1
+ require 'helper'
2
+
3
+ describe OAuth2::Strategy::Password do
4
+ let(:client) do
5
+ cli = OAuth2::Client.new('abc', 'def', :site => 'http://api.example.com')
6
+ cli.connection.build do |b|
7
+ b.adapter :test do |stub|
8
+ stub.post('/oauth/token') do |env|
9
+ case @mode
10
+ when 'formencoded'
11
+ [200, {'Content-Type' => 'application/x-www-form-urlencoded'}, 'expires_in=600&access_token=salmon&refresh_token=trout']
12
+ when 'json'
13
+ [200, {'Content-Type' => 'application/json'}, '{"expires_in":600,"access_token":"salmon","refresh_token":"trout"}']
14
+ end
15
+ end
16
+ end
17
+ end
18
+ cli
19
+ end
20
+ subject { client.password }
21
+
22
+ describe '#authorize_url' do
23
+ it 'raises NotImplementedError' do
24
+ expect { subject.authorize_url }.to raise_error(NotImplementedError)
25
+ end
26
+ end
27
+
28
+ %w(json formencoded).each do |mode|
29
+ describe "#get_token (#{mode})" do
30
+ before do
31
+ @mode = mode
32
+ @access = subject.get_token('username', 'password')
33
+ end
34
+
35
+ it 'returns AccessToken with same Client' do
36
+ expect(@access.client).to eq(client)
37
+ end
38
+
39
+ it 'returns AccessToken with #token' do
40
+ expect(@access.token).to eq('salmon')
41
+ end
42
+
43
+ it 'returns AccessToken with #refresh_token' do
44
+ expect(@access.refresh_token).to eq('trout')
45
+ end
46
+
47
+ it 'returns AccessToken with #expires_in' do
48
+ expect(@access.expires_in).to eq(600)
49
+ end
50
+
51
+ it 'returns AccessToken with #expires_at' do
52
+ expect(@access.expires_at).not_to be_nil
53
+ end
54
+ end
55
+ end
56
+
57
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oauth2-aptible
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.4.aptible
5
+ platform: ruby
6
+ authors:
7
+ - Frank Macreery
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ - - <
35
+ - !ruby/object:Gem::Version
36
+ version: '0.10'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0.8'
44
+ - - <
45
+ - !ruby/object:Gem::Version
46
+ version: '0.10'
47
+ - !ruby/object:Gem::Dependency
48
+ name: multi_json
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '1.3'
61
+ - !ruby/object:Gem::Dependency
62
+ name: multi_xml
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '0.5'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: '0.5'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rack
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ version: '1.2'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ version: '1.2'
89
+ - !ruby/object:Gem::Dependency
90
+ name: jwt
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ version: 0.1.8
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: 0.1.8
103
+ description: A Ruby wrapper for the OAuth 2.0 protocol built with a similar style
104
+ to the original OAuth spec.
105
+ email:
106
+ - frank@macreery.com
107
+ executables: []
108
+ extensions: []
109
+ extra_rdoc_files: []
110
+ files:
111
+ - .document
112
+ - CONTRIBUTING.md
113
+ - LICENSE.md
114
+ - README.md
115
+ - Rakefile
116
+ - lib/oauth2.rb
117
+ - lib/oauth2/access_token.rb
118
+ - lib/oauth2/client.rb
119
+ - lib/oauth2/error.rb
120
+ - lib/oauth2/response.rb
121
+ - lib/oauth2/strategy/assertion.rb
122
+ - lib/oauth2/strategy/auth_code.rb
123
+ - lib/oauth2/strategy/base.rb
124
+ - lib/oauth2/strategy/client_credentials.rb
125
+ - lib/oauth2/strategy/implicit.rb
126
+ - lib/oauth2/strategy/password.rb
127
+ - lib/oauth2/version.rb
128
+ - oauth2.gemspec
129
+ - spec/helper.rb
130
+ - spec/oauth2/access_token_spec.rb
131
+ - spec/oauth2/client_spec.rb
132
+ - spec/oauth2/response_spec.rb
133
+ - spec/oauth2/strategy/assertion_spec.rb
134
+ - spec/oauth2/strategy/auth_code_spec.rb
135
+ - spec/oauth2/strategy/base_spec.rb
136
+ - spec/oauth2/strategy/client_credentials_spec.rb
137
+ - spec/oauth2/strategy/implicit_spec.rb
138
+ - spec/oauth2/strategy/password_spec.rb
139
+ homepage: http://github.com/fancyremarker/oauth2-aptible
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - '>'
155
+ - !ruby/object:Gem::Version
156
+ version: 1.3.1
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.2.1
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: A Ruby wrapper for the OAuth 2.0 protocol.
163
+ test_files:
164
+ - spec/helper.rb
165
+ - spec/oauth2/access_token_spec.rb
166
+ - spec/oauth2/client_spec.rb
167
+ - spec/oauth2/response_spec.rb
168
+ - spec/oauth2/strategy/assertion_spec.rb
169
+ - spec/oauth2/strategy/auth_code_spec.rb
170
+ - spec/oauth2/strategy/base_spec.rb
171
+ - spec/oauth2/strategy/client_credentials_spec.rb
172
+ - spec/oauth2/strategy/implicit_spec.rb
173
+ - spec/oauth2/strategy/password_spec.rb
174
+ has_rdoc: