boxr 0.20.0 → 0.21.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/bin/boxr +0 -0
- data/boxr.gemspec +1 -0
- data/examples/jwt_auth.rb +24 -0
- data/lib/boxr/auth.rb +17 -8
- data/lib/boxr/client.rb +5 -5
- data/lib/boxr/version.rb +1 -1
- metadata +17 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 3a3b6baa11b8ad38247f9656f13c408516e97388
         | 
| 4 | 
            +
              data.tar.gz: 3fcb4e8d3db3aff66811bc0132015e0e15f02096
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 1e75ef1039e90040d877590acac9a37986375492ca48cfe45dac8cdd1667b588b1ea61b53097366766545796fa8c3cf625cc4767e18291246df49992f165d6a2
         | 
| 7 | 
            +
              data.tar.gz: 58ce42b7bd7892c06647541e3d75b768c312d423e2f9ce7fb8d682398a4d428ec8864b00483364b280a1b12586368cea0fb40e16049f3737a50026eb13b48066
         | 
    
        data/bin/boxr
    CHANGED
    
    | 
            File without changes
         | 
    
        data/boxr.gemspec
    CHANGED
    
    | @@ -27,6 +27,7 @@ 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"
         | 
| 30 31 |  | 
| 31 32 | 
             
              spec.add_runtime_dependency "oj", "~> 2.11"
         | 
| 32 33 | 
             
              spec.add_runtime_dependency "httpclient", "~> 2.5"
         | 
| @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            require 'dotenv'; Dotenv.load("../.env")
         | 
| 2 | 
            +
            require 'boxr'
         | 
| 3 | 
            +
            require 'awesome_print'
         | 
| 4 | 
            +
            require 'jwt'
         | 
| 5 | 
            +
            require 'securerandom'
         | 
| 6 | 
            +
            require 'openssl'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
             | 
| 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"
         | 
| 11 | 
            +
             | 
| 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 | 
            +
            }
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            assertion = JWT.encode(payload, private_key, "RS256")
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            response = Boxr::get_token(grant_type: grant_type, assertion: assertion)
         | 
| 24 | 
            +
            ap response
         | 
    
        data/lib/boxr/auth.rb
    CHANGED
    
    | @@ -1,9 +1,9 @@ | |
| 1 1 | 
             
            module Boxr
         | 
| 2 2 |  | 
| 3 | 
            -
              def self.oauth_url(state, host: "app.box.com", response_type: "code", scope: nil, folder_id: nil,  | 
| 3 | 
            +
              def self.oauth_url(state, host: "app.box.com", response_type: "code", scope: nil, folder_id: nil, client_id: ENV['BOX_CLIENT_ID'])
         | 
| 4 4 | 
             
                template = Addressable::Template.new("https://{host}/api/oauth2/authorize{?query*}")
         | 
| 5 5 |  | 
| 6 | 
            -
                query = {"response_type" => "#{response_type}", "state" => "#{state}", "client_id" => "#{ | 
| 6 | 
            +
                query = {"response_type" => "#{response_type}", "state" => "#{state}", "client_id" => "#{client_id}"}
         | 
| 7 7 | 
             
                query["scope"] = "#{scope}" unless scope.nil?
         | 
| 8 8 | 
             
                query["folder_id"] = "#{folder_id}" unless folder_id.nil?
         | 
| 9 9 |  | 
| @@ -11,28 +11,37 @@ module Boxr | |
| 11 11 | 
             
                uri
         | 
| 12 12 | 
             
              end
         | 
| 13 13 |  | 
| 14 | 
            -
              def self.get_tokens(code, grant_type: "authorization_code", username: nil,  | 
| 14 | 
            +
              def self.get_tokens(code=nil, grant_type: "authorization_code", assertion: nil, scope: nil, username: nil, client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
         | 
| 15 15 | 
             
                uri = "https://api.box.com/oauth2/token"
         | 
| 16 | 
            -
                body = " | 
| 16 | 
            +
                body = "grant_type=#{grant_type}&client_id=#{client_id}&client_secret=#{client_secret}"
         | 
| 17 | 
            +
                body = body + "&code=#{code}" unless code.nil?
         | 
| 18 | 
            +
                body = body + "&scope=#{scope}" unless scope.nil?
         | 
| 17 19 | 
             
                body = body + "&username=#{username}" unless username.nil?
         | 
| 20 | 
            +
                body = body + "&assertion=#{assertion}" unless assertion.nil?
         | 
| 18 21 |  | 
| 19 22 | 
             
                auth_post(uri, body)
         | 
| 20 23 | 
             
              end
         | 
| 21 24 |  | 
| 22 | 
            -
              def self.refresh_tokens(refresh_token,  | 
| 25 | 
            +
              def self.refresh_tokens(refresh_token, client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
         | 
| 23 26 | 
             
                uri = "https://api.box.com/oauth2/token"
         | 
| 24 | 
            -
                body = "grant_type=refresh_token&refresh_token=#{refresh_token}&client_id=#{ | 
| 27 | 
            +
                body = "grant_type=refresh_token&refresh_token=#{refresh_token}&client_id=#{client_id}&client_secret=#{client_secret}"
         | 
| 25 28 |  | 
| 26 29 | 
             
                auth_post(uri, body)
         | 
| 27 30 | 
             
              end
         | 
| 28 31 |  | 
| 29 | 
            -
              def self.revoke_tokens(token,  | 
| 32 | 
            +
              def self.revoke_tokens(token, client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
         | 
| 30 33 | 
             
                uri = "https://api.box.com/oauth2/revoke"
         | 
| 31 | 
            -
                body = "client_id=#{ | 
| 34 | 
            +
                body = "client_id=#{client_id}&client_secret=#{client_secret}&token=#{token}"
         | 
| 32 35 |  | 
| 33 36 | 
             
                auth_post(uri, body)
         | 
| 34 37 | 
             
              end
         | 
| 35 38 |  | 
| 39 | 
            +
              class << self
         | 
| 40 | 
            +
                alias :get_token :get_tokens
         | 
| 41 | 
            +
                alias :refresh_token :refresh_tokens
         | 
| 42 | 
            +
                alias :revoke_token :revoke_tokens
         | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
             | 
| 36 45 | 
             
              private
         | 
| 37 46 |  | 
| 38 47 | 
             
              def self.auth_post(uri, body)
         | 
    
        data/lib/boxr/client.rb
    CHANGED
    
    | @@ -2,7 +2,7 @@ module Boxr | |
| 2 2 |  | 
| 3 3 | 
             
              class Client
         | 
| 4 4 |  | 
| 5 | 
            -
                attr_reader :access_token, :refresh_token, : | 
| 5 | 
            +
                attr_reader :access_token, :refresh_token, :client_id, :client_secret, :identifier, :as_user_id
         | 
| 6 6 |  | 
| 7 7 | 
             
                API_URI = "https://api.box.com/2.0"
         | 
| 8 8 | 
             
                UPLOAD_URI = "https://upload.box.com/api/2.0"
         | 
| @@ -53,14 +53,14 @@ module Boxr | |
| 53 53 | 
             
                VALID_COLLABORATION_ROLES = ['editor','viewer','previewer','uploader','previewer uploader','viewer uploader','co-owner','owner']
         | 
| 54 54 |  | 
| 55 55 |  | 
| 56 | 
            -
                def initialize(access_token=ENV['BOX_DEVELOPER_TOKEN'], refresh_token: nil,  | 
| 56 | 
            +
                def initialize(access_token=ENV['BOX_DEVELOPER_TOKEN'], refresh_token: nil, client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'], 
         | 
| 57 57 | 
             
                                identifier: nil, as_user: nil, &token_refresh_listener)
         | 
| 58 58 | 
             
                  @access_token = access_token
         | 
| 59 59 | 
             
                  raise BoxrError.new(boxr_message: "Access token cannot be nil") if @access_token.nil?
         | 
| 60 60 |  | 
| 61 61 | 
             
                  @refresh_token = refresh_token
         | 
| 62 | 
            -
                  @ | 
| 63 | 
            -
                  @ | 
| 62 | 
            +
                  @client_id = client_id
         | 
| 63 | 
            +
                  @client_secret = client_secret
         | 
| 64 64 | 
             
                  @identifier = identifier
         | 
| 65 65 | 
             
                  @as_user_id = ensure_id(as_user)
         | 
| 66 66 | 
             
                  @token_refresh_listener = token_refresh_listener
         | 
| @@ -190,7 +190,7 @@ module Boxr | |
| 190 190 | 
             
                  if res.status == 401
         | 
| 191 191 | 
             
                    auth_header = res.header['WWW-Authenticate'][0]
         | 
| 192 192 | 
             
                    if auth_header && auth_header.include?('invalid_token')
         | 
| 193 | 
            -
                      new_tokens = Boxr::refresh_tokens(@refresh_token,  | 
| 193 | 
            +
                      new_tokens = Boxr::refresh_tokens(@refresh_token, client_id: client_id, client_secret: client_secret)
         | 
| 194 194 | 
             
                      @access_token = new_tokens.access_token
         | 
| 195 195 | 
             
                      @refresh_token = new_tokens.refresh_token
         | 
| 196 196 | 
             
                      @token_refresh_listener.call(@access_token, @refresh_token, @identifier) if @token_refresh_listener
         | 
    
        data/lib/boxr/version.rb
    CHANGED
    
    
    
        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. | 
| 4 | 
            +
              version: 0.21.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- | 
| 11 | 
            +
            date: 2015-04-16 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -108,6 +108,20 @@ 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'
         | 
| 111 125 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 112 126 | 
             
              name: oj
         | 
| 113 127 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -181,6 +195,7 @@ files: | |
| 181 195 | 
             
            - bin/boxr
         | 
| 182 196 | 
             
            - boxr.gemspec
         | 
| 183 197 | 
             
            - examples/enterprise_events.rb
         | 
| 198 | 
            +
            - examples/jwt_auth.rb
         | 
| 184 199 | 
             
            - examples/oauth.rb
         | 
| 185 200 | 
             
            - examples/use_events_to_send_sms.rb
         | 
| 186 201 | 
             
            - examples/use_events_to_warn_about_sharing.rb
         |