boxr 0.21.0 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a3b6baa11b8ad38247f9656f13c408516e97388
4
- data.tar.gz: 3fcb4e8d3db3aff66811bc0132015e0e15f02096
3
+ metadata.gz: f81fca6ac793e46eb0f19c162e0d64d99dd227c9
4
+ data.tar.gz: 6c3de3cc84f0189799cece2582ce59aae0ee09dd
5
5
  SHA512:
6
- metadata.gz: 1e75ef1039e90040d877590acac9a37986375492ca48cfe45dac8cdd1667b588b1ea61b53097366766545796fa8c3cf625cc4767e18291246df49992f165d6a2
7
- data.tar.gz: 58ce42b7bd7892c06647541e3d75b768c312d423e2f9ce7fb8d682398a4d428ec8864b00483364b280a1b12586368cea0fb40e16049f3737a50026eb13b48066
6
+ metadata.gz: 5473112cd30336361310e50e230d09a6fe414d63d0a84052e17df85d42b8ce216b117a995b4838f5fda36a3b56410c104ccbfe86744edf1ee2569d3878972e50
7
+ data.tar.gz: 88be3dbc6f94304946d6f3d2bc95cb6329f01d07e7a30a479aee183b1fbddf9749819428e2858db105f4fae14a278d44e48be27d39b9681db419756cc3a5c3fb
@@ -9,4 +9,7 @@
9
9
 
10
10
  BOX_DEVELOPER_TOKEN={a valid developer token for your Box app}
11
11
  BOX_CLIENT_ID={client id of your Box app}
12
- BOX_CLIENT_SECRET={client secret of your Box app}
12
+ BOX_CLIENT_SECRET={client secret of your Box app}
13
+ BOX_ENTERPRISE_ID={box enterprise id}
14
+ JWT_SECRET_KEY_PATH={path to your JWT private key}
15
+ JWT_SECRET_KEY_PASSWORD={JWT private key password}
@@ -27,10 +27,10 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "dotenv", "~> 0.11"
28
28
  spec.add_development_dependency "awesome_print"
29
29
  spec.add_development_dependency "lru_redux", "~> 0.8"
30
- spec.add_development_dependency "jwt", "~> 1.4"
31
30
 
32
31
  spec.add_runtime_dependency "oj", "~> 2.11"
33
32
  spec.add_runtime_dependency "httpclient", "~> 2.5"
34
33
  spec.add_runtime_dependency "hashie", "~> 3.3"
35
34
  spec.add_runtime_dependency "addressable", "~> 2.3"
35
+ spec.add_runtime_dependency "jwt", "~> 1.4"
36
36
  end
@@ -1,24 +1,12 @@
1
1
  require 'dotenv'; Dotenv.load("../.env")
2
2
  require 'boxr'
3
3
  require 'awesome_print'
4
- require 'jwt'
5
- require 'securerandom'
6
4
  require 'openssl'
7
5
 
8
6
 
9
- private_key = OpenSSL::PKey::RSA.new File.read(ENV['JWT_SECRET_KEY_PATH']), ENV['JWT_SECRET_KEY_PASSWORD']
10
- grant_type = "urn:ietf:params:oauth:grant-type:jwt-bearer"
7
+ private_key = OpenSSL::PKey::RSA.new(File.read(ENV['JWT_SECRET_KEY_PATH']), ENV['JWT_SECRET_KEY_PASSWORD'])
11
8
 
12
- payload = {
13
- iss: ENV['BOX_CLIENT_ID'],
14
- sub: ENV['BOX_ENTERPRISE_ID'],
15
- box_sub_type: "enterprise",
16
- aud: "https://api.box.com/oauth2/token",
17
- jti: SecureRandom.hex(64),
18
- exp: (Time.now.utc + 10).to_i
19
- }
9
+ #make sure ENV['BOX_ENTERPRISE_ID'] and ENV['BOX_CLIENT_ID'] are set
10
+ response = Boxr::get_enterprise_token(private_key)
20
11
 
21
- assertion = JWT.encode(payload, private_key, "RS256")
22
-
23
- response = Boxr::get_token(grant_type: grant_type, assertion: assertion)
24
12
  ap response
@@ -4,7 +4,7 @@ require 'uri'
4
4
  require 'awesome_print'
5
5
 
6
6
  #make sure you have BOX_CLIENT_ID and BOX_CLIENT_SECRET set in your .env file
7
- #make sure you have the redirect_uri for your application set to something like https://localhost:1234 in the developer portal
7
+ #make sure you have the redirect_uri for your application set to something like http://localhost:1234 in the developer portal
8
8
 
9
9
  oauth_url = Boxr::oauth_url(URI.encode_www_form_component('your-anti-forgery-token'))
10
10
 
@@ -2,6 +2,8 @@ require 'oj'
2
2
  require 'httpclient'
3
3
  require 'hashie'
4
4
  require 'addressable/template'
5
+ require 'jwt'
6
+ require 'securerandom'
5
7
 
6
8
  require 'boxr/version'
7
9
  require 'boxr/errors'
@@ -1,5 +1,7 @@
1
1
  module Boxr
2
2
 
3
+ JWT_GRANT_TYPE="urn:ietf:params:oauth:grant-type:jwt-bearer"
4
+
3
5
  def self.oauth_url(state, host: "app.box.com", response_type: "code", scope: nil, folder_id: nil, client_id: ENV['BOX_CLIENT_ID'])
4
6
  template = Addressable::Template.new("https://{host}/api/oauth2/authorize{?query*}")
5
7
 
@@ -22,6 +24,14 @@ module Boxr
22
24
  auth_post(uri, body)
23
25
  end
24
26
 
27
+ def self.get_enterprise_token(private_key, enterprise_id=ENV['BOX_ENTERPRISE_ID'], client_id=ENV['BOX_CLIENT_ID'])
28
+ jwt_auth_post(private_key, client_id, enterprise_id, "enterprise")
29
+ end
30
+
31
+ def self.get_user_token(private_key, user_id, client_id=ENV['BOX_CLIENT_ID'])
32
+ jwt_auth_post(private_key, client_id, user_id, "user")
33
+ end
34
+
25
35
  def self.refresh_tokens(refresh_token, client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
26
36
  uri = "https://api.box.com/oauth2/token"
27
37
  body = "grant_type=refresh_token&refresh_token=#{refresh_token}&client_id=#{client_id}&client_secret=#{client_secret}"
@@ -44,6 +54,20 @@ module Boxr
44
54
 
45
55
  private
46
56
 
57
+ def self.jwt_auth_post(private_key, iss, sub, box_sub_type)
58
+ payload = {
59
+ iss: iss,
60
+ sub: sub,
61
+ box_sub_type: box_sub_type,
62
+ aud: "https://api.box.com/oauth2/token",
63
+ jti: SecureRandom.hex(64),
64
+ exp: (Time.now.utc + 10).to_i
65
+ }
66
+ assertion = JWT.encode(payload, private_key, "RS256")
67
+
68
+ get_token(grant_type: JWT_GRANT_TYPE, assertion: assertion)
69
+ end
70
+
47
71
  def self.auth_post(uri, body)
48
72
  uri = Addressable::URI.encode(uri)
49
73
 
@@ -1,3 +1,3 @@
1
1
  module Boxr
2
- VERSION = "0.21.0"
2
+ VERSION = "0.22.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.21.0
4
+ version: 0.22.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-04-16 00:00:00.000000000 Z
11
+ date: 2015-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,20 +108,6 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.8'
111
- - !ruby/object:Gem::Dependency
112
- name: jwt
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '1.4'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '1.4'
125
111
  - !ruby/object:Gem::Dependency
126
112
  name: oj
127
113
  requirement: !ruby/object:Gem::Requirement
@@ -178,6 +164,20 @@ dependencies:
178
164
  - - "~>"
179
165
  - !ruby/object:Gem::Version
180
166
  version: '2.3'
167
+ - !ruby/object:Gem::Dependency
168
+ name: jwt
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '1.4'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '1.4'
181
181
  description: ''
182
182
  email:
183
183
  - chadburnette@me.com