plangrade-ruby 0.3.22 → 0.3.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +2 -2
- data/README.md +3 -3
- data/lib/plangrade/oauth2_client.rb +8 -14
- data/lib/plangrade/ruby/version.rb +1 -1
- data/spec/oauth2_client_spec.rb +3 -18
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecb0949e0cc91058f9f73270572ec1430024c60e
|
4
|
+
data.tar.gz: aed964c431dcfc9b084351fe17d7ce0567f51c73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd5fbc422ed5ad109cbf3e7fc807c26e100a9fffdc700efcf64616e357397804957d6dd2bdba69bce8bbd47f0ff0eab15fad84136f499a83bc5c4bc745890ac3
|
7
|
+
data.tar.gz: 9640f6b24614b22ba86792672a8239aa47cb78e92285a761ec18f1301bf569d568a1f21cb2cf037565e4f97e6d5117e8479a07c2ce13fff98a0a3600921f01ce
|
checksums.yaml.gz.sig
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
x��������BRٱ��|���y��gJ�)���7�\��H�y�l�*�/T�Mޠң���S��]���`��7�#�"������a��^��DG���H�Sr�%��,�ݵ���|J�]2^hBR~j#����{l�o������bme,2��/ffh�eMK�g��54��@j4�X�1�
|
2
|
+
:$%"t.-��?�[ֽ��� ����hV�x*"+�ғ��j���P5�kH&�ҕ��KM\K��9*?�z;c����
|
data/README.md
CHANGED
@@ -53,14 +53,14 @@ require 'plangrade'
|
|
53
53
|
|
54
54
|
# Begin by getting the authorization url
|
55
55
|
plangrade_client = Plangrade::OAuth2Client.new(ENV['PLANGRADE_CLIENT_ID'], ENV['PLANGRADE_CLIENT_SECRET'])
|
56
|
-
auth_url = plangrade_client.webserver_authorization_url(
|
56
|
+
auth_url = plangrade_client.webserver_authorization_url(your_redirect_uri)
|
57
57
|
```
|
58
58
|
|
59
59
|
After the user follows the link created above and authorizes your app, they will be redirected to your `redirect_uri`, with a code in the params that you can use to obtain an access token.
|
60
60
|
|
61
61
|
```ruby
|
62
62
|
plangrade_client = Plangrade::OAuth2Client.new(ENV['PLANGRADE_CLIENT_ID'], ENV['PLANGRADE_CLIENT_SECRET'])
|
63
|
-
response = plangrade_client.exchange_auth_code_for_token(
|
63
|
+
response = plangrade_client.exchange_auth_code_for_token(params[:code], your_redirect_uri)
|
64
64
|
token = JSON.parse response.body
|
65
65
|
access_token = token["access_token"]
|
66
66
|
refresh_token = token["refresh_token"]
|
@@ -75,7 +75,7 @@ This gem also allows you to use a `refresh_token` to obtain a new `access_token`
|
|
75
75
|
```ruby
|
76
76
|
# Set up a plangrade OAuth2 client and retrieve your refresh_token
|
77
77
|
plangrade_client = Plangrade::OAuth2Client.new(ENV['PLANGRADE_CLIENT_ID'], ENV['PLANGRADE_CLIENT_SECRET'])
|
78
|
-
response = plangrade_client.refresh_access_token(
|
78
|
+
response = plangrade_client.refresh_access_token(your_refresh_token, your_redirect_uri)
|
79
79
|
token = JSON.parse response.body
|
80
80
|
access_token = token["access_token"]
|
81
81
|
refresh_token = token["refresh_token"]
|
@@ -30,8 +30,8 @@ module Plangrade
|
|
30
30
|
# >> https://plangrade.com/oauth/authorize/?client_id={client_id}&
|
31
31
|
# redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Fplangrade%2Fcallback&response_type=code
|
32
32
|
#
|
33
|
-
def webserver_authorization_url(
|
34
|
-
opts
|
33
|
+
def webserver_authorization_url(redirect)
|
34
|
+
opts = {:redirect_uri => redirect}
|
35
35
|
authorization_code.authorization_url(opts)
|
36
36
|
end
|
37
37
|
|
@@ -54,12 +54,9 @@ module Plangrade
|
|
54
54
|
|
55
55
|
# client_id={client_id}&code=G3Y6jU3a&grant_type=authorization_code&
|
56
56
|
# redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Fplangrade%2Fcallback&client_secret={client_secret}
|
57
|
-
def exchange_auth_code_for_token(
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
opts[:authenticate] ||= :body
|
62
|
-
code = opts[:params].delete(:code)
|
57
|
+
def exchange_auth_code_for_token(code, redirect)
|
58
|
+
opts = {:params => {:redirect_uri => redirect}}
|
59
|
+
opts[:authenticate] = :body
|
63
60
|
authorization_code.get_token(code, opts)
|
64
61
|
end
|
65
62
|
|
@@ -81,13 +78,10 @@ module Plangrade
|
|
81
78
|
|
82
79
|
# client_id={client_id}&refresh_token=G3Y6jU3a&grant_type=refresh_token&
|
83
80
|
# client_secret={client_secret}
|
84
|
-
def refresh_access_token(
|
85
|
-
|
86
|
-
raise ArgumentError.new("You must provide a refresh_token as a parameter")
|
87
|
-
end
|
81
|
+
def refresh_access_token(ref_token, redirect)
|
82
|
+
opts = {:params => {:redirect_uri => redirect}}
|
88
83
|
opts[:authenticate] = :body
|
89
|
-
|
90
|
-
refresh_token.get_token(token, opts)
|
84
|
+
refresh_token.get_token(ref_token, opts)
|
91
85
|
end
|
92
86
|
end
|
93
87
|
end
|
data/spec/oauth2_client_spec.rb
CHANGED
@@ -38,14 +38,9 @@ describe Plangrade::OAuth2Client do
|
|
38
38
|
"client_id" => "PRbTcg9qjgKsp4jjpm1pw",
|
39
39
|
"redirect_uri" => "https://localhost:3000/callback",
|
40
40
|
"response_type" =>"code",
|
41
|
-
"state" => "12345"
|
42
41
|
}
|
43
42
|
|
44
|
-
auth_url = subject.webserver_authorization_url(
|
45
|
-
:client_id => 'PRbTcg9qjgKsp4jjpm1pw',
|
46
|
-
:state => '12345',
|
47
|
-
:redirect_uri => 'https://localhost:3000/callback'
|
48
|
-
)
|
43
|
+
auth_url = subject.webserver_authorization_url('https://localhost:3000/callback')
|
49
44
|
|
50
45
|
parsed_url = Addressable::URI.parse(auth_url)
|
51
46
|
expect(parsed_url.path).to eq '/oauth/authorize'
|
@@ -72,12 +67,7 @@ describe Plangrade::OAuth2Client do
|
|
72
67
|
'User-Agent' =>"Plangrade OAuth2 Client #{Plangrade::Ruby::VERSION}"
|
73
68
|
})
|
74
69
|
|
75
|
-
subject.exchange_auth_code_for_token(
|
76
|
-
:params => {
|
77
|
-
:code => 'MmOGL795LbIZuJJVnL49Cc',
|
78
|
-
:redirect_uri => 'http://localhost:3000/callback'
|
79
|
-
}
|
80
|
-
)
|
70
|
+
subject.exchange_auth_code_for_token('MmOGL795LbIZuJJVnL49Cc', 'http://localhost:3000/callback')
|
81
71
|
end
|
82
72
|
end
|
83
73
|
|
@@ -98,12 +88,7 @@ describe Plangrade::OAuth2Client do
|
|
98
88
|
'User-Agent' =>"Plangrade OAuth2 Client #{Plangrade::Ruby::VERSION}"
|
99
89
|
})
|
100
90
|
|
101
|
-
subject.refresh_access_token(
|
102
|
-
:params => {
|
103
|
-
:refresh_token => 'MmOGL795LbIZuJJVnL49Cc',
|
104
|
-
:redirect_uri => 'http://localhost:3000/callback'
|
105
|
-
}
|
106
|
-
)
|
91
|
+
subject.refresh_access_token('MmOGL795LbIZuJJVnL49Cc', 'http://localhost:3000/callback')
|
107
92
|
end
|
108
93
|
end
|
109
94
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|