cronofy 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/lib/cronofy/auth.rb +14 -3
- data/lib/cronofy/client.rb +2 -0
- data/lib/cronofy/version.rb +1 -1
- data/spec/lib/cronofy/auth_spec.rb +95 -27
- 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: e337b294d628d5677d58763c49dd46441d66edcf
|
4
|
+
data.tar.gz: 7ad6ea54a3fd5cba4b43f7f2533368574fa1639e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae50423467418330fbe878fbf70fbb2e8547c69e17b94858b0d66e1c9e700d0e54d1c827fbdb2abb16f7aa796f5ad5c8d81d3878d742266858051918c508dd76
|
7
|
+
data.tar.gz: 747e9ef78b0da42569496a3ff48ebdce4213be8848dc1a8332cd1c4d507e419fd23c5c8c057f49b08b6a055cae017a22d31ee7f7407422abefea714edb3d8dca
|
data/Gemfile
CHANGED
data/lib/cronofy/auth.rb
CHANGED
@@ -11,7 +11,7 @@ module Cronofy
|
|
11
11
|
@auth_client = OAuth2::Client.new(client_id, client_secret, site: ::Cronofy.app_url, connection_opts: { headers: { "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}" } })
|
12
12
|
@api_client = OAuth2::Client.new(client_id, client_secret, site: ::Cronofy.api_url, connection_opts: { headers: { "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}" } })
|
13
13
|
|
14
|
-
set_access_token(token, refresh_token) if token
|
14
|
+
set_access_token(token, refresh_token) if token || refresh_token
|
15
15
|
end
|
16
16
|
|
17
17
|
# Internal: generate a URL for authorizing the application with Cronofy
|
@@ -52,8 +52,15 @@ module Cronofy
|
|
52
52
|
end
|
53
53
|
|
54
54
|
# Internal: Refreshes the access token
|
55
|
-
#
|
55
|
+
#
|
56
|
+
# Returns Hash of token elements to allow client to update in local store
|
57
|
+
# for user
|
58
|
+
#
|
59
|
+
# Raises Cronofy::CredentialsMissingError if no credentials available.
|
56
60
|
def refresh!
|
61
|
+
raise CredentialsMissingError.new("No credentials to refresh") unless access_token
|
62
|
+
raise CredentialsMissingError.new("No refresh_token provided") unless access_token.refresh_token
|
63
|
+
|
57
64
|
do_request do
|
58
65
|
@access_token = access_token.refresh!
|
59
66
|
Credentials.new(@access_token)
|
@@ -71,12 +78,16 @@ module Cronofy
|
|
71
78
|
# Internal: Revokes the refresh token and corresponding access tokens.
|
72
79
|
#
|
73
80
|
# Returns nothing.
|
81
|
+
#
|
82
|
+
# Raises Cronofy::CredentialsMissingError if no credentials available.
|
74
83
|
def revoke!
|
84
|
+
raise CredentialsMissingError.new("No credentials to revoke") unless access_token
|
85
|
+
|
75
86
|
do_request do
|
76
87
|
body = {
|
77
88
|
client_id: @api_client.id,
|
78
89
|
client_secret: @api_client.secret,
|
79
|
-
token: access_token.refresh_token,
|
90
|
+
token: access_token.refresh_token || access_token.token,
|
80
91
|
}
|
81
92
|
|
82
93
|
@api_client.request(:post, "/oauth/token/revoke", body: body)
|
data/lib/cronofy/client.rb
CHANGED
@@ -455,6 +455,7 @@ module Cronofy
|
|
455
455
|
# been revoked.
|
456
456
|
# Raises Cronofy::AuthenticationFailureError if the client ID and secret are
|
457
457
|
# not valid.
|
458
|
+
# Raises Cronofy::CredentialsMissingError if no credentials available.
|
458
459
|
def refresh_access_token
|
459
460
|
@auth.refresh!
|
460
461
|
end
|
@@ -471,6 +472,7 @@ module Cronofy
|
|
471
472
|
#
|
472
473
|
# Raises Cronofy::AuthenticationFailureError if the client ID and secret are
|
473
474
|
# not valid.
|
475
|
+
# Raises Cronofy::CredentialsMissingError if no credentials available.
|
474
476
|
def revoke_authorization
|
475
477
|
@auth.revoke!
|
476
478
|
end
|
data/lib/cronofy/version.rb
CHANGED
@@ -243,46 +243,114 @@ describe Cronofy::Auth do
|
|
243
243
|
end
|
244
244
|
|
245
245
|
describe '#refresh!' do
|
246
|
-
|
247
|
-
|
246
|
+
context "access_token and refresh_token present" do
|
247
|
+
subject do
|
248
|
+
Cronofy::Auth.new(client_id, client_secret, access_token, refresh_token).refresh!
|
249
|
+
end
|
250
|
+
|
251
|
+
it_behaves_like 'an authorization request'
|
248
252
|
end
|
249
253
|
|
250
|
-
|
254
|
+
context "no refresh_token" do
|
255
|
+
subject do
|
256
|
+
Cronofy::Auth.new(client_id, client_secret, access_token, nil).refresh!
|
257
|
+
end
|
258
|
+
|
259
|
+
it "raises a credentials missing error" do
|
260
|
+
expect { subject }.to raise_error(Cronofy::CredentialsMissingError)
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
context "no access_token or refresh_token" do
|
265
|
+
subject do
|
266
|
+
Cronofy::Auth.new(client_id, client_secret, nil, nil).refresh!
|
267
|
+
end
|
268
|
+
|
269
|
+
it "raises a credentials missing error" do
|
270
|
+
expect { subject }.to raise_error(Cronofy::CredentialsMissingError)
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
context "only refresh_token" do
|
275
|
+
subject do
|
276
|
+
Cronofy::Auth.new(client_id, client_secret, nil, refresh_token).refresh!
|
277
|
+
end
|
278
|
+
|
279
|
+
it_behaves_like 'an authorization request'
|
280
|
+
end
|
251
281
|
end
|
252
282
|
|
253
283
|
describe "#revoke!" do
|
254
|
-
|
255
|
-
|
284
|
+
shared_examples 'successful revocation' do
|
285
|
+
let!(:revocation_request) do
|
286
|
+
stub_request(:post, "https://api.cronofy.com/oauth/token/revoke")
|
287
|
+
.with(
|
288
|
+
body: {
|
289
|
+
client_id: client_id,
|
290
|
+
client_secret: client_secret,
|
291
|
+
token: revoke_token,
|
292
|
+
},
|
293
|
+
headers: {
|
294
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
295
|
+
'User-Agent' => "Cronofy Ruby #{Cronofy::VERSION}",
|
296
|
+
}
|
297
|
+
)
|
298
|
+
.to_return(
|
299
|
+
status: response_status,
|
300
|
+
)
|
301
|
+
end
|
302
|
+
|
303
|
+
before do
|
304
|
+
auth.revoke!
|
305
|
+
end
|
306
|
+
|
307
|
+
it "unsets the access token" do
|
308
|
+
expect(auth.access_token).to be_nil
|
309
|
+
end
|
310
|
+
|
311
|
+
it "makes the revocation request" do
|
312
|
+
expect(revocation_request).to have_been_requested
|
313
|
+
end
|
256
314
|
end
|
257
315
|
|
258
|
-
|
259
|
-
|
260
|
-
.
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
headers: {
|
267
|
-
'Content-Type' => 'application/x-www-form-urlencoded',
|
268
|
-
'User-Agent' => "Cronofy Ruby #{Cronofy::VERSION}",
|
269
|
-
}
|
270
|
-
)
|
271
|
-
.to_return(
|
272
|
-
status: response_status,
|
273
|
-
)
|
316
|
+
context "access_token and refresh_token present" do
|
317
|
+
let(:auth) do
|
318
|
+
Cronofy::Auth.new(client_id, client_secret, access_token, refresh_token)
|
319
|
+
end
|
320
|
+
|
321
|
+
let(:revoke_token) { refresh_token }
|
322
|
+
|
323
|
+
it_behaves_like 'successful revocation'
|
274
324
|
end
|
275
325
|
|
276
|
-
|
277
|
-
auth
|
326
|
+
context "only refresh_token" do
|
327
|
+
let(:auth) do
|
328
|
+
Cronofy::Auth.new(client_id, client_secret, nil, refresh_token)
|
329
|
+
end
|
330
|
+
|
331
|
+
let(:revoke_token) { refresh_token }
|
332
|
+
|
333
|
+
it_behaves_like 'successful revocation'
|
278
334
|
end
|
279
335
|
|
280
|
-
|
281
|
-
|
336
|
+
context "only access_token" do
|
337
|
+
let(:auth) do
|
338
|
+
Cronofy::Auth.new(client_id, client_secret, access_token, nil)
|
339
|
+
end
|
340
|
+
|
341
|
+
let(:revoke_token) { access_token }
|
342
|
+
|
343
|
+
it_behaves_like 'successful revocation'
|
282
344
|
end
|
283
345
|
|
284
|
-
|
285
|
-
|
346
|
+
context "no access_token or refresh_token" do
|
347
|
+
let(:auth) do
|
348
|
+
Cronofy::Auth.new(client_id, client_secret, nil, nil)
|
349
|
+
end
|
350
|
+
|
351
|
+
it "raises a credentials missing error" do
|
352
|
+
expect { auth.revoke! }.to raise_error(Cronofy::CredentialsMissingError)
|
353
|
+
end
|
286
354
|
end
|
287
355
|
end
|
288
356
|
end
|
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.10.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: 2016-
|
12
|
+
date: 2016-07-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth2
|