open_auth2 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -46,12 +46,6 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
46
46
  spec.rspec_opts = ['--backtrace']
47
47
  end
48
48
 
49
- desc "Generate SimpleCov test coverage and open in your browser"
50
- task :coverage do
51
- sh "rake spec COVERAGE=true"
52
- sh "open coverage/index.html"
53
- end
54
-
55
49
  desc "Open an irb session preloaded with this library"
56
50
  task :irb do
57
51
  sh "irb -rubygems -r ./lib/#{name}.rb"
data/Readme.markdown CHANGED
@@ -1,6 +1,6 @@
1
- # OpenAuth2 [![Build Status](https://secure.travis-ci.org/sent-hil/OpenAuth2.png?branch=master)][travis]
1
+ # open_auth2 [![Build Status](https://secure.travis-ci.org/sent-hil/open_auth2.png?branch=master)][travis]
2
2
 
3
- [travis]: http://travis-ci.org/sent-hil/OpenAuth2
3
+ [travis]: http://travis-ci.org/sent-hil/open_auth2
4
4
 
5
5
  OpenAuth2 is a thin OAuth2 wrapper written on top of Faraday in Ruby. The goal is a simple, well documented, easy to use interface for all your OAuth2 needs.
6
6
 
@@ -168,11 +168,11 @@ module OpenAuth2
168
168
  #
169
169
  def options
170
170
  {
171
- :response_type => 'code',
172
- :access_token_grant_name => 'authorization_code',
173
- :refresh_token_grant_name => 'refresh_token',
174
- :refresh_token_name => :refresh_token,
175
- :scope => [],
171
+ :response_type => 'code',
172
+ :access_token_grant_name => 'authorization_code',
173
+ :refresh_token_grant_name => 'refresh_token',
174
+ :refresh_token_name => :refresh_token,
175
+ :scope => [],
176
176
  }
177
177
  end
178
178
 
@@ -181,7 +181,7 @@ module OpenAuth2
181
181
  #
182
182
  def parse(config, response_body)
183
183
  # parse the response body
184
- access_token = response_body.gsub('access_token=', '')
184
+ access_token = response_body.gsub('access_token=', '')
185
185
 
186
186
  # update config to reflect new information
187
187
  config.access_token = access_token
data/examples/fb.rb CHANGED
@@ -1,18 +1,19 @@
1
1
  require_relative '../lib/open_auth2'
2
2
 
3
- ClientId = '216091171753850'
4
- ClientSecret = '56f751bef00d6d21e858566b873ac8f8'
5
- Code = ''
6
- AccessToken = ''
3
+ require 'yaml'
4
+ Creds = YAML.load_file('spec/fixtures/creds.yml')
5
+
6
+ Code = Creds['Facebook']['Code']
7
+ AccessToken = Creds['Facebook']['AccessToken']
7
8
 
8
9
  @config = OpenAuth2::Config.new do |c|
9
10
  c.provider = :facebook
10
- c.client_id = ClientId
11
- c.client_secret = ClientSecret
11
+ c.client_id = Creds['Facebook']['ClientId']
12
+ c.client_secret = Creds['Facebook']['ClientSecret']
12
13
  c.code = Code
13
14
  c.access_token = AccessToken
14
15
  c.redirect_uri = 'http://localhost:9393/'
15
- c.scope = ['manage_pages', 'read_insights']
16
+ c.scope = ['publish_stream']
16
17
  end
17
18
 
18
19
  @client = OpenAuth2::Client.new(@config)
data/examples/google.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  require_relative '../lib/open_auth2'
2
2
  require 'json'
3
3
 
4
- ClientId = '948773240950.apps.googleusercontent.com'
5
- ClientSecret = 'MTkeuqOhFTbfRbd27BcEROTl'
4
+ require 'yaml'
5
+ Creds = YAML.load_file('spec/fixtures/creds.yml')
6
+
6
7
  Code = nil
7
8
  AccessToken = 'ya29.AHES6ZRL6dKYn5HvssNQvH15KXTc76jCd9KC6Wfsir74whQ'
8
9
  RefreshToken = '1/2hTXHN9FULj7v_hVOIoyHn6BpOQS6uDOw-xllInXnTU'
@@ -10,9 +11,9 @@ PostEmail = 'senthil196@gmail.com'
10
11
 
11
12
  @config = OpenAuth2::Config.new do |c|
12
13
  c.provider = :google
14
+ c.client_id = Creds['Google']['ClientId']
15
+ c.client_secret = Creds['Google']['ClientSecret']
13
16
  c.code = Code
14
- c.client_id = ClientId
15
- c.client_secret = ClientSecret
16
17
  c.access_token = AccessToken
17
18
  c.refresh_token = RefreshToken
18
19
  c.scope = ['https://www.googleapis.com/auth/calendar']
@@ -38,6 +38,8 @@ module OpenAuth2
38
38
  # name - String/Symbol/Constant.
39
39
  #
40
40
  def provider=(name)
41
+ return unless name
42
+
41
43
  set_provider_vars(name)
42
44
  copy_provider_keys
43
45
  end
@@ -8,11 +8,11 @@ module OpenAuth2
8
8
  class Default
9
9
  def options
10
10
  {
11
- :response_type => 'code',
12
- :access_token_grant_name => 'authorization_code',
13
- :refresh_token_grant_name => 'refresh_token',
14
- :refresh_token_name => :refresh_token,
15
- :scope => [],
11
+ :response_type => 'code',
12
+ :access_token_grant_name => 'authorization_code',
13
+ :refresh_token_grant_name => 'refresh_token',
14
+ :refresh_token_name => :refresh_token,
15
+ :scope => [],
16
16
  }
17
17
  end
18
18
 
@@ -14,11 +14,13 @@ module OpenAuth2
14
14
  end
15
15
 
16
16
  def parse(config, response_body)
17
- access_token = response_body.gsub('access_token=', '')
18
- config.access_token = access_token
19
- config.refresh_token = access_token
17
+ resp = response_body.gsub('access_token=', '')
18
+ resp = resp.split('&expires=')
19
+
20
+ config.access_token = resp[0]
21
+ config.refresh_token = resp[0]
20
22
  config.token_arrived_at = Time.now
21
- config.token_expires_at = "60 days?"
23
+ config.token_expires_at = (Time.now.to_date+60).to_time
22
24
  end
23
25
  end
24
26
  end
@@ -3,18 +3,17 @@ module OpenAuth2
3
3
  class Google
4
4
  def options
5
5
  {
6
- :authorize_url => 'https://accounts.google.com',
7
- :code_url => 'https://accounts.google.com',
8
- :authorize_path => '/o/oauth2/auth',
9
- :redirect_uri => 'http://localhost:9393/google/callback',
10
- :token_path => '/o/oauth2/token',
11
- :endpoint => 'https://www.googleapis.com'
6
+ :authorize_url => 'https://accounts.google.com',
7
+ :code_url => 'https://accounts.google.com',
8
+ :authorize_path => '/o/oauth2/auth',
9
+ :redirect_uri => 'http://localhost:9393/google/callback',
10
+ :token_path => '/o/oauth2/token',
11
+ :endpoint => 'https://www.googleapis.com'
12
12
  }
13
13
  end
14
14
 
15
15
  def parse(config, body)
16
16
  json = JSON.parse(body)
17
-
18
17
  config.access_token = json['access_token']
19
18
  config.token_arrived_at = Time.now
20
19
  config.token_expires_at = Time.now+3600
@@ -59,7 +59,7 @@ module OpenAuth2
59
59
  end
60
60
 
61
61
  def token_expired?
62
- token_expires_at > Time.now
62
+ Time.now > token_expires_at
63
63
  rescue
64
64
  nil
65
65
  end
@@ -1,3 +1,3 @@
1
1
  module OpenAuth2
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
data/lib/open_auth2.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'bundler/setup'
2
+
1
3
  require 'active_support/inflector'
2
4
  require 'faraday'
3
5
  require 'uri'
data/open_auth2.gemspec CHANGED
@@ -34,6 +34,8 @@ Gem::Specification.new do |s|
34
34
  s.add_development_dependency 'vcr', '1.11.3'
35
35
  s.add_development_dependency 'fakeweb', '~> 1.3'
36
36
  s.add_development_dependency 'timecop', '~> 0.3'
37
+ s.add_development_dependency 'pry', '~> 0.9'
38
+ s.add_development_dependency 'capybara'
37
39
 
38
40
  # = MANIFEST =
39
41
  s.files = %w[
@@ -61,7 +63,7 @@ Gem::Specification.new do |s|
61
63
  spec/config_spec.rb
62
64
  spec/facebook/client_spec.rb
63
65
  spec/facebook/token_spec.rb
64
- spec/fixtures/creds.rb
66
+ spec/fixtures/creds.yml
65
67
  spec/fixtures/vcr/fb/access_token.yml
66
68
  spec/fixtures/vcr/fb/cocacola.yml
67
69
  spec/fixtures/vcr/fb/me.yml
@@ -73,6 +75,7 @@ Gem::Specification.new do |s|
73
75
  spec/fixtures/vcr/goog/refresh_token.yml
74
76
  spec/google/client_spec.rb
75
77
  spec/google/token_spec.rb
78
+ spec/reset_tokens.rb
76
79
  spec/spec_helper.rb
77
80
  spec/token_spec.rb
78
81
  ]
data/spec/config_spec.rb CHANGED
@@ -82,6 +82,12 @@ describe OpenAuth2::Config do
82
82
  subject.provider = :unknown
83
83
  end.to raise_error(OpenAuth2::UnknownProvider)
84
84
  end
85
+
86
+ it 'does not set provider if arg is nil' do
87
+ expect do
88
+ subject.provider = nil
89
+ end.to_not change{subject.provider}
90
+ end
85
91
  end
86
92
 
87
93
  let(:overwrite_response_type) do
@@ -3,14 +3,7 @@ require 'spec_helper'
3
3
 
4
4
  describe 'Facebook Client' do
5
5
  let(:config) do
6
- OpenAuth2::Config.new do |c|
7
- c.provider = :facebook
8
- c.client_id = Creds::Facebook::ClientId
9
- c.client_secret = Creds::Facebook::ClientSecret
10
- c.code = Creds::Facebook::Code
11
- c.redirect_uri = 'http://localhost:9393/'
12
- c.scope = ['offline_access', 'publish_stream']
13
- end
6
+ facebook_config
14
7
  end
15
8
 
16
9
  subject { OpenAuth2::Client.new(config) }
@@ -25,7 +18,7 @@ describe 'Facebook Client' do
25
18
 
26
19
  it 'makes private request if #access_token' do
27
20
  subject.configure do |c|
28
- c.access_token = Creds::Facebook::AccessToken
21
+ c.access_token = Creds['Facebook']['AccessToken']
29
22
  end
30
23
 
31
24
  VCR.use_cassette('fb/me') do
@@ -46,7 +39,7 @@ describe 'Facebook Client' do
46
39
 
47
40
  it 'makes private GET request' do
48
41
  VCR.use_cassette('fb/me') do
49
- path = "/me/likes?access_token=#{Creds::Facebook::AccessToken}"
42
+ path = "/me/likes?access_token=#{Creds['Facebook']['AccessToken']}"
50
43
  request = subject.run_request(:verb => :get, :path => path,
51
44
  :body => nil , :header => nil)
52
45
  request.status.should == 200
@@ -57,7 +50,7 @@ describe 'Facebook Client' do
57
50
  context '#post' do
58
51
  before do
59
52
  subject.configure do |c|
60
- c.access_token = Creds::Facebook::AccessToken
53
+ c.access_token = Creds['Facebook']['AccessToken']
61
54
  end
62
55
  end
63
56
 
@@ -65,15 +58,10 @@ describe 'Facebook Client' do
65
58
  "/me/feed?message='From OpenAuth2'"
66
59
  end
67
60
 
68
- let(:body) do
69
- "{\"message\":\"From OpenAuth2\"}"
70
- end
71
-
72
- xit 'makes request' do
61
+ it 'makes request' do
73
62
  VCR.use_cassette('fb/post') do
74
63
  content_type = 'application/json'
75
64
  request = subject.post(:path => post_url,
76
- :body => body,
77
65
  :content_type => content_type)
78
66
  request.status.should == 200
79
67
  end
@@ -3,14 +3,7 @@ require 'spec_helper'
3
3
 
4
4
  describe 'Facebook Token' do
5
5
  let(:config) do
6
- OpenAuth2::Config.new do |c|
7
- c.provider = :facebook
8
- c.client_id = Creds::Facebook::ClientId
9
- c.client_secret = Creds::Facebook::ClientSecret
10
- c.code = Creds::Facebook::Code
11
- c.redirect_uri = 'http://localhost:9393/'
12
- c.scope = ['offline_access', 'publish_stream']
13
- end
6
+ facebook_config
14
7
  end
15
8
 
16
9
  subject do
@@ -19,13 +12,13 @@ describe 'Facebook Token' do
19
12
 
20
13
  context '#build_code_url' do
21
14
  it 'returns url' do
22
- url = "https://www.facebook.com/dialog/oauth?response_type=code&client_id=225722397503003&redirect_uri=http%3A%2F%2Flocalhost%3A9393%2F&scope=offline_access%2Cpublish_stream"
15
+ url = "https://www.facebook.com/dialog/oauth?response_type=code&client_id=369754433115833&redirect_uri=http%3A%2F%2Flocalhost%3A9393%2F&scope=offline_access%2Cpublish_stream"
23
16
 
24
17
  subject.build_code_url.should == url
25
18
  end
26
19
 
27
20
  it 'accepts params' do
28
- url = "https://www.facebook.com/dialog/oauth?response_type=code&client_id=225722397503003&redirect_uri=http%3A%2F%2Flocalhost%3A9393%2F&scope=publish_stream"
21
+ url = "https://www.facebook.com/dialog/oauth?response_type=code&client_id=369754433115833&redirect_uri=http%3A%2F%2Flocalhost%3A9393%2F&scope=publish_stream"
29
22
 
30
23
  subject.build_code_url(:scope => 'publish_stream').should == url
31
24
  end
@@ -53,26 +46,30 @@ describe 'Facebook Token' do
53
46
  end
54
47
 
55
48
  it 'sets #access_token' do
56
- subject.access_token.should == Creds::Facebook::AccessToken
49
+ subject.access_token.should == Creds['Facebook']['AccessToken']
57
50
  end
58
51
 
59
52
  it 'sets #refresh_token' do
60
- subject.refresh_token.should == Creds::Facebook::AccessToken
53
+ subject.refresh_token.should == Creds['Facebook']['AccessToken']
61
54
  end
62
55
 
63
56
  it 'sets #token_arrived_at' do
64
57
  subject.token_arrived_at.should == time
65
58
  end
66
59
 
60
+ it 'sets #token_expires_at' do
61
+ subject.token_expires_at.to_s.should == '2013-02-19 00:00:00 -0500'
62
+ end
63
+
67
64
  it 'returns nil for #token_expired?' do
68
- subject.token_expired?.should == nil
65
+ subject.token_expired?.should == false
69
66
  end
70
67
  end
71
68
 
72
69
  context '#refresh' do
73
70
  let(:refresh_token) do
74
71
  config.configure do |c|
75
- c.refresh_token = Creds::Facebook::AccessToken
72
+ c.refresh_token = Creds['Facebook']['AccessToken']
76
73
  end
77
74
 
78
75
  VCR.use_cassette('fb/refresh_token') do
@@ -86,7 +83,7 @@ describe 'Facebook Token' do
86
83
 
87
84
  it 'sets new #access_token' do
88
85
  refresh_token
89
- subject.access_token.should == Creds::Facebook::AccessToken
86
+ subject.access_token.should == Creds['Facebook']['AccessToken']
90
87
  end
91
88
  end
92
89
  end
@@ -0,0 +1,13 @@
1
+ ---
2
+ Facebook:
3
+ ClientId: 369754433115833
4
+ ClientSecret: 117d2e4932154c8c408d3d170c81c2dc
5
+ Code: AQDDc5Ul1RBTTlsaWBGyHVN7FBhBvBAzjrr-qEcwSL7qtJizos5JAm9-6fCZo10Uxp3g4yhKcx9xArw-e1M9DzS0spBtlztBq9Aeus3cgM7U9UhmwY4OEim0EmrrhJGzy_LXEIUfaCwR7ds2M2DxkbWY7ZPHkTWbbpImonaq7SwiO43cKot1-UGCInZyaLqjqCzO_IP-M1phQ8zv6LF7ohnS
6
+ AccessToken: AAAFQSimj1rkBAEEzYjDGNyIag6EZBSwYHl2jXDJlmIdAjc3nlXpkajStjqhPyrSLZBUQ8sfV6H40LktIa1zvAILHZCZBgJgPowtiJ2K9lQZDZD
7
+ Google:
8
+ ClientId: 77848792642.apps.googleusercontent.com
9
+ ClientSecret: 8oPMGGpIzZLwaW89pIcx78mB
10
+ Code: 4/2jmx49tYiahM2MzvM_W75S7Zd92i
11
+ AccessToken: ya29.AHES6ZRXhZRQLYkdqVoHz9qxzTkNVhElBAQitCdJq816PQ
12
+ RefreshToken: 1/gUwId5-5ZHpM5G3Qooj67RDQI07zgzlJQwPjErLRzEg
13
+ NewAccessToken: ya29.AHES6ZR2V9Y9vZnTC4YFHChTetjwML1mDLZRSmiBx-XT9g
@@ -3,7 +3,7 @@
3
3
  request: !ruby/struct:VCR::Request
4
4
  method: :post
5
5
  uri: https://graph.facebook.com:443/oauth/access_token
6
- body:
6
+ body: client_id=369754433115833&client_secret=117d2e4932154c8c408d3d170c81c2dc&code=AQDGiFQqdI8cQjIDO9ynqQ-TS6srenjl9QgU8cAq_aeMuZ2B2aLx0B2sn57t3HOuhJSVYW4sdq0Wuf6Jg-jkXrY_ooKvhrBiTE5wHo-2tigUBvtnqHByMI2Z1R92CiVkAPMrLSLuNCWAzWH_EDAD6PcxGRjOw2-YNMC0Dls4dZ2FNbw4xmqPa9p2Nmvvjs2krgqhHVCSmUfFY0wZ-jfEfGdH&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost%3A9393%2F
7
7
  headers:
8
8
  content-type:
9
9
  - application/x-www-form-urlencoded
@@ -25,12 +25,12 @@
25
25
  pragma:
26
26
  - no-cache
27
27
  x-fb-rev:
28
- - '514925'
28
+ - '688120'
29
29
  x-fb-debug:
30
- - P9I9NADR2jvZfeNcVamI71Cay4CB4KBqBXQYcJ4YYws=
30
+ - ej1HI0QsiUnSnsYsICzam4rhNvDx4SLPbjuOOZi9ohE=
31
31
  date:
32
- - Sat, 25 Feb 2012 21:49:01 GMT
32
+ - Thu, 06 Dec 2012 19:07:26 GMT
33
33
  content-length:
34
- - '127'
35
- body: access_token=AAADNSxdSLhsBALUJwhyMDYVTCV07ZAUyXIGwm2Bb9G5oudfZCYz2TcZB23ZABbFKTShb6JZC0aUVEsNfTMTRrqVWIrVyxNf4pElZAZCUWnd9QZDZD
34
+ - '140'
35
+ body: access_token=AAAFQSimj1rkBAEEzYjDGNyIag6EZBSwYHl2jXDJlmIdAjc3nlXpkajStjqhPyrSLZBUQ8sfV6H40LktIa1zvAILHZCZBgJgPowtiJ2K9lQZDZD&expires=5178908
36
36
  http_version: '1.1'
@@ -24,7 +24,7 @@
24
24
  dGV4dC9qYXZhc2NyaXB0OyBjaGFyc2V0PVVURi04
25
25
  !binary "ZXRhZw==":
26
26
  - !binary |-
27
- IjRkNDBlYzNhZDNjZjk0NmU2ZTdkYTFkYzM4MjFkZjJjZWI0N2FmYzYi
27
+ IjY2MzE1NDM5MGUyNTVjZDBiZjdmNzRhMDQzZGY4MDQ3MDMwNzY5Y2Ii
28
28
  !binary "ZXhwaXJlcw==":
29
29
  - !binary |-
30
30
  U2F0LCAwMSBKYW4gMjAwMCAwMDowMDowMCBHTVQ=
@@ -33,36 +33,37 @@
33
33
  bm8tY2FjaGU=
34
34
  !binary "eC1mYi1yZXY=":
35
35
  - !binary |-
36
- NTE0OTI1
36
+ Njg4MTIw
37
37
  !binary "Y29udGVudC1lbmNvZGluZw==":
38
38
  - !binary |-
39
39
  Z3ppcA==
40
40
  !binary "eC1mYi1kZWJ1Zw==":
41
41
  - !binary |-
42
- dzAzV3B1V0tkS1BiT244ZEcxM3dkZEZhMG9kd3R5Y2FvaUI1blUwMVViTT0=
42
+ S0FEa1hoL203R0xxTGZieFVadEJLNS82VHZKcVFWS2FNMkVPUmVrcGFFOD0=
43
43
  !binary "ZGF0ZQ==":
44
44
  - !binary |-
45
- U2F0LCAyNSBGZWIgMjAxMiAyMjowMjo0MyBHTVQ=
45
+ VGh1LCAwNiBEZWMgMjAxMiAxOTowNzoyNSBHTVQ=
46
46
  !binary "Y29udGVudC1sZW5ndGg=":
47
47
  - !binary |-
48
- NzIx
48
+ Nzk4
49
49
  body: !binary |-
50
- H4sIAAAAAAAAA3VTTY/TMBD9K6NcuGTThrRN2htaBILTSsCtUjVx3MTUsS3b
51
- 2RAh/jvP7cLuCpFD4tjjeR8z8zNTXXbINut6v6vWTbXeZnlmeJTYvLe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
  request: !ruby/struct:VCR::Request
4
4
  method: :get
5
- uri: https://graph.facebook.com:443/me/likes?access_token=AAADNSxdSLhsBALUJwhyMDYVTCV07ZAUyXIGwm2Bb9G5oudfZCYz2TcZB23ZABbFKTShb6JZC0aUVEsNfTMTRrqVWIrVyxNf4pElZAZCUWnd9QZDZD
5
+ uri: https://graph.facebook.com:443/me/likes?access_token=AAAFQSimj1rkBAEEzYjDGNyIag6EZBSwYHl2jXDJlmIdAjc3nlXpkajStjqhPyrSLZBUQ8sfV6H40LktIa1zvAILHZCZBgJgPowtiJ2K9lQZDZD
6
6
  body:
7
7
  headers:
8
8
  accept-encoding:
@@ -19,18 +19,18 @@
19
19
  content-type:
20
20
  - text/javascript; charset=UTF-8
21
21
  etag:
22
- - ! '"c60f2e60a5df83da5585ebda43b554fcf98a0486"'
22
+ - ! '"7363db52a3026cdc124c3fac4cbe7422bfb540c9"'
23
23
  expires:
24
24
  - Sat, 01 Jan 2000 00:00:00 GMT
25
25
  pragma:
26
26
  - no-cache
27
27
  x-fb-rev:
28
- - '514925'
28
+ - '688120'
29
29
  x-fb-debug:
30
- - KrTg1q4nx3Apmj1vpbKXn0k7W3EmEsfq0rt2uQLSJ/g=
30
+ - tx+4BRudPUdklffLDIYB4FQqquI+4SULntIz9XFwlsE=
31
31
  date:
32
- - Sat, 25 Feb 2012 22:08:52 GMT
32
+ - Thu, 06 Dec 2012 19:07:25 GMT
33
33
  content-length:
34
- - '370'
35
- body: ! '{"data":[{"name":"EmiBalbuena.com","category":"Personal website","id":"197230593668050","created_time":"2011-10-06T22:00:02+0000"}],"paging":{"next":"https:\/\/graph.facebook.com\/me\/likes?access_token=AAADNSxdSLhsBALUJwhyMDYVTCV07ZAUyXIGwm2Bb9G5oudfZCYz2TcZB23ZABbFKTShb6JZC0aUVEsNfTMTRrqVWIrVyxNf4pElZAZCUWnd9QZDZD&limit=5000&offset=5000&__after_id=197230593668050"}}'
34
+ - '380'
35
+ body: ! '{"data":[{"category":"Personal website","name":"EmiBalbuena.com","id":"197230593668050","created_time":"2011-10-06T22:00:02+0000"}],"paging":{"next":"https:\/\/graph.facebook.com\/100002930317357\/likes?access_token=AAAFQSimj1rkBAEEzYjDGNyIag6EZBSwYHl2jXDJlmIdAjc3nlXpkajStjqhPyrSLZBUQ8sfV6H40LktIa1zvAILHZCZBgJgPowtiJ2K9lQZDZD&limit=5000&offset=5000&__after_id=197230593668050"}}'
36
36
  http_version: '1.1'
@@ -2,11 +2,13 @@
2
2
  - !ruby/struct:VCR::HTTPInteraction
3
3
  request: !ruby/struct:VCR::Request
4
4
  method: :post
5
- uri: https://graph.facebook.com:443/me/feed?message=%27From%20OpenAuth2%27&access_token=AAADNSxdSLhsBALUJwhyMDYVTCV07ZAUyXIGwm2Bb9G5oudfZCYz2TcZB23ZABbFKTShb6JZC0aUVEsNfTMTRrqVWIrVyxNf4pElZAZCUWnd9QZDZD
5
+ uri: https://graph.facebook.com:443/me/feed?message=%27From+OpenAuth2%27&access_token=AAAFQSimj1rkBAEEzYjDGNyIag6EZBSwYHl2jXDJlmIdAjc3nlXpkajStjqhPyrSLZBUQ8sfV6H40LktIa1zvAILHZCZBgJgPowtiJ2K9lQZDZD
6
6
  body:
7
7
  headers:
8
8
  content-type:
9
9
  - application/json
10
+ content-length:
11
+ - '0'
10
12
  response: !ruby/struct:VCR::Response
11
13
  status: !ruby/struct:VCR::ResponseStatus
12
14
  code: 200
@@ -23,12 +25,12 @@
23
25
  pragma:
24
26
  - no-cache
25
27
  x-fb-rev:
26
- - '518267'
28
+ - '688120'
27
29
  x-fb-debug:
28
- - 1+GpoD6kWif2JDnTaD/XeITjokumXXb6BbGmwAciEiA=
30
+ - 5EaMjzPReHxh3EhmzC812yk4xK8NCyEGtP0B61IZ/AE=
29
31
  date:
30
- - Sat, 03 Mar 2012 01:37:49 GMT
32
+ - Thu, 06 Dec 2012 19:07:26 GMT
31
33
  content-length:
32
34
  - '40'
33
- body: ! '{"id":"100002930317357_200068986767444"}'
35
+ body: ! '{"id":"100002930317357_327490434025298"}'
34
36
  http_version: '1.1'
@@ -3,7 +3,7 @@
3
3
  request: !ruby/struct:VCR::Request
4
4
  method: :post
5
5
  uri: https://graph.facebook.com:443/oauth/access_token
6
- body:
6
+ body: client_id=369754433115833&client_secret=117d2e4932154c8c408d3d170c81c2dc&grant_type=fb_exchange_token&fb_exchange_token=AAAFQSimj1rkBAEEzYjDGNyIag6EZBSwYHl2jXDJlmIdAjc3nlXpkajStjqhPyrSLZBUQ8sfV6H40LktIa1zvAILHZCZBgJgPowtiJ2K9lQZDZD
7
7
  headers:
8
8
  content-type:
9
9
  - application/x-www-form-urlencoded
@@ -25,12 +25,12 @@
25
25
  pragma:
26
26
  - no-cache
27
27
  x-fb-rev:
28
- - '514925'
28
+ - '688120'
29
29
  x-fb-debug:
30
- - oAZnBNFMltYkzFalaO5iH4uo5Jcc0fnhK7QFGrcMfvI=
30
+ - 1FSF+P+Q7JKdczlPGLIFmGK88XtusThF5BENI6qmdiU=
31
31
  date:
32
- - Sat, 25 Feb 2012 21:56:05 GMT
32
+ - Thu, 06 Dec 2012 19:07:27 GMT
33
33
  content-length:
34
- - '127'
35
- body: access_token=AAADNSxdSLhsBALUJwhyMDYVTCV07ZAUyXIGwm2Bb9G5oudfZCYz2TcZB23ZABbFKTShb6JZC0aUVEsNfTMTRrqVWIrVyxNf4pElZAZCUWnd9QZDZD
34
+ - '140'
35
+ body: access_token=AAAFQSimj1rkBAEEzYjDGNyIag6EZBSwYHl2jXDJlmIdAjc3nlXpkajStjqhPyrSLZBUQ8sfV6H40LktIa1zvAILHZCZBgJgPowtiJ2K9lQZDZD&expires=5178907
36
36
  http_version: '1.1'
@@ -3,13 +3,7 @@ require 'spec_helper'
3
3
 
4
4
  describe 'Google Client' do
5
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
6
+ google_config
13
7
  end
14
8
 
15
9
  subject { OpenAuth2::Client.new(config) }
@@ -45,7 +39,7 @@ describe 'Google Client' do
45
39
 
46
40
  it 'POST request via #run_request' do
47
41
  header = {"Content-Type" => "application/json"}
48
- full_url = "#{post_url}?access_token=#{Creds::Google::AccessToken}"
42
+ full_url = "#{post_url}?access_token=#{Creds['Google']['AccessToken']}"
49
43
 
50
44
  VCR.use_cassette('goog/post') do
51
45
  request = subject.run_request(:verb => :post,
@@ -3,14 +3,7 @@ require 'spec_helper'
3
3
 
4
4
  describe 'Google Token' do
5
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
6
+ google_config
14
7
  end
15
8
 
16
9
  subject do
@@ -48,11 +41,11 @@ describe 'Google Token' do
48
41
  end
49
42
 
50
43
  it 'sets #access_token' do
51
- subject.access_token.should == Creds::Google::AccessToken
44
+ subject.access_token.should == Creds['Google']['AccessToken']
52
45
  end
53
46
 
54
47
  it 'sets #refresh_token' do
55
- subject.refresh_token.should == Creds::Google::RefreshToken
48
+ subject.refresh_token.should == Creds['Google']['RefreshToken']
56
49
  end
57
50
 
58
51
  it 'sets #token_arrived_at' do
@@ -60,14 +53,14 @@ describe 'Google Token' do
60
53
  end
61
54
 
62
55
  it 'returns false for #token_expired?' do
63
- subject.token_expired?.should == true
56
+ subject.token_expired?.should == false
64
57
  end
65
58
  end
66
59
 
67
60
  context '#refresh' do
68
61
  let(:refresh_token) do
69
62
  config.configure do |c|
70
- c.refresh_token = Creds::Google::RefreshToken
63
+ c.refresh_token = Creds['Google']['RefreshToken']
71
64
  end
72
65
 
73
66
  VCR.use_cassette('goog/refresh_token') do
@@ -81,7 +74,7 @@ describe 'Google Token' do
81
74
 
82
75
  it 'sets new #access_token' do
83
76
  refresh_token
84
- subject.access_token.should == Creds::Google::NewAccessToken
77
+ subject.access_token.should == Creds['Google']['NewAccessToken']
85
78
  end
86
79
  end
87
80
  end
@@ -0,0 +1,51 @@
1
+ if ENV['RESET_TOKENS']
2
+ require_relative '../lib/open_auth2'
3
+
4
+ require 'capybara/rspec'
5
+ require 'pry'
6
+
7
+ require 'yaml'
8
+ Creds = YAML.load_file('spec/fixtures/creds.yml')
9
+
10
+ describe "ResetToken", :js => true do
11
+ include Capybara::DSL
12
+
13
+ it 'Facebook' do
14
+ config = OpenAuth2::Config.new do |c|
15
+ c.provider = :facebook
16
+ c.client_id = Creds['Facebook']['ClientId']
17
+ c.client_secret = Creds['Facebook']['ClientSecret']
18
+ c.code = Creds['Facebook']['Code']
19
+ c.access_token = Creds['Facebook']['AccessToken']
20
+ c.redirect_uri = 'http://localhost:9393/'
21
+ c.scope = ['publish_stream']
22
+ end
23
+
24
+ client = OpenAuth2::Client.new(config)
25
+ url = client.build_code_url
26
+ token = client.token
27
+
28
+ response = visit('https://www.facebook.com/')
29
+ fill_in :email, :with => ENV['USER']
30
+ fill_in :pass, :with => ENV['PASS']
31
+ click_button 'Log In'
32
+
33
+ response = visit(url)
34
+ code = current_url.split('=')[1].split('#')[0]
35
+
36
+ config.code = code
37
+ token.get
38
+ access_token = config.access_token
39
+
40
+ response = visit(url)
41
+ code = current_url.split('=')[1].split('#')[0]
42
+
43
+ Creds['Facebook']['Code'] = code
44
+ Creds['Facebook']['AccessToken'] = access_token
45
+
46
+ File.open('spec/fixtures/creds.yml', 'w') do |f|
47
+ f.puts(YAML.dump(Creds))
48
+ end
49
+ end
50
+ end
51
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,34 @@
1
- if ENV['COVERAGE']
2
- require 'simplecov'
3
- SimpleCov.start
4
- end
5
-
6
1
  require 'vcr'
7
2
  require 'timecop'
8
- require 'fixtures/creds'
9
3
 
10
4
  VCR.config do |c|
11
5
  c.cassette_library_dir = 'spec/fixtures/vcr'
12
6
  c.stub_with :fakeweb
13
7
  end
8
+
9
+ require 'yaml'
10
+ Creds = YAML.load_file('spec/fixtures/creds.yml')
11
+
12
+ def facebook_config
13
+ OpenAuth2::Config.new do |c|
14
+ c.provider = :facebook
15
+ c.client_id = Creds['Facebook']['ClientId']
16
+ c.client_secret = Creds['Facebook']['ClientSecret']
17
+ c.code = Creds['Facebook']['Code']
18
+ c.redirect_uri = 'http://localhost:9393/'
19
+ c.scope = ['offline_access', 'publish_stream']
20
+ end
21
+ end
22
+
23
+ def google_config
24
+ OpenAuth2::Config.new do |c|
25
+ c.provider = :google
26
+ c.client_id = Creds['Google']['ClientId']
27
+ c.client_secret = Creds['Google']['ClientSecret']
28
+ c.access_token = Creds['Google']['AccessToken']
29
+ c.refresh_token = Creds['Google']['RefreshToken']
30
+ c.redirect_uri = 'http://localhost:9393/google/callback'
31
+ c.path_prefix = '/calendar/v3'
32
+ c.scope = ['https://www.googleapis.com/auth/calendar']
33
+ end
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_auth2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-22 00:00:00.000000000 Z
12
+ date: 2012-12-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -139,6 +139,38 @@ dependencies:
139
139
  - - ~>
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0.3'
142
+ - !ruby/object:Gem::Dependency
143
+ name: pry
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: '0.9'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: '0.9'
158
+ - !ruby/object:Gem::Dependency
159
+ name: capybara
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
142
174
  description: OpenAuth2 is a simple OAuth2 client.
143
175
  email:
144
176
  - me@sent-hil.com
@@ -170,7 +202,7 @@ files:
170
202
  - spec/config_spec.rb
171
203
  - spec/facebook/client_spec.rb
172
204
  - spec/facebook/token_spec.rb
173
- - spec/fixtures/creds.rb
205
+ - spec/fixtures/creds.yml
174
206
  - spec/fixtures/vcr/fb/access_token.yml
175
207
  - spec/fixtures/vcr/fb/cocacola.yml
176
208
  - spec/fixtures/vcr/fb/me.yml
@@ -182,6 +214,7 @@ files:
182
214
  - spec/fixtures/vcr/goog/refresh_token.yml
183
215
  - spec/google/client_spec.rb
184
216
  - spec/google/token_spec.rb
217
+ - spec/reset_tokens.rb
185
218
  - spec/spec_helper.rb
186
219
  - spec/token_spec.rb
187
220
  homepage: https://github.com/sent-hil/OpenAuth2
@@ -196,18 +229,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
196
229
  - - ! '>='
197
230
  - !ruby/object:Gem::Version
198
231
  version: '0'
199
- segments:
200
- - 0
201
- hash: 1597151657867498836
202
232
  required_rubygems_version: !ruby/object:Gem::Requirement
203
233
  none: false
204
234
  requirements:
205
235
  - - ! '>='
206
236
  - !ruby/object:Gem::Version
207
237
  version: '0'
208
- segments:
209
- - 0
210
- hash: 1597151657867498836
211
238
  requirements: []
212
239
  rubyforge_project: OpenAuth2
213
240
  rubygems_version: 1.8.24
@@ -220,7 +247,7 @@ test_files:
220
247
  - spec/config_spec.rb
221
248
  - spec/facebook/client_spec.rb
222
249
  - spec/facebook/token_spec.rb
223
- - spec/fixtures/creds.rb
250
+ - spec/fixtures/creds.yml
224
251
  - spec/fixtures/vcr/fb/access_token.yml
225
252
  - spec/fixtures/vcr/fb/cocacola.yml
226
253
  - spec/fixtures/vcr/fb/me.yml
@@ -232,5 +259,7 @@ test_files:
232
259
  - spec/fixtures/vcr/goog/refresh_token.yml
233
260
  - spec/google/client_spec.rb
234
261
  - spec/google/token_spec.rb
262
+ - spec/reset_tokens.rb
235
263
  - spec/spec_helper.rb
236
264
  - spec/token_spec.rb
265
+ has_rdoc:
@@ -1,18 +0,0 @@
1
- module Creds
2
- module Facebook
3
- ClientId = '225722397503003'
4
- ClientSecret = 'c5ede842aaa3a3f377ca56464acc37fe'
5
- Code = 'AQB2Z6BvTFr9_VhMiP6eVLCIxUb26ym6mjuie4h2rbxGyN3QjMzVB_mozUfTCqJpH4Ta7MeRRxF7-sWQ9wdwR6iic6Mbb5hTtg1bj2nHBo85iCPfel4q-Blf3mp8xv0aKGw6mgYVMBfW1MhJC4qDgKE8pTgi7230Vgthjs7LWKBIcDJtonjUAFldhcKVrPZSx90'
6
- AccessToken = 'AAADNSxdSLhsBALUJwhyMDYVTCV07ZAUyXIGwm2Bb9G5oudfZCYz2TcZB23ZABbFKTShb6JZC0aUVEsNfTMTRrqVWIrVyxNf4pElZAZCUWnd9QZDZD'
7
- end
8
-
9
- module Google
10
- ClientId = '77848792642.apps.googleusercontent.com'
11
- ClientSecret = '8oPMGGpIzZLwaW89pIcx78mB'
12
- Code = '4/2jmx49tYiahM2MzvM_W75S7Zd92i'
13
- AccessToken = 'ya29.AHES6ZRXhZRQLYkdqVoHz9qxzTkNVhElBAQitCdJq816PQ'
14
- RefreshToken = '1/gUwId5-5ZHpM5G3Qooj67RDQI07zgzlJQwPjErLRzEg'
15
-
16
- NewAccessToken = 'ya29.AHES6ZR2V9Y9vZnTC4YFHChTetjwML1mDLZRSmiBx-XT9g'
17
- end
18
- end