OpenAuth2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,50 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: https://www.googleapis.com:443/calendar/v3/users/me/calendarList?access_token=ya29.AHES6ZRXhZRQLYkdqVoHz9qxzTkNVhElBAQitCdJq816PQ
6
+ body:
7
+ headers:
8
+ accept-encoding:
9
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
10
+ response: !ruby/struct:VCR::Response
11
+ status: !ruby/struct:VCR::ResponseStatus
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ expires:
16
+ - Sat, 03 Mar 2012 00:43:30 GMT
17
+ date:
18
+ - Sat, 03 Mar 2012 00:43:30 GMT
19
+ cache-control:
20
+ - private, max-age=0, must-revalidate, no-transform
21
+ etag:
22
+ - ! '"05UDIdu8MZ4l75GrR4XASfYyuJA/zOhVd4w0MdY1DcWnD1I5Aw6EG1A"'
23
+ content-type:
24
+ - application/json; charset=UTF-8
25
+ x-content-type-options:
26
+ - nosniff
27
+ x-frame-options:
28
+ - SAMEORIGIN
29
+ x-xss-protection:
30
+ - 1; mode=block
31
+ server:
32
+ - GSE
33
+ body: ! "{\n \"kind\": \"calendar#calendarList\",\n \"etag\": \"\\\"05UDIdu8MZ4l75GrR4XASfYyuJA/RlR_v1har4GKp7r_0Pat7Cwxutc\\\"\",\n
34
+ \"items\": [\n {\n \"kind\": \"calendar#calendarListEntry\",\n \"etag\":
35
+ \"\\\"05UDIdu8MZ4l75GrR4XASfYyuJA/Xy22eQFbkRyL-kXKKp9gXUGjeVU\\\"\",\n \"id\":
36
+ \"#contacts@group.v.calendar.google.com\",\n \"summary\": \"Contacts' birthdays
37
+ and events\",\n \"description\": \"Your contacts' birthdays and anniversaries\",\n
38
+ \ \"timeZone\": \"America/Los_Angeles\",\n \"colorId\": \"12\",\n \"selected\":
39
+ true,\n \"accessRole\": \"reader\"\n },\n {\n \"kind\": \"calendar#calendarListEntry\",\n
40
+ \ \"etag\": \"\\\"05UDIdu8MZ4l75GrR4XASfYyuJA/gHhWepcSR_7BG-SE_f3YmpNqHhA\\\"\",\n
41
+ \ \"id\": \"en.usa#holiday@group.v.calendar.google.com\",\n \"summary\":
42
+ \"US Holidays\",\n \"description\": \"US Holidays\",\n \"timeZone\": \"America/Los_Angeles\",\n
43
+ \ \"colorId\": \"9\",\n \"selected\": true,\n \"accessRole\": \"reader\"\n
44
+ \ },\n {\n \"kind\": \"calendar#calendarListEntry\",\n \"etag\": \"\\\"05UDIdu8MZ4l75GrR4XASfYyuJA/_btzWSa3jrAuPbrE6wq47gM7i5U\\\"\",\n
45
+ \ \"id\": \"openauth2@gmail.com\",\n \"summary\": \"openauth2@gmail.com\",\n
46
+ \ \"timeZone\": \"America/Los_Angeles\",\n \"colorId\": \"15\",\n \"selected\":
47
+ true,\n \"accessRole\": \"owner\",\n \"defaultReminders\": [\n {\n \"method\":
48
+ \"email\",\n \"minutes\": 10\n },\n {\n \"method\": \"popup\",\n
49
+ \ \"minutes\": 10\n }\n ]\n }\n ]\n}\n"
50
+ http_version: '1.1'
@@ -0,0 +1,44 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: https://www.googleapis.com:443/calendar/v3/calendars/openauth2@gmail.com/events?access_token=ya29.AHES6ZRXhZRQLYkdqVoHz9qxzTkNVhElBAQitCdJq816PQ
6
+ body:
7
+ headers:
8
+ content-type:
9
+ - application/json
10
+ response: !ruby/struct:VCR::Response
11
+ status: !ruby/struct:VCR::ResponseStatus
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ cache-control:
16
+ - no-cache, no-store, max-age=0, must-revalidate
17
+ pragma:
18
+ - no-cache
19
+ expires:
20
+ - Fri, 01 Jan 1990 00:00:00 GMT
21
+ date:
22
+ - Sat, 03 Mar 2012 00:48:55 GMT
23
+ etag:
24
+ - ! '"05UDIdu8MZ4l75GrR4XASfYyuJA/Q05qQm43RGRKaEVBQUFBQUFBQUFBQT09"'
25
+ content-type:
26
+ - application/json; charset=UTF-8
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 \"kind\": \"calendar#event\",\n \"etag\": \"\\\"05UDIdu8MZ4l75GrR4XASfYyuJA/Q05qQm43RGRKaEVBQUFBQUFBQUFBQT09\\\"\",\n
36
+ \"id\": \"htblfka4hqckqtiirnriam72e4\",\n \"status\": \"confirmed\",\n \"htmlLink\":
37
+ \"https://www.google.com/calendar/event?eid=aHRibGZrYTRocWNrcXRpaXJucmlhbTcyZTQgb3BlbmF1dGgyQG0\",\n
38
+ \"created\": \"2012-03-03T00:48:55.000Z\",\n \"updated\": \"2012-03-03T00:48:55.000Z\",\n
39
+ \"summary\": \"From OpenAuth2\",\n \"creator\": {\n \"email\": \"openauth2@gmail.com\"\n
40
+ },\n \"organizer\": {\n \"email\": \"openauth2@gmail.com\"\n },\n \"start\":
41
+ {\n \"dateTime\": \"2012-01-20T09:00:00-08:00\"\n },\n \"end\": {\n \"dateTime\":
42
+ \"2012-01-20T09:25:00-08:00\"\n },\n \"iCalUID\": \"htblfka4hqckqtiirnriam72e4@google.com\",\n
43
+ \"sequence\": 0,\n \"reminders\": {\n \"useDefault\": true\n }\n}\n"
44
+ http_version: '1.1'
@@ -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
@@ -0,0 +1,13 @@
1
+ if ENV['COVERAGE']
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+ end
5
+
6
+ require 'vcr'
7
+ require 'timecop'
8
+ require 'fixtures/creds'
9
+
10
+ VCR.config do |c|
11
+ c.cassette_library_dir = 'spec/fixtures/vcr'
12
+ c.stub_with :fakeweb
13
+ end
@@ -0,0 +1,23 @@
1
+ require 'open_auth2'
2
+ require 'spec_helper'
3
+
4
+ describe OpenAuth2::Client 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,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: OpenAuth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Senthil A
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: &70361644616180 !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: *70361644616180
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ requirement: &70361644615200 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.2'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70361644615200
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &70361644614360 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '0.9'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70361644614360
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &70361644613500 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.8'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70361644613500
58
+ - !ruby/object:Gem::Dependency
59
+ name: vcr
60
+ requirement: &70361644612160 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '1.11'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70361644612160
69
+ - !ruby/object:Gem::Dependency
70
+ name: fakeweb
71
+ requirement: &70361644608520 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '1.3'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70361644608520
80
+ - !ruby/object:Gem::Dependency
81
+ name: timecop
82
+ requirement: &70361644606700 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: '0.3'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70361644606700
91
+ description: OpenAuth2 is a thin OAuth2 wrapper written on top of Faraday in Ruby.
92
+ email:
93
+ - senthil196@gmail.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - Gemfile
99
+ - License
100
+ - Rakefile
101
+ - Readme.markdown
102
+ - Spec.markdown
103
+ - examples/fb.rb
104
+ - examples/google.rb
105
+ - lib/open_auth2.rb
106
+ - lib/open_auth2/client.rb
107
+ - lib/open_auth2/config.rb
108
+ - lib/open_auth2/connection.rb
109
+ - lib/open_auth2/delegate_to_config.rb
110
+ - lib/open_auth2/provider.rb
111
+ - lib/open_auth2/provider/base.rb
112
+ - lib/open_auth2/provider/default.rb
113
+ - lib/open_auth2/provider/facebook.rb
114
+ - lib/open_auth2/provider/google.rb
115
+ - lib/open_auth2/token.rb
116
+ - lib/open_auth2/version.rb
117
+ - open_auth2.gemspec
118
+ - spec/client_spec.rb
119
+ - spec/config_spec.rb
120
+ - spec/facebook/client_spec.rb
121
+ - spec/facebook/token_spec.rb
122
+ - spec/fixtures/creds.rb
123
+ - spec/fixtures/vcr/fb/access_token.yml
124
+ - spec/fixtures/vcr/fb/cocacola.yml
125
+ - spec/fixtures/vcr/fb/me.yml
126
+ - spec/fixtures/vcr/fb/post.yml
127
+ - spec/fixtures/vcr/fb/refresh_token.yml
128
+ - spec/fixtures/vcr/goog/access_token.yml
129
+ - spec/fixtures/vcr/goog/list.yml
130
+ - spec/fixtures/vcr/goog/post.yml
131
+ - spec/fixtures/vcr/goog/refresh_token.yml
132
+ - spec/google/client_spec.rb
133
+ - spec/google/token_spec.rb
134
+ - spec/spec_helper.rb
135
+ - spec/token_spec.rb
136
+ homepage: https://github.com/senthilnambi/OpenAuth2
137
+ licenses: []
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project: OpenAuth2
156
+ rubygems_version: 1.8.10
157
+ signing_key:
158
+ specification_version: 3
159
+ summary: OpenAuth2 is a thin OAuth2 wrapper written on top of Faraday in Ruby. The
160
+ goal is a simple, well documented, easy to use interface for all your OAuth2 needs.
161
+ test_files:
162
+ - spec/client_spec.rb
163
+ - spec/config_spec.rb
164
+ - spec/facebook/client_spec.rb
165
+ - spec/facebook/token_spec.rb
166
+ - spec/fixtures/creds.rb
167
+ - spec/fixtures/vcr/fb/access_token.yml
168
+ - spec/fixtures/vcr/fb/cocacola.yml
169
+ - spec/fixtures/vcr/fb/me.yml
170
+ - spec/fixtures/vcr/fb/post.yml
171
+ - spec/fixtures/vcr/fb/refresh_token.yml
172
+ - spec/fixtures/vcr/goog/access_token.yml
173
+ - spec/fixtures/vcr/goog/list.yml
174
+ - spec/fixtures/vcr/goog/post.yml
175
+ - spec/fixtures/vcr/goog/refresh_token.yml
176
+ - spec/google/client_spec.rb
177
+ - spec/google/token_spec.rb
178
+ - spec/spec_helper.rb
179
+ - spec/token_spec.rb