open_auth2 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/License +9 -0
- data/Rakefile +126 -0
- data/Readme.markdown +235 -0
- data/Spec.markdown +0 -0
- data/examples/fb.rb +20 -0
- data/examples/google.rb +57 -0
- data/lib/open_auth2/client.rb +184 -0
- data/lib/open_auth2/config.rb +95 -0
- data/lib/open_auth2/connection.rb +37 -0
- data/lib/open_auth2/delegate_to_config.rb +25 -0
- data/lib/open_auth2/provider/base.rb +31 -0
- data/lib/open_auth2/provider/default.rb +24 -0
- data/lib/open_auth2/provider/facebook.rb +25 -0
- data/lib/open_auth2/provider/google.rb +30 -0
- data/lib/open_auth2/provider.rb +21 -0
- data/lib/open_auth2/token.rb +126 -0
- data/lib/open_auth2/version.rb +3 -0
- data/lib/open_auth2.rb +23 -0
- data/open_auth2.gemspec +80 -0
- data/spec/client_spec.rb +92 -0
- data/spec/config_spec.rb +116 -0
- data/spec/facebook/client_spec.rb +82 -0
- data/spec/facebook/token_spec.rb +92 -0
- data/spec/fixtures/creds.rb +18 -0
- data/spec/fixtures/vcr/fb/access_token.yml +36 -0
- data/spec/fixtures/vcr/fb/cocacola.yml +68 -0
- data/spec/fixtures/vcr/fb/me.yml +36 -0
- data/spec/fixtures/vcr/fb/post.yml +34 -0
- data/spec/fixtures/vcr/fb/refresh_token.yml +36 -0
- data/spec/fixtures/vcr/goog/access_token.yml +38 -0
- data/spec/fixtures/vcr/goog/list.yml +50 -0
- data/spec/fixtures/vcr/goog/post.yml +44 -0
- data/spec/fixtures/vcr/goog/refresh_token.yml +37 -0
- data/spec/google/client_spec.rb +59 -0
- data/spec/google/token_spec.rb +87 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/token_spec.rb +23 -0
- metadata +236 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :post
|
5
|
+
uri: https://accounts.google.com:443/o/oauth2/token
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
content-type:
|
9
|
+
- application/x-www-form-urlencoded
|
10
|
+
accept:
|
11
|
+
- application/json
|
12
|
+
response: !ruby/struct:VCR::Response
|
13
|
+
status: !ruby/struct:VCR::ResponseStatus
|
14
|
+
code: 200
|
15
|
+
message: OK
|
16
|
+
headers:
|
17
|
+
cache-control:
|
18
|
+
- no-cache, no-store, max-age=0, must-revalidate
|
19
|
+
pragma:
|
20
|
+
- no-cache
|
21
|
+
expires:
|
22
|
+
- Fri, 01 Jan 1990 00:00:00 GMT
|
23
|
+
date:
|
24
|
+
- Sat, 03 Mar 2012 00:38:51 GMT
|
25
|
+
content-type:
|
26
|
+
- application/json
|
27
|
+
x-content-type-options:
|
28
|
+
- nosniff
|
29
|
+
x-frame-options:
|
30
|
+
- SAMEORIGIN
|
31
|
+
x-xss-protection:
|
32
|
+
- 1; mode=block
|
33
|
+
server:
|
34
|
+
- GSE
|
35
|
+
body: ! "{\n \"access_token\" : \"ya29.AHES6ZR2V9Y9vZnTC4YFHChTetjwML1mDLZRSmiBx-XT9g\",\n
|
36
|
+
\ \"token_type\" : \"Bearer\",\n \"expires_in\" : 3600\n}"
|
37
|
+
http_version: '1.1'
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'open_auth2'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'Google Client' do
|
5
|
+
let(:config) do
|
6
|
+
OpenAuth2::Config.new do |c|
|
7
|
+
c.provider = :google
|
8
|
+
c.access_token = Creds::Google::AccessToken
|
9
|
+
c.refresh_token = Creds::Google::RefreshToken
|
10
|
+
c.redirect_uri = 'http://localhost:9393/google/callback'
|
11
|
+
c.path_prefix = '/calendar/v3'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
subject { OpenAuth2::Client.new(config) }
|
16
|
+
|
17
|
+
context '#get' do
|
18
|
+
it 'makes private request' do
|
19
|
+
VCR.use_cassette('goog/list') do
|
20
|
+
request = subject.get(:path => '/users/me/calendarList')
|
21
|
+
request.status.should == 200
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context '#post' do
|
27
|
+
let(:post_url) do
|
28
|
+
'/calendar/v3/calendars/openauth2@gmail.com/events'
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:body) do
|
32
|
+
"{\"summary\":\"From OpenAuth2\",\"start\":{\"dateTime\":\"2012-03-01T10:00:00.000-07:00\"},\"end\":{\"dateTime\":\"2012-03-02T10:25:00.000-07:00\"}}"
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'POST request' do
|
36
|
+
content_type = 'application/json'
|
37
|
+
|
38
|
+
VCR.use_cassette('goog/post') do
|
39
|
+
request = subject.post(:path => post_url,
|
40
|
+
:body => body,
|
41
|
+
:content_type => content_type)
|
42
|
+
request.status.should == 200
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'POST request via #run_request' do
|
47
|
+
header = {"Content-Type" => "application/json"}
|
48
|
+
full_url = "#{post_url}?access_token=#{Creds::Google::AccessToken}"
|
49
|
+
|
50
|
+
VCR.use_cassette('goog/post') do
|
51
|
+
request = subject.run_request(:verb => :post,
|
52
|
+
:path => full_url,
|
53
|
+
:body => body,
|
54
|
+
:header => header)
|
55
|
+
request.status.should == 200
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'open_auth2'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'Google Token' do
|
5
|
+
let(:config) do
|
6
|
+
OpenAuth2::Config.new do |c|
|
7
|
+
c.provider = :google
|
8
|
+
c.client_id = Creds::Google::ClientId
|
9
|
+
c.client_secret = Creds::Google::ClientSecret
|
10
|
+
c.code = Creds::Google::Code
|
11
|
+
c.redirect_uri = 'http://localhost:9393/google/callback'
|
12
|
+
c.scope = ['https://www.googleapis.com/auth/calendar']
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
subject do
|
17
|
+
OpenAuth2::Token.new(config)
|
18
|
+
end
|
19
|
+
|
20
|
+
context '#build_code_url' do
|
21
|
+
it 'returns url' do
|
22
|
+
url = "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=77848792642.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A9393%2Fgoogle%2Fcallback&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar&approval_prompt=force&access_type=offline"
|
23
|
+
|
24
|
+
params = {:approval_prompt => 'force', :access_type => 'offline'}
|
25
|
+
subject.build_code_url(params).should == url
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context '#get' do
|
30
|
+
let(:get_token) do
|
31
|
+
VCR.use_cassette('goog/access_token') do
|
32
|
+
subject.get
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:time) do
|
37
|
+
Time.local(2012, 12, 21)
|
38
|
+
end
|
39
|
+
|
40
|
+
before do
|
41
|
+
Timecop.freeze(time) do
|
42
|
+
get_token
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'requests OAuth server for access token' do
|
47
|
+
get_token.status.should == 200
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'sets #access_token' do
|
51
|
+
subject.access_token.should == Creds::Google::AccessToken
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'sets #refresh_token' do
|
55
|
+
subject.refresh_token.should == Creds::Google::RefreshToken
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'sets #token_arrived_at' do
|
59
|
+
subject.token_arrived_at.should == time
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'returns false for #token_expired?' do
|
63
|
+
subject.token_expired?.should == true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context '#refresh' do
|
68
|
+
let(:refresh_token) do
|
69
|
+
config.configure do |c|
|
70
|
+
c.refresh_token = Creds::Google::RefreshToken
|
71
|
+
end
|
72
|
+
|
73
|
+
VCR.use_cassette('goog/refresh_token') do
|
74
|
+
subject.refresh
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'requests OAuth server to refresh access token' do
|
79
|
+
refresh_token.status.should == 200
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'sets new #access_token' do
|
83
|
+
refresh_token
|
84
|
+
subject.access_token.should == Creds::Google::NewAccessToken
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/token_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'open_auth2'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe OpenAuth2::Token do
|
5
|
+
let(:config) do
|
6
|
+
OpenAuth2::Config.new do |c|
|
7
|
+
c.provider = :facebook
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
subject { OpenAuth2::Token.new(config) }
|
12
|
+
|
13
|
+
context '#initialize' do
|
14
|
+
it 'accepts config as argument' do
|
15
|
+
subject = described_class.new(config)
|
16
|
+
subject.config.should == config
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'sets @faraday_url' do
|
20
|
+
subject.faraday_url.should == 'https://graph.facebook.com'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,236 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: open_auth2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.8
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- sent-hil
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.7'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.7'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activesupport
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.1'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.1'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: json
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.9'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.9'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '2.8'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '2.8'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: vcr
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - '='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.11.3
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - '='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.11.3
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: fakeweb
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.3'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '1.3'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: timecop
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ~>
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0.3'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ~>
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0.3'
|
142
|
+
description: OpenAuth2 is a simple OAuth2 client.
|
143
|
+
email:
|
144
|
+
- me@sent-hil.com
|
145
|
+
executables: []
|
146
|
+
extensions: []
|
147
|
+
extra_rdoc_files: []
|
148
|
+
files:
|
149
|
+
- Gemfile
|
150
|
+
- License
|
151
|
+
- Rakefile
|
152
|
+
- Readme.markdown
|
153
|
+
- Spec.markdown
|
154
|
+
- examples/fb.rb
|
155
|
+
- examples/google.rb
|
156
|
+
- lib/open_auth2.rb
|
157
|
+
- lib/open_auth2/client.rb
|
158
|
+
- lib/open_auth2/config.rb
|
159
|
+
- lib/open_auth2/connection.rb
|
160
|
+
- lib/open_auth2/delegate_to_config.rb
|
161
|
+
- lib/open_auth2/provider.rb
|
162
|
+
- lib/open_auth2/provider/base.rb
|
163
|
+
- lib/open_auth2/provider/default.rb
|
164
|
+
- lib/open_auth2/provider/facebook.rb
|
165
|
+
- lib/open_auth2/provider/google.rb
|
166
|
+
- lib/open_auth2/token.rb
|
167
|
+
- lib/open_auth2/version.rb
|
168
|
+
- open_auth2.gemspec
|
169
|
+
- spec/client_spec.rb
|
170
|
+
- spec/config_spec.rb
|
171
|
+
- spec/facebook/client_spec.rb
|
172
|
+
- spec/facebook/token_spec.rb
|
173
|
+
- spec/fixtures/creds.rb
|
174
|
+
- spec/fixtures/vcr/fb/access_token.yml
|
175
|
+
- spec/fixtures/vcr/fb/cocacola.yml
|
176
|
+
- spec/fixtures/vcr/fb/me.yml
|
177
|
+
- spec/fixtures/vcr/fb/post.yml
|
178
|
+
- spec/fixtures/vcr/fb/refresh_token.yml
|
179
|
+
- spec/fixtures/vcr/goog/access_token.yml
|
180
|
+
- spec/fixtures/vcr/goog/list.yml
|
181
|
+
- spec/fixtures/vcr/goog/post.yml
|
182
|
+
- spec/fixtures/vcr/goog/refresh_token.yml
|
183
|
+
- spec/google/client_spec.rb
|
184
|
+
- spec/google/token_spec.rb
|
185
|
+
- spec/spec_helper.rb
|
186
|
+
- spec/token_spec.rb
|
187
|
+
homepage: https://github.com/sent-hil/OpenAuth2
|
188
|
+
licenses: []
|
189
|
+
post_install_message:
|
190
|
+
rdoc_options: []
|
191
|
+
require_paths:
|
192
|
+
- lib
|
193
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
194
|
+
none: false
|
195
|
+
requirements:
|
196
|
+
- - ! '>='
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: '0'
|
199
|
+
segments:
|
200
|
+
- 0
|
201
|
+
hash: 1597151657867498836
|
202
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
|
+
none: false
|
204
|
+
requirements:
|
205
|
+
- - ! '>='
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '0'
|
208
|
+
segments:
|
209
|
+
- 0
|
210
|
+
hash: 1597151657867498836
|
211
|
+
requirements: []
|
212
|
+
rubyforge_project: OpenAuth2
|
213
|
+
rubygems_version: 1.8.24
|
214
|
+
signing_key:
|
215
|
+
specification_version: 3
|
216
|
+
summary: OpenAuth2 is a simple OAuth2 client written on top of Faraday in Ruby. The
|
217
|
+
goal is a simple, well documented, easy to use interface for all your OAuth2 needs.
|
218
|
+
test_files:
|
219
|
+
- spec/client_spec.rb
|
220
|
+
- spec/config_spec.rb
|
221
|
+
- spec/facebook/client_spec.rb
|
222
|
+
- spec/facebook/token_spec.rb
|
223
|
+
- spec/fixtures/creds.rb
|
224
|
+
- spec/fixtures/vcr/fb/access_token.yml
|
225
|
+
- spec/fixtures/vcr/fb/cocacola.yml
|
226
|
+
- spec/fixtures/vcr/fb/me.yml
|
227
|
+
- spec/fixtures/vcr/fb/post.yml
|
228
|
+
- spec/fixtures/vcr/fb/refresh_token.yml
|
229
|
+
- spec/fixtures/vcr/goog/access_token.yml
|
230
|
+
- spec/fixtures/vcr/goog/list.yml
|
231
|
+
- spec/fixtures/vcr/goog/post.yml
|
232
|
+
- spec/fixtures/vcr/goog/refresh_token.yml
|
233
|
+
- spec/google/client_spec.rb
|
234
|
+
- spec/google/token_spec.rb
|
235
|
+
- spec/spec_helper.rb
|
236
|
+
- spec/token_spec.rb
|