cronofy 0.36.1 → 0.37.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f05693cffaf2848f4ff1d8dbc874ca832a04a13670ab5c30219a4927e04d0d4b
4
- data.tar.gz: cdbd7c8463b2ae594d7fce826343e453c1099d2f603fd267c0e2b9e1cb98e145
3
+ metadata.gz: 308d390e34e9ed071119e343cc32f18121ddcff2328fbc945b3a785e64550676
4
+ data.tar.gz: 2ab98066dd1c8eeef0d44a4ddef32f49945edd2d4b84c16d7f5607bbbb54220a
5
5
  SHA512:
6
- metadata.gz: 44018884d14fe47332fe1e5fca9754ef1357005d9643fb91960886a04d20afec8670a8e340a36ed19b5fb4e04a6e7e02454b48a959474d46f9985998e7079d77
7
- data.tar.gz: eca3eb5a85e980ebd72d3416b48b945d6f0dfb832cf63ad8baf7c0cecf3b4429b5682ea69ea9a41b93ad08f498228f7e901f84941a2e6f0e784cfdc444b2b192
6
+ metadata.gz: c61c10c546d52fee5d4af2ed2030f33a477d0b79cce98c89eb977e76cb9a1918250a00cf4fa1d74b2a35eb044da6ba338f504d6427b07173386c542dae48af97
7
+ data.tar.gz: 844a546be5ef240ebb964e72926363eedf023bc05ce05bfa95e5af7b1adc8bfbef18a53b1415cec348b370367ec322e5513b7330622753b29b350c1ec046fa67
@@ -1,6 +1,10 @@
1
+ ## [0.37.0]
2
+
3
+ * Add `revoke_by_token` and `revoke_by_sub` to the Client [#86]
4
+
1
5
  ## [0.36.1]
2
6
 
3
- * Loosen the version requirement on Hashie to allow 4.X
7
+ * Loosen the version requirement on Hashie to allow 4.X
4
8
 
5
9
  ## [0.36.0]
6
10
 
@@ -172,6 +176,7 @@
172
176
  [0.35.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.35.0
173
177
  [0.36.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.36.0
174
178
  [0.36.1]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.36.1
179
+ [0.37.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.37.0
175
180
 
176
181
  [#13]: https://github.com/cronofy/cronofy-ruby/pull/13
177
182
  [#16]: https://github.com/cronofy/cronofy-ruby/pull/16
@@ -213,3 +218,4 @@
213
218
  [#77]: https://github.com/cronofy/cronofy-ruby/pull/77
214
219
  [#81]: https://github.com/cronofy/cronofy-ruby/pull/81
215
220
  [#85]: https://github.com/cronofy/cronofy-ruby/pull/85
221
+ [#86]: https://github.com/cronofy/cronofy-ruby/pull/86
@@ -118,20 +118,50 @@ module Cronofy
118
118
  def revoke!
119
119
  raise CredentialsMissingError.new("No credentials to revoke") unless access_token
120
120
 
121
+ token = access_token.refresh_token || access_token.token
122
+ revoke_by_token(token)
123
+ @access_token = nil
124
+ end
125
+
126
+ # Internal: Revokes an authorization by the sub
127
+ #
128
+ # Returns nothing.
129
+ #
130
+ # Raises Cronofy::CredentialsMissingError if no credentials available.
131
+ def revoke_by_sub(sub)
132
+ do_revoke(sub: sub)
133
+ end
134
+
135
+ # Internal: Revokes an authorization via the token
136
+ #
137
+ # Returns nothing.
138
+ #
139
+ # Raises Cronofy::CredentialsMissingError if no credentials available.
140
+ def revoke_by_token(token)
141
+ do_revoke(token: token)
142
+ end
143
+
144
+ private
145
+
146
+ def do_revoke(token: nil, sub: nil)
147
+ raise CredentialsMissingError.new("No credentials to revoke") unless token || sub
148
+
121
149
  do_request do
122
150
  body = {
123
151
  client_id: @api_client.id,
124
152
  client_secret: @api_client.secret,
125
- token: access_token.refresh_token || access_token.token,
126
153
  }
127
154
 
155
+ if token
156
+ body.merge!(token: token)
157
+ else
158
+ body.merge!(sub: sub)
159
+ end
160
+
128
161
  @api_client.request(:post, "/oauth/token/revoke", body: body)
129
- @access_token = nil
130
162
  end
131
163
  end
132
164
 
133
- private
134
-
135
165
  def do_request(&block)
136
166
  if @client_credentials_missing
137
167
  raise CredentialsMissingError.new("OAuth client_id and client_secret must be set")
@@ -737,6 +737,14 @@ module Cronofy
737
737
  @auth.revoke!
738
738
  end
739
739
 
740
+ def revoke_by_sub(sub)
741
+ @auth.revoke_by_sub(sub)
742
+ end
743
+
744
+ def revoke_by_token(token)
745
+ @auth.revoke_by_token(token)
746
+ end
747
+
740
748
  # Public: Requests elevated permissions for a set of calendars.
741
749
  #
742
750
  # args - A Hash of options used to initialize the request (default: {}):
@@ -1,3 +1,3 @@
1
1
  module Cronofy
2
- VERSION = "0.36.1".freeze
2
+ VERSION = "0.37.0".freeze
3
3
  end
@@ -476,4 +476,84 @@ describe Cronofy::Auth do
476
476
  end
477
477
  end
478
478
  end
479
+
480
+ describe "#revoke_by_sub" do
481
+ let(:auth) do
482
+ Cronofy::Auth.new(
483
+ client_id: client_id,
484
+ client_secret: client_secret,
485
+ access_token: access_token,
486
+ refresh_token: refresh_token,
487
+ )
488
+ end
489
+
490
+ let!(:revocation_request) do
491
+ stub_request(:post, "https://api.cronofy.com/oauth/token/revoke")
492
+ .with(
493
+ body: {
494
+ client_id: client_id,
495
+ client_secret: client_secret,
496
+ sub: sub,
497
+ },
498
+ headers: {
499
+ 'Content-Type' => 'application/x-www-form-urlencoded',
500
+ 'User-Agent' => "Cronofy Ruby #{Cronofy::VERSION}",
501
+ }
502
+ ).to_return(status: response_status)
503
+ end
504
+
505
+ let(:sub) { "random_sub_value" }
506
+
507
+ before do
508
+ auth.revoke_by_sub(sub)
509
+ end
510
+
511
+ it "does not unset the access token for the current auth" do
512
+ expect(auth.access_token).not_to be_nil
513
+ end
514
+
515
+ it "makes the revocation request" do
516
+ expect(revocation_request).to have_been_requested
517
+ end
518
+ end
519
+
520
+ describe "#revoke_by_token" do
521
+ let(:auth) do
522
+ Cronofy::Auth.new(
523
+ client_id: client_id,
524
+ client_secret: client_secret,
525
+ access_token: access_token,
526
+ refresh_token: refresh_token,
527
+ )
528
+ end
529
+
530
+ let!(:revocation_request) do
531
+ stub_request(:post, "https://api.cronofy.com/oauth/token/revoke")
532
+ .with(
533
+ body: {
534
+ client_id: client_id,
535
+ client_secret: client_secret,
536
+ token: token,
537
+ },
538
+ headers: {
539
+ 'Content-Type' => 'application/x-www-form-urlencoded',
540
+ 'User-Agent' => "Cronofy Ruby #{Cronofy::VERSION}",
541
+ }
542
+ ).to_return(status: response_status)
543
+ end
544
+
545
+ let(:token) { "random_token_value" }
546
+
547
+ before do
548
+ auth.revoke_by_token(token)
549
+ end
550
+
551
+ it "does not unset the access token for the current auth" do
552
+ expect(auth.access_token).not_to be_nil
553
+ end
554
+
555
+ it "makes the revocation request" do
556
+ expect(revocation_request).to have_been_requested
557
+ end
558
+ end
479
559
  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.36.1
4
+ version: 0.37.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: 2020-10-20 00:00:00.000000000 Z
12
+ date: 2021-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashie
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
158
  requirements: []
159
- rubygems_version: 3.1.2
159
+ rubygems_version: 3.2.4
160
160
  signing_key:
161
161
  specification_version: 4
162
162
  summary: Cronofy - one API for all the calendars