cronofy 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/lib/cronofy/auth.rb +18 -4
- data/lib/cronofy/client.rb +11 -6
- data/lib/cronofy/version.rb +1 -1
- data/spec/lib/cronofy/auth_spec.rb +59 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d36dfd5dfa353d4d906d8ca54a6f5de39d584b13
|
4
|
+
data.tar.gz: 7b38f363878df9bf48df0cf16faba49c42379f67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5025298994becd0ae491eaf498db26578535779bac1535fec7cf27b2e0ef3fdf4a89f71b172f01bb6a04f0c1ce804039fe465d403f5bc2ba7dbba839a17ac0dd
|
7
|
+
data.tar.gz: 28d0d9200ce72f96978309df3ec1bc9e908af2149b6279a3c7be9852ac4e82f635424f119ba865852aae23e283d54ef5ffd0d7bd5f81ea7dbf07bb0d9a26af2b
|
data/lib/cronofy/auth.rb
CHANGED
@@ -14,14 +14,28 @@ module Cronofy
|
|
14
14
|
|
15
15
|
# Internal: generate a URL for authorizing the application with Cronofy
|
16
16
|
#
|
17
|
-
# redirect_uri
|
18
|
-
#
|
17
|
+
# redirect_uri - A String specifing the URI to return the user to once they
|
18
|
+
# have completed the authorization steps.
|
19
|
+
# options - The Hash options used to refine the selection
|
20
|
+
# (default: {}):
|
21
|
+
# :scope - Array of scopes describing the access to request
|
22
|
+
# from the user to the users calendars (required).
|
23
|
+
# :state - String containing the state value to retain during
|
24
|
+
# the OAuth authorization process (optional).
|
19
25
|
#
|
20
26
|
# See http://www.cronofy.com/developers/api#authorization for reference.
|
21
27
|
#
|
22
28
|
# Returns the URL as a String.
|
23
|
-
def user_auth_link(redirect_uri,
|
24
|
-
|
29
|
+
def user_auth_link(redirect_uri, options = {})
|
30
|
+
raise ArgumentError.new(":scope is required") unless options[:scope]
|
31
|
+
|
32
|
+
params = options.merge(redirect_uri: redirect_uri, response_type: 'code')
|
33
|
+
|
34
|
+
# Reformat params as needed
|
35
|
+
params.delete(:state) if params[:state].nil?
|
36
|
+
params[:scope] = params[:scope].join(' ')
|
37
|
+
|
38
|
+
@auth_client.auth_code.authorize_url(params)
|
25
39
|
end
|
26
40
|
|
27
41
|
def get_token_from_code(code, redirect_uri)
|
data/lib/cronofy/client.rb
CHANGED
@@ -268,17 +268,22 @@ module Cronofy
|
|
268
268
|
# Public: Generates a URL to send the user to in order to perform the OAuth
|
269
269
|
# 2.0 authorization process.
|
270
270
|
#
|
271
|
-
#
|
271
|
+
# redirect_uri - A String specifing the URI to return the user to once they
|
272
272
|
# have completed the authorization steps.
|
273
|
-
#
|
274
|
-
#
|
275
|
-
#
|
273
|
+
# options - The Hash options used to refine the selection
|
274
|
+
# (default: {}):
|
275
|
+
# :scope - Array of scopes describing the access to request
|
276
|
+
# from the user to the users calendars
|
277
|
+
# (default: DEFAULT_OAUTH_SCOPE).
|
278
|
+
# :state - String containing the state value to retain during
|
279
|
+
# the OAuth authorization process (optional).
|
276
280
|
#
|
277
281
|
# See http://www.cronofy.com/developers/api#authorization for reference.
|
278
282
|
#
|
279
283
|
# Returns the URL as a String.
|
280
|
-
def user_auth_link(redirect_url,
|
281
|
-
|
284
|
+
def user_auth_link(redirect_url, options = {})
|
285
|
+
options = { scope: DEFAULT_OAUTH_SCOPE }.merge(options)
|
286
|
+
@auth.user_auth_link(redirect_url, options)
|
282
287
|
end
|
283
288
|
|
284
289
|
# Public: Retrieves the OAuth credentials authorized for the given code and
|
data/lib/cronofy/version.rb
CHANGED
@@ -78,6 +78,65 @@ describe Cronofy::Auth do
|
|
78
78
|
)
|
79
79
|
end
|
80
80
|
|
81
|
+
describe '#user_auth_link' do
|
82
|
+
let(:scope_array) { %w{read_events list_calendars create_event} }
|
83
|
+
let(:scheme) { 'https' }
|
84
|
+
let(:host) { 'app.cronofy.com' }
|
85
|
+
let(:path) { '/oauth/authorize' }
|
86
|
+
let(:default_params) do
|
87
|
+
{
|
88
|
+
'client_id' => client_id,
|
89
|
+
'redirect_uri' => redirect_uri,
|
90
|
+
'response_type' => 'code',
|
91
|
+
'scope' => scope
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
let(:auth) do
|
96
|
+
Cronofy::Auth.new(client_id, client_secret)
|
97
|
+
end
|
98
|
+
|
99
|
+
subject do
|
100
|
+
url = auth.user_auth_link(redirect_uri, scope: scope_array, state: state)
|
101
|
+
URI.parse(url)
|
102
|
+
end
|
103
|
+
|
104
|
+
shared_examples 'a user auth link provider' do
|
105
|
+
it 'contains the correct scheme' do
|
106
|
+
expect(subject.scheme).to eq scheme
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'contains the correct host' do
|
110
|
+
expect(subject.host).to eq host
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'contains the correct path' do
|
114
|
+
expect(subject.path).to eq path
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'contains the correct query params' do
|
118
|
+
expect(Rack::Utils.parse_query(subject.query)).to eq params
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'when no state' do
|
123
|
+
let(:state) { nil }
|
124
|
+
let(:params) { default_params }
|
125
|
+
|
126
|
+
it_behaves_like 'a user auth link provider'
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'when state is passed' do
|
130
|
+
let(:state) { SecureRandom.hex }
|
131
|
+
let(:params) do
|
132
|
+
default_params['state'] = state
|
133
|
+
default_params
|
134
|
+
end
|
135
|
+
|
136
|
+
it_behaves_like 'a user auth link provider'
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
81
140
|
shared_examples 'an authorization request' do
|
82
141
|
context 'when succeeds' do
|
83
142
|
it 'returns a correct Credentials object' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cronofy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergii Paryzhskyi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-04-
|
12
|
+
date: 2015-04-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth2
|