OpenAuth2 0.0.1

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.
@@ -0,0 +1,82 @@
1
+ require 'open_auth2'
2
+ require 'spec_helper'
3
+
4
+ describe 'Facebook Client' do
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
14
+ end
15
+
16
+ subject { OpenAuth2::Client.new(config) }
17
+
18
+ context '#get' do
19
+ it 'makes public request' do
20
+ VCR.use_cassette('fb/cocacola') do
21
+ request = subject.get(:path => '/cocacola')
22
+ request.status.should == 200
23
+ end
24
+ end
25
+
26
+ it 'makes private request if #access_token' do
27
+ subject.configure do |c|
28
+ c.access_token = Creds::Facebook::AccessToken
29
+ end
30
+
31
+ VCR.use_cassette('fb/me') do
32
+ request = subject.get(:path => '/me/likes')
33
+ request.status.should == 200
34
+ end
35
+ end
36
+ end
37
+
38
+ context '#run_request' do
39
+ it 'makes public GET request' do
40
+ VCR.use_cassette('fb/cocacola') do
41
+ request = subject.run_request(:verb => :get, :path => '/cocacola',
42
+ :body => nil , :header => nil)
43
+ request.status.should == 200
44
+ end
45
+ end
46
+
47
+ it 'makes private GET request' do
48
+ VCR.use_cassette('fb/me') do
49
+ path = "/me/likes?access_token=#{Creds::Facebook::AccessToken}"
50
+ request = subject.run_request(:verb => :get, :path => path,
51
+ :body => nil , :header => nil)
52
+ request.status.should == 200
53
+ end
54
+ end
55
+ end
56
+
57
+ context '#post' do
58
+ before do
59
+ subject.configure do |c|
60
+ c.access_token = Creds::Facebook::AccessToken
61
+ end
62
+ end
63
+
64
+ let(:post_url) do
65
+ "/me/feed?message='From OpenAuth2'"
66
+ end
67
+
68
+ let(:body) do
69
+ "{\"message\":\"From OpenAuth2\"}"
70
+ end
71
+
72
+ it 'makes request' do
73
+ VCR.use_cassette('fb/post') do
74
+ content_type = 'application/json'
75
+ request = subject.post(:path => post_url,
76
+ :body => body,
77
+ :content_type => content_type)
78
+ request.status.should == 200
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,92 @@
1
+ require 'open_auth2'
2
+ require 'spec_helper'
3
+
4
+ describe 'Facebook Token' do
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
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://www.facebook.com/dialog/oauth?response_type=code&client_id=225722397503003&redirect_uri=http%3A%2F%2Flocalhost%3A9393%2F&scope=offline_access%2Cpublish_stream"
23
+
24
+ subject.build_code_url.should == url
25
+ end
26
+
27
+ 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"
29
+
30
+ subject.build_code_url(:scope => 'publish_stream').should == url
31
+ end
32
+ end
33
+
34
+ context '#get' do
35
+ let(:get_token) do
36
+ VCR.use_cassette('fb/access_token') do
37
+ subject.get
38
+ end
39
+ end
40
+
41
+ let(:time) do
42
+ Time.local(2012, 12, 21)
43
+ end
44
+
45
+ before do
46
+ Timecop.freeze(time) do
47
+ get_token
48
+ end
49
+ end
50
+
51
+ it 'requests OAuth server for access token' do
52
+ get_token.status.should == 200
53
+ end
54
+
55
+ it 'sets #access_token' do
56
+ subject.access_token.should == Creds::Facebook::AccessToken
57
+ end
58
+
59
+ it 'sets #refresh_token' do
60
+ subject.refresh_token.should == Creds::Facebook::AccessToken
61
+ end
62
+
63
+ it 'sets #token_arrived_at' do
64
+ subject.token_arrived_at.should == time
65
+ end
66
+
67
+ it 'returns nil for #token_expired?' do
68
+ subject.token_expired?.should == nil
69
+ end
70
+ end
71
+
72
+ context '#refresh' do
73
+ let(:refresh_token) do
74
+ config.configure do |c|
75
+ c.refresh_token = Creds::Facebook::AccessToken
76
+ end
77
+
78
+ VCR.use_cassette('fb/refresh_token') do
79
+ subject.refresh
80
+ end
81
+ end
82
+
83
+ it 'requests OAuth server to refresh access token' do
84
+ refresh_token.status.should == 200
85
+ end
86
+
87
+ it 'sets new #access_token' do
88
+ refresh_token
89
+ subject.access_token.should == Creds::Facebook::AccessToken
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,18 @@
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
@@ -0,0 +1,36 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: https://graph.facebook.com:443/oauth/access_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
+ access-control-allow-origin:
18
+ - ! '*'
19
+ cache-control:
20
+ - private, no-cache, no-store, must-revalidate
21
+ content-type:
22
+ - text/plain; charset=UTF-8
23
+ expires:
24
+ - Sat, 01 Jan 2000 00:00:00 GMT
25
+ pragma:
26
+ - no-cache
27
+ x-fb-rev:
28
+ - '514925'
29
+ x-fb-debug:
30
+ - P9I9NADR2jvZfeNcVamI71Cay4CB4KBqBXQYcJ4YYws=
31
+ date:
32
+ - Sat, 25 Feb 2012 21:49:01 GMT
33
+ content-length:
34
+ - '127'
35
+ body: access_token=AAADNSxdSLhsBALUJwhyMDYVTCV07ZAUyXIGwm2Bb9G5oudfZCYz2TcZB23ZABbFKTShb6JZC0aUVEsNfTMTRrqVWIrVyxNf4pElZAZCUWnd9QZDZD
36
+ http_version: '1.1'
@@ -0,0 +1,68 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: https://graph.facebook.com:443/cocacola
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: !binary |-
14
+ T0s=
15
+ headers:
16
+ !binary "YWNjZXNzLWNvbnRyb2wtYWxsb3ctb3JpZ2lu":
17
+ - !binary |-
18
+ Kg==
19
+ !binary "Y2FjaGUtY29udHJvbA==":
20
+ - !binary |-
21
+ cHJpdmF0ZSwgbm8tY2FjaGUsIG5vLXN0b3JlLCBtdXN0LXJldmFsaWRhdGU=
22
+ !binary "Y29udGVudC10eXBl":
23
+ - !binary |-
24
+ dGV4dC9qYXZhc2NyaXB0OyBjaGFyc2V0PVVURi04
25
+ !binary "ZXRhZw==":
26
+ - !binary |-
27
+ IjRkNDBlYzNhZDNjZjk0NmU2ZTdkYTFkYzM4MjFkZjJjZWI0N2FmYzYi
28
+ !binary "ZXhwaXJlcw==":
29
+ - !binary |-
30
+ U2F0LCAwMSBKYW4gMjAwMCAwMDowMDowMCBHTVQ=
31
+ !binary "cHJhZ21h":
32
+ - !binary |-
33
+ bm8tY2FjaGU=
34
+ !binary "eC1mYi1yZXY=":
35
+ - !binary |-
36
+ NTE0OTI1
37
+ !binary "Y29udGVudC1lbmNvZGluZw==":
38
+ - !binary |-
39
+ Z3ppcA==
40
+ !binary "eC1mYi1kZWJ1Zw==":
41
+ - !binary |-
42
+ dzAzV3B1V0tkS1BiT244ZEcxM3dkZEZhMG9kd3R5Y2FvaUI1blUwMVViTT0=
43
+ !binary "ZGF0ZQ==":
44
+ - !binary |-
45
+ U2F0LCAyNSBGZWIgMjAxMiAyMjowMjo0MyBHTVQ=
46
+ !binary "Y29udGVudC1sZW5ndGg=":
47
+ - !binary |-
48
+ NzIx
49
+ body: !binary |-
50
+ H4sIAAAAAAAAA3VTTY/TMBD9K6NcuGTThrRN2htaBILTSsCtUjVx3MTUsS3b
51
+ 2RAh/jvP7cLuCpFD4tjjeR8z8zNTXXbINut6v6vWTbXeZnlmeJTYvLeC7+6t
52
+ Zmw5JeLk0+4QozscV8eV8/astCz4Upxb0ZnCyHhcDU/bd3y5C0ZsjqtyWzf7
53
+ +vQC4lSWTV2Xb6uyPoXiu+sBoJW5vMw+z3NxZiFbay+FsONxJRIdcaOj1UWG
54
+ 7FDtm3Ld7PZ5JjjK3voFKT5Y2x1XrXyUnntE5ZkKJze1WoVBQmz0k8yzWbZB
55
+ xVeCEuRfkISJq1OQ/smOl/hnO5kuJcvKptkhrpNBeOWisiY55yX4dKQMpfP0
56
+ fRc1m8g5fZTW9wqLdqH3vqDPdjD0paAHObbSR2ty+ms8zRzorHyIZM9n6ZES
57
+ G0wJPjKy/lFJHOkzC9u+CfQwsB9ZLAlgVD+U6V8kDIufHM0qDiTYt9Zcec54
58
+ g8rRHM1rbIcD86ykzsnLXgVE/6ESPXdyZH+5id1XxKZL0FhvScWrhFYmFsHq
59
+ qyWpMguFiNzXYGTzKqJ46TAOkr4ZVKajLykiFPTpmnif01ecPfO7t6NjA5my
60
+ Z0Nnz0YMKuBea2NEO/VkHVoglST8J/NrwaPqBxg9S9AOZL3qFW5G+y8nFG+K
61
+ 1yhn3aQZ9BcaIHSEGUk0ekwvNBkFqYF1QV9tx0tOi53gO9gq6H6WAt2PyseJ
62
+ NW7d7HHsU9Gv2LP1uivQZdzaKaK/Xhvx4WlM6AH9Tio1CMZES5GkpxxA9fAb
63
+ imSgMNg5mYMPOWmdlvDOjsQ+9fQzHvQ8ShqkdrB05EuyHi9lYMg8oN8gE1gx
64
+ CUvcNMbz1v4/M41VnDpM111VFU2526N+TYUnxZn+6bDcrotm02w2a4Ts6l9p
65
+ jM3J2QCNtykVgxQXVCE71E2eRdb46U9XG04iDUF22O6adVX/+g1sWrgEyQQA
66
+ AA==
67
+ http_version: !binary |-
68
+ MS4x
@@ -0,0 +1,36 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: https://graph.facebook.com:443/me/likes?access_token=AAADNSxdSLhsBALUJwhyMDYVTCV07ZAUyXIGwm2Bb9G5oudfZCYz2TcZB23ZABbFKTShb6JZC0aUVEsNfTMTRrqVWIrVyxNf4pElZAZCUWnd9QZDZD
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
+ access-control-allow-origin:
16
+ - ! '*'
17
+ cache-control:
18
+ - private, no-cache, no-store, must-revalidate
19
+ content-type:
20
+ - text/javascript; charset=UTF-8
21
+ etag:
22
+ - ! '"c60f2e60a5df83da5585ebda43b554fcf98a0486"'
23
+ expires:
24
+ - Sat, 01 Jan 2000 00:00:00 GMT
25
+ pragma:
26
+ - no-cache
27
+ x-fb-rev:
28
+ - '514925'
29
+ x-fb-debug:
30
+ - KrTg1q4nx3Apmj1vpbKXn0k7W3EmEsfq0rt2uQLSJ/g=
31
+ date:
32
+ - Sat, 25 Feb 2012 22:08:52 GMT
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"}}'
36
+ http_version: '1.1'
@@ -0,0 +1,34 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: https://graph.facebook.com:443/me/feed?message=%27From%20OpenAuth2%27&access_token=AAADNSxdSLhsBALUJwhyMDYVTCV07ZAUyXIGwm2Bb9G5oudfZCYz2TcZB23ZABbFKTShb6JZC0aUVEsNfTMTRrqVWIrVyxNf4pElZAZCUWnd9QZDZD
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
+ access-control-allow-origin:
16
+ - ! '*'
17
+ cache-control:
18
+ - private, no-cache, no-store, must-revalidate
19
+ content-type:
20
+ - text/javascript; charset=UTF-8
21
+ expires:
22
+ - Sat, 01 Jan 2000 00:00:00 GMT
23
+ pragma:
24
+ - no-cache
25
+ x-fb-rev:
26
+ - '518267'
27
+ x-fb-debug:
28
+ - 1+GpoD6kWif2JDnTaD/XeITjokumXXb6BbGmwAciEiA=
29
+ date:
30
+ - Sat, 03 Mar 2012 01:37:49 GMT
31
+ content-length:
32
+ - '40'
33
+ body: ! '{"id":"100002930317357_200068986767444"}'
34
+ http_version: '1.1'
@@ -0,0 +1,36 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: https://graph.facebook.com:443/oauth/access_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
+ access-control-allow-origin:
18
+ - ! '*'
19
+ cache-control:
20
+ - private, no-cache, no-store, must-revalidate
21
+ content-type:
22
+ - text/plain; charset=UTF-8
23
+ expires:
24
+ - Sat, 01 Jan 2000 00:00:00 GMT
25
+ pragma:
26
+ - no-cache
27
+ x-fb-rev:
28
+ - '514925'
29
+ x-fb-debug:
30
+ - oAZnBNFMltYkzFalaO5iH4uo5Jcc0fnhK7QFGrcMfvI=
31
+ date:
32
+ - Sat, 25 Feb 2012 21:56:05 GMT
33
+ content-length:
34
+ - '127'
35
+ body: access_token=AAADNSxdSLhsBALUJwhyMDYVTCV07ZAUyXIGwm2Bb9G5oudfZCYz2TcZB23ZABbFKTShb6JZC0aUVEsNfTMTRrqVWIrVyxNf4pElZAZCUWnd9QZDZD
36
+ http_version: '1.1'
@@ -0,0 +1,38 @@
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:36:32 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.AHES6ZRXhZRQLYkdqVoHz9qxzTkNVhElBAQitCdJq816PQ\",\n
36
+ \ \"token_type\" : \"Bearer\",\n \"expires_in\" : 3600,\n \"refresh_token\"
37
+ : \"1/gUwId5-5ZHpM5G3Qooj67RDQI07zgzlJQwPjErLRzEg\"\n}"
38
+ http_version: '1.1'