adsk_auth_service 1.0.1 → 1.0.2
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/Gemfile +2 -1
- data/adsk_auth_service.gemspec +14 -5
- data/lib/adsk_auth_service.rb +10 -2
- data/lib/caches/mc_cache.rb +42 -0
- data/lib/services/config_service.rb +30 -0
- data/lib/services/token_cache_service.rb +44 -0
- data/lib/utils/net_util.rb +0 -2
- metadata +61 -5
- data/conf/auth_keys.example.yml +0 -25
- data/spec/rspec_helper.rb +0 -6
- data/spec/services/auth_service_spec.rb +0 -26
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 3cb5e95ef1b397e51967320a3809d7ab3c3a6783
         | 
| 4 | 
            +
              data.tar.gz: bb1e2dbbbbce8684d4c7d4bc5272038e2663728f
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: b12800b6e40701cd2c08c537b52b682be70ddadbcd0a4b7bb104bcc9b4d076ae2bc48218e6344c69bb32e3e42d957ef768f6ba79b50232b862d86dd322725728
         | 
| 7 | 
            +
              data.tar.gz: d51e7e73505e28154ec20843349d04635260e61b8e93f706f471fd42e6d27986823647c28ec831e263fb78826497418a09043eb31708e33411e067ca962d3110
         | 
    
        data/Gemfile
    CHANGED
    
    
    
        data/adsk_auth_service.gemspec
    CHANGED
    
    | @@ -1,15 +1,24 @@ | |
| 1 1 | 
             
            Gem::Specification.new do |s|
         | 
| 2 2 | 
             
              s.name        = 'adsk_auth_service'
         | 
| 3 | 
            -
              s.version     = '1.0. | 
| 3 | 
            +
              s.version     = '1.0.2'
         | 
| 4 4 | 
             
              s.summary     = "Autodesk second phase token retrieval"
         | 
| 5 5 | 
             
              s.description = "A gem for Autodesk 2-phase authentication service."
         | 
| 6 6 | 
             
              s.authors     = ['Linh Chau']
         | 
| 7 7 | 
             
              s.email       = 'chauhonglinh@gmail.com'
         | 
| 8 8 | 
             
              s.files       = [
         | 
| 9 | 
            -
                                './Gemfile', './adsk_auth_service.gemspec',  | 
| 10 | 
            -
                                'lib/ | 
| 11 | 
            -
                                ' | 
| 9 | 
            +
                                './Gemfile', './adsk_auth_service.gemspec', 
         | 
| 10 | 
            +
                                'lib/adsk_auth_service.rb',
         | 
| 11 | 
            +
                                'lib/services/auth_service.rb', 'lib/services/config_service.rb', 
         | 
| 12 | 
            +
                                'lib/services/sdk_logger.rb', 'lib/services/token_cache_service.rb',
         | 
| 13 | 
            +
                                'lib/caches/mc_cache.rb',
         | 
| 14 | 
            +
                                'lib/utils/net_util.rb',
         | 
| 15 | 
            +
                                
         | 
| 12 16 | 
             
                              ]
         | 
| 13 17 | 
             
              s.homepage    = 'https://git.autodesk.com/t-chaul/adsk_auth_service.git'
         | 
| 14 18 | 
             
              s.license     = 'MIT'
         | 
| 15 | 
            -
             | 
| 19 | 
            +
              s.add_runtime_dependency 'logging', '~> 0'
         | 
| 20 | 
            +
              s.add_runtime_dependency 'activesupport'
         | 
| 21 | 
            +
              s.add_runtime_dependency 'dalli', '~> 0'  
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              s.add_development_dependency 'rspec', '~> 3.1'
         | 
| 24 | 
            +
            end
         | 
    
        data/lib/adsk_auth_service.rb
    CHANGED
    
    | @@ -1,5 +1,13 @@ | |
| 1 1 | 
             
            require 'yaml'
         | 
| 2 | 
            +
            require_relative 'services/config_service'
         | 
| 2 3 |  | 
| 3 | 
            -
            [' | 
| 4 | 
            -
               | 
| 4 | 
            +
            ['caches', 'services', 'utils'].each do |sub_path|
         | 
| 5 | 
            +
              rb_files =  Dir.glob("#{File.expand_path('.')}/lib/#{sub_path}/*.rb")
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              if rb_files.empty?
         | 
| 8 | 
            +
                spec = Gem::Specification.find_by_name('adsk_auth_service')
         | 
| 9 | 
            +
                rb_files =  Dir.glob("#{spec.gem_dir}/lib/#{sub_path}/*.rb")
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
              
         | 
| 12 | 
            +
              rb_files.each { |rb_file| require rb_file }
         | 
| 5 13 | 
             
            end
         | 
| @@ -0,0 +1,42 @@ | |
| 1 | 
            +
            require 'dalli'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class McCache
         | 
| 4 | 
            +
              class << self
         | 
| 5 | 
            +
                def client
         | 
| 6 | 
            +
                  @@client
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def initialize
         | 
| 10 | 
            +
                  @@env  = ConfigService.environment
         | 
| 11 | 
            +
                  config = ConfigService.load_config('memcached.yml')[@@env]
         | 
| 12 | 
            +
                  host = config['host']
         | 
| 13 | 
            +
                  options = config.dup
         | 
| 14 | 
            +
                  options.delete('host')
         | 
| 15 | 
            +
                  @@client = Dalli::Client.new(host, options)
         | 
| 16 | 
            +
                end #initialize
         | 
| 17 | 
            +
             | 
| 18 | 
            +
             | 
| 19 | 
            +
                # Cache API, mimics ActiveSupport::Cache::Store
         | 
| 20 | 
            +
                # http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def read(key, options = {})
         | 
| 23 | 
            +
                  client.get(key, options)
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                def write(key, value, options = {})
         | 
| 27 | 
            +
                  client.set(key, value, options[:expires_in], options)
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                def delete(key, options = {})
         | 
| 31 | 
            +
                  deleted = read(key)
         | 
| 32 | 
            +
                  client.delete(key)
         | 
| 33 | 
            +
                  deleted
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                def token_key
         | 
| 37 | 
            +
                  "#{@@env}_token_data"
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
              end #class methods
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              initialize
         | 
| 42 | 
            +
            end
         | 
| @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            require 'active_support'
         | 
| 2 | 
            +
            require 'active_support/core_ext'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class ConfigService
         | 
| 5 | 
            +
              class << self
         | 
| 6 | 
            +
                def load_config(config_file_name)
         | 
| 7 | 
            +
                  app_root = (defined? APP_ROOT)? APP_ROOT : File.expand_path('.')
         | 
| 8 | 
            +
                  
         | 
| 9 | 
            +
                  config_file = nil
         | 
| 10 | 
            +
                  ['conf', 'config'].each do |sub_path|
         | 
| 11 | 
            +
                    if File.exist?("#{app_root}/#{sub_path}/#{config_file_name}")
         | 
| 12 | 
            +
                      config_file = "#{app_root}/#{sub_path}/#{config_file_name}"
         | 
| 13 | 
            +
                      break
         | 
| 14 | 
            +
                    end
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
                  
         | 
| 17 | 
            +
                  raise("You must have the file #{config_file_name} in either 'conf' or 'config' directory of your application") unless config_file
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  YAML.load_file(config_file)
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def environment
         | 
| 23 | 
            +
                  return Rails.env if defined? Rails
         | 
| 24 | 
            +
                  return ENV['RACK_ENV'] if ENV['RACK_ENV'].present?
         | 
| 25 | 
            +
                  'local'
         | 
| 26 | 
            +
                rescue => error
         | 
| 27 | 
            +
                  'local'
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
              end # class methods
         | 
| 30 | 
            +
            end
         | 
| @@ -0,0 +1,44 @@ | |
| 1 | 
            +
            require 'adsk_auth_service'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require_relative './config_service'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            class TokenCacheService
         | 
| 6 | 
            +
              class << self
         | 
| 7 | 
            +
                def cache
         | 
| 8 | 
            +
                  # The cache supports the following API functions:
         | 
| 9 | 
            +
                  #   - read(key, options = {})
         | 
| 10 | 
            +
                  #   - write(key, value, options = {})
         | 
| 11 | 
            +
                  #   - delete(key, options = {})
         | 
| 12 | 
            +
                  #   - token_key
         | 
| 13 | 
            +
                  @@cache
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                def cache=(other_cache)
         | 
| 17 | 
            +
                  @@cache = other_cache
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                def initialize
         | 
| 21 | 
            +
                  @@env  = ConfigService.environment
         | 
| 22 | 
            +
                  config = ConfigService.load_config('cache_config.yml')[@@env]
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  @@cache = Object.const_get(config['cache'])
         | 
| 25 | 
            +
                  
         | 
| 26 | 
            +
                end #initialize
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                 def get_token
         | 
| 29 | 
            +
                  token_data = cache.read(cache.token_key)
         | 
| 30 | 
            +
                  if token_data.nil?
         | 
| 31 | 
            +
                    token_data = AuthService.oauth_token
         | 
| 32 | 
            +
                    set_token(token_data)
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
                  token_data
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                def set_token(token_data)
         | 
| 38 | 
            +
                  cache.write(cache.token_key, token_data, { expires_in: token_data['expires_in'].to_i })
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
               
         | 
| 41 | 
            +
              end #class methods
         | 
| 42 | 
            +
             | 
| 43 | 
            +
              initialize
         | 
| 44 | 
            +
            end
         | 
    
        data/lib/utils/net_util.rb
    CHANGED
    
    | @@ -82,9 +82,7 @@ class NetUtil | |
| 82 82 | 
             
              end
         | 
| 83 83 |  | 
| 84 84 | 
             
              def NetUtil.set_ssl(request, url)
         | 
| 85 | 
            -
                SdkLogger.logger.debug("URL is #{url}")
         | 
| 86 85 | 
             
                if url.start_with? 'https'
         | 
| 87 | 
            -
                  SdkLogger.logger.debug("Use https - URL is #{url}")
         | 
| 88 86 | 
             
                  request.use_ssl = true 
         | 
| 89 87 | 
             
                  request.verify_mode = OpenSSL::SSL::VERIFY_NONE
         | 
| 90 88 | 
             
                end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: adsk_auth_service
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0. | 
| 4 | 
            +
              version: 1.0.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Linh Chau
         | 
| @@ -9,7 +9,63 @@ autorequire: | |
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 11 | 
             
            date: 2014-11-16 00:00:00.000000000 Z
         | 
| 12 | 
            -
            dependencies: | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: logging
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '0'
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '0'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: activesupport
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - ">="
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '0'
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - ">="
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: dalli
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - "~>"
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0'
         | 
| 48 | 
            +
              type: :runtime
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - "~>"
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0'
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: rspec
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - "~>"
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '3.1'
         | 
| 62 | 
            +
              type: :development
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - "~>"
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: '3.1'
         | 
| 13 69 | 
             
            description: A gem for Autodesk 2-phase authentication service.
         | 
| 14 70 | 
             
            email: chauhonglinh@gmail.com
         | 
| 15 71 | 
             
            executables: []
         | 
| @@ -18,13 +74,13 @@ extra_rdoc_files: [] | |
| 18 74 | 
             
            files:
         | 
| 19 75 | 
             
            - "./Gemfile"
         | 
| 20 76 | 
             
            - "./adsk_auth_service.gemspec"
         | 
| 21 | 
            -
            - conf/auth_keys.example.yml
         | 
| 22 77 | 
             
            - lib/adsk_auth_service.rb
         | 
| 78 | 
            +
            - lib/caches/mc_cache.rb
         | 
| 23 79 | 
             
            - lib/services/auth_service.rb
         | 
| 80 | 
            +
            - lib/services/config_service.rb
         | 
| 24 81 | 
             
            - lib/services/sdk_logger.rb
         | 
| 82 | 
            +
            - lib/services/token_cache_service.rb
         | 
| 25 83 | 
             
            - lib/utils/net_util.rb
         | 
| 26 | 
            -
            - spec/rspec_helper.rb
         | 
| 27 | 
            -
            - spec/services/auth_service_spec.rb
         | 
| 28 84 | 
             
            homepage: https://git.autodesk.com/t-chaul/adsk_auth_service.git
         | 
| 29 85 | 
             
            licenses:
         | 
| 30 86 | 
             
            - MIT
         | 
    
        data/conf/auth_keys.example.yml
    DELETED
    
    | @@ -1,25 +0,0 @@ | |
| 1 | 
            -
            local:
         | 
| 2 | 
            -
              consumer_key: YOUR_CONSUMER_KEY
         | 
| 3 | 
            -
              consumer_secret: YOUR_CONSUMER_SECRET
         | 
| 4 | 
            -
              url: https://developer-dev.api.autodesk.com/authentication/v1/authenticate
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            development:
         | 
| 7 | 
            -
              consumer_key: YOUR_CONSUMER_KEY
         | 
| 8 | 
            -
              consumer_secret: YOUR_CONSUMER_SECRET
         | 
| 9 | 
            -
              url: https://developer-dev.api.autodesk.com/authentication/v1/authenticate
         | 
| 10 | 
            -
             | 
| 11 | 
            -
            test:
         | 
| 12 | 
            -
              consumer_key: YOUR_CONSUMER_KEY
         | 
| 13 | 
            -
              consumer_secret: YOUR_CONSUMER_SECRET
         | 
| 14 | 
            -
              url: https://developer-dev.api.autodesk.com/authentication/v1/authenticate
         | 
| 15 | 
            -
             | 
| 16 | 
            -
            stage:
         | 
| 17 | 
            -
              consumer_key: YOUR_CONSUMER_KEY
         | 
| 18 | 
            -
              consumer_secret: YOUR_CONSUMER_SECRET
         | 
| 19 | 
            -
              url: https://developer-stg.api.autodesk.com/authentication/v1/authenticate
         | 
| 20 | 
            -
             | 
| 21 | 
            -
            production:
         | 
| 22 | 
            -
              consumer_key: YOUR_CONSUMER_KEY
         | 
| 23 | 
            -
              consumer_secret: YOUR_CONSUMER_SECRET
         | 
| 24 | 
            -
              url: https://developer.api.autodesk.com/authentication/v1/authenticate
         | 
| 25 | 
            -
             | 
    
        data/spec/rspec_helper.rb
    DELETED
    
    
| @@ -1,26 +0,0 @@ | |
| 1 | 
            -
            require_relative('../rspec_helper')
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            describe AuthService do
         | 
| 4 | 
            -
              context 'load_config' do
         | 
| 5 | 
            -
                it 'load config from YAML file' do
         | 
| 6 | 
            -
                  config = AuthService.load_config
         | 
| 7 | 
            -
                  expect(config).not_to be_nil
         | 
| 8 | 
            -
                  expect(config.is_a? Hash).to eql(true)
         | 
| 9 | 
            -
                end
         | 
| 10 | 
            -
              end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
              context 'oauth_token' do
         | 
| 13 | 
            -
                it 'returns auth token' do
         | 
| 14 | 
            -
                  token_data = AuthService.oauth_token
         | 
| 15 | 
            -
                  puts("Token #{token_data}")
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                  # token_data['access_token'] is the real token
         | 
| 18 | 
            -
                  expect(token_data).not_to be_nil
         | 
| 19 | 
            -
                  expect(token_data.is_a? Hash).to eql(true)
         | 
| 20 | 
            -
                  expect(token_data['token_type']).not_to be_nil
         | 
| 21 | 
            -
                  expect(token_data['expires_in']).not_to be_nil
         | 
| 22 | 
            -
                  expect(token_data['access_token']).not_to be_nil
         | 
| 23 | 
            -
                end
         | 
| 24 | 
            -
              end
         | 
| 25 | 
            -
             | 
| 26 | 
            -
            end
         |