boxr 0.29.0 → 0.30.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
  SHA1:
3
- metadata.gz: 0665e63cc6208e2b553601a6a1748b3ab7e0b4b6
4
- data.tar.gz: 2161c7d7914825edf273d40c1e576851bb766199
3
+ metadata.gz: 527dd92dd98452269357273594b57fd009e875c8
4
+ data.tar.gz: 814f84b862988ba3fc7df51610bc4cc182908a4c
5
5
  SHA512:
6
- metadata.gz: ed18bbde850f3662f24feb12b3e8243e73d2af181893a80076c006197eb949b7daba26a0919b3492dbcda4358993b24d4468a20d8c39aaab7e3de284ce1e6acf
7
- data.tar.gz: 2d590a62dc56694c53a5c24b5d59e32ced3ed081173968763c73c700f517e25f0273481a5d66731c2abf7617d5dafb1e37659cbd51f703917752c823bbba07db
6
+ metadata.gz: b363f469d80d454db40a5ff53fe4ff39568ca3c1ff7bbc959efa8bb5c4138822ad3e4c56affbe3079b842694040ad054891366a7893322ee7d4277e1167b4881
7
+ data.tar.gz: e7badddaada9d1f4d34c2d7d144df62ebb84a74bcbf59dc2856099e0f1ea5ac67966b23660128e55f1815a4d015b4a0aa9dd62f932685992813d1649271c3612
data/README.md CHANGED
@@ -84,7 +84,17 @@ client = Boxr::Client.new('zX3UjFwNerOy5PSWc2WI8aJgMHtAjs8T',
84
84
  ```
85
85
  Here's the complete method signature to initialize an instance of Boxr::Client
86
86
  ```ruby
87
- initialize(access_token=ENV['BOX_DEVELOPER_TOKEN'], refresh_token: nil, box_client_id: ENV['BOX_CLIENT_ID'], box_client_secret: ENV['BOX_CLIENT_SECRET'], identifier: nil, as_user: nil, &token_refresh_listener)
87
+ initialize( access_token=ENV['BOX_DEVELOPER_TOKEN'],
88
+ refresh_token: nil,
89
+ client_id: ENV['BOX_CLIENT_ID'],
90
+ client_secret: ENV['BOX_CLIENT_SECRET'],
91
+ enterprise_id: ENV['BOX_ENTERPRISE_ID'],
92
+ jwt_private_key: ENV['JWT_PRIVATE_KEY'],
93
+ jwt_private_key_password: ENV['JWT_PRIVATE_KEY_PASSWORD'],
94
+ jwt_public_key_id: ENV['JWT_PUBLIC_KEY_ID'],
95
+ identifier: nil,
96
+ as_user: nil,
97
+ &token_refresh_listener)
88
98
  ```
89
99
 
90
100
  ### A quick example
@@ -116,9 +126,9 @@ Boxr::refresh_tokens(refresh_token, client_id: ENV['BOX_CLIENT_ID'], client_secr
116
126
  Boxr::revoke_tokens(token, client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
117
127
 
118
128
  #JWT methods
119
- Boxr::get_enterprise_token(private_key: ENV['JWT_PRIVATE_KEY'], private_key_password: ENV['JWT_PRIVATE_KEY_PASSWORD'], enterprise_id: ENV['BOX_ENTERPRISE_ID'], client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
129
+ Boxr::get_enterprise_token(private_key: ENV['JWT_PRIVATE_KEY'], private_key_password: ENV['JWT_PRIVATE_KEY_PASSWORD'], public_key_id: ENV['JWT_PUBLIC_KEY_ID'], enterprise_id: ENV['BOX_ENTERPRISE_ID'], client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
120
130
 
121
- Boxr::get_user_token(user_id, private_key: ENV['JWT_PRIVATE_KEY'], private_key_password: ENV['JWT_PRIVATE_KEY_PASSWORD'], client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
131
+ Boxr::get_user_token(user_id, private_key: ENV['JWT_PRIVATE_KEY'], private_key_password: ENV['JWT_PRIVATE_KEY_PASSWORD'], public_key_id: ENV['JWT_PUBLIC_KEY_ID'], client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
122
132
  ```
123
133
  #### [Folders](https://developers.box.com/docs/#folders)
124
134
  ```ruby
@@ -0,0 +1,24 @@
1
+ require 'dotenv'; Dotenv.load("../.env")
2
+ require 'awesome_print'
3
+ require 'boxr'
4
+
5
+ box_client = Boxr::Client.new(ENV['BOX_DEVELOPER_TOKEN'])
6
+
7
+ current_user_id = box_client.me.id
8
+
9
+ folders = box_client.root_folder_items(fields:[:owned_by, :name]).folders
10
+ owned_folders = folders.select{|f| f.owned_by.id == current_user_id}
11
+
12
+ removed_count = 0
13
+ owned_folders.each do |f|
14
+ puts "Checking folder '#{f.name}'"
15
+ collabs = box_client.folder_collaborations(f, fields:[:accessible_by])
16
+ collabs.each do |c|
17
+ box_client.remove_collaboration(c)
18
+ removed_count += 1
19
+ puts "\t removed collaboration with the #{c.accessible_by.type} #{c.accessible_by.name}"
20
+ end
21
+ end
22
+
23
+ puts
24
+ puts "Removed #{removed_count} collaborations from #{owned_folders.count} folders"
data/lib/boxr/auth.rb CHANGED
@@ -25,16 +25,17 @@ module Boxr
25
25
  end
26
26
 
27
27
  def self.get_enterprise_token(private_key: ENV['JWT_PRIVATE_KEY'], private_key_password: ENV['JWT_PRIVATE_KEY_PASSWORD'],
28
- enterprise_id: ENV['BOX_ENTERPRISE_ID'], client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
28
+ public_key_id: ENV['JWT_PUBLIC_KEY_ID'], enterprise_id: ENV['BOX_ENTERPRISE_ID'],
29
+ client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
29
30
  unlocked_private_key = unlock_key(private_key, private_key_password)
30
- assertion = jwt_assertion(unlocked_private_key, client_id, enterprise_id, "enterprise")
31
+ assertion = jwt_assertion(unlocked_private_key, client_id, enterprise_id, "enterprise", public_key_id)
31
32
  get_token(grant_type: JWT_GRANT_TYPE, assertion: assertion, client_id: client_id, client_secret: client_secret)
32
33
  end
33
34
 
34
35
  def self.get_user_token(user_id, private_key: ENV['JWT_PRIVATE_KEY'], private_key_password: ENV['JWT_PRIVATE_KEY_PASSWORD'],
35
- client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
36
+ public_key_id: ENV['JWT_PUBLIC_KEY_ID'], client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
36
37
  unlocked_private_key = unlock_key(private_key, private_key_password)
37
- assertion = jwt_assertion(unlocked_private_key, client_id, user_id, "user")
38
+ assertion = jwt_assertion(unlocked_private_key, client_id, user_id, "user", public_key_id)
38
39
  get_token(grant_type: JWT_GRANT_TYPE, assertion: assertion, client_id: client_id, client_secret: client_secret)
39
40
  end
40
41
 
@@ -61,7 +62,7 @@ module Boxr
61
62
  private
62
63
 
63
64
 
64
- def self.jwt_assertion(private_key, iss, sub, box_sub_type)
65
+ def self.jwt_assertion(private_key, iss, sub, box_sub_type, public_key_id)
65
66
  payload = {
66
67
  iss: iss,
67
68
  sub: sub,
@@ -70,8 +71,11 @@ module Boxr
70
71
  jti: SecureRandom.hex(64),
71
72
  exp: (Time.now.utc + 10).to_i
72
73
  }
74
+
75
+ additional_headers = {}
76
+ additional_headers['kid'] = public_key_id unless public_key_id.nil?
73
77
 
74
- JWT.encode(payload, private_key, "RS256")
78
+ JWT.encode(payload, private_key, "RS256", additional_headers)
75
79
  end
76
80
 
77
81
  def self.auth_post(uri, body)
data/lib/boxr/client.rb CHANGED
@@ -63,6 +63,7 @@ module Boxr
63
63
  enterprise_id: ENV['BOX_ENTERPRISE_ID'],
64
64
  jwt_private_key: ENV['JWT_PRIVATE_KEY'],
65
65
  jwt_private_key_password: ENV['JWT_PRIVATE_KEY_PASSWORD'],
66
+ jwt_public_key_id: ENV['JWT_PUBLIC_KEY_ID'],
66
67
  identifier: nil,
67
68
  as_user: nil,
68
69
  &token_refresh_listener)
@@ -76,6 +77,7 @@ module Boxr
76
77
  @enterprise_id = enterprise_id
77
78
  @jwt_private_key = jwt_private_key
78
79
  @jwt_private_key_password = jwt_private_key_password
80
+ @jwt_public_key_id = jwt_public_key_id
79
81
  @identifier = identifier
80
82
  @as_user_id = ensure_id(as_user)
81
83
  @token_refresh_listener = token_refresh_listener
@@ -214,10 +216,10 @@ module Boxr
214
216
  @token_refresh_listener.call(@access_token, @refresh_token, @identifier) if @token_refresh_listener
215
217
  else
216
218
  if @as_user_id
217
- new_token = Boxr::get_user_token(@as_user_id, private_key: @jwt_private_key, private_key_password: @jwt_private_key_password, client_id: @client_id, client_secret: @client_secret)
219
+ new_token = Boxr::get_user_token(@as_user_id, private_key: @jwt_private_key, private_key_password: @jwt_private_key_password, public_key_id: @jwt_public_key_id, client_id: @client_id, client_secret: @client_secret)
218
220
  @access_token = new_token.access_token
219
221
  else
220
- new_token = Boxr::get_enterprise_token(private_key: @jwt_private_key, private_key_password: @jwt_private_key_password, enterprise_id: @enterprise_id, client_id: @client_id, client_secret: @client_secret)
222
+ new_token = Boxr::get_enterprise_token(private_key: @jwt_private_key, private_key_password: @jwt_private_key_password, public_key_id: @jwt_public_key_id, enterprise_id: @enterprise_id, client_id: @client_id, client_secret: @client_secret)
221
223
  @access_token = new_token.access_token
222
224
  end
223
225
  end
data/lib/boxr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Boxr
2
- VERSION = "0.29.0"
2
+ VERSION = "0.30.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.29.0
4
+ version: 0.30.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Burnette
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-17 00:00:00.000000000 Z
11
+ date: 2015-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -197,6 +197,7 @@ files:
197
197
  - examples/enterprise_events.rb
198
198
  - examples/jwt_auth.rb
199
199
  - examples/oauth.rb
200
+ - examples/remove_collaborators.rb
200
201
  - examples/use_events_to_send_sms.rb
201
202
  - examples/use_events_to_warn_about_sharing.rb
202
203
  - examples/user_events.rb
@@ -240,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
241
  version: '0'
241
242
  requirements: []
242
243
  rubyforge_project:
243
- rubygems_version: 2.4.5
244
+ rubygems_version: 2.4.6
244
245
  signing_key:
245
246
  specification_version: 4
246
247
  summary: A Ruby client library for the Box V2 Content API that covers 100% of the