grape_oauth2 0.1.1 → 0.2.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/.gitignore +11 -11
 - data/Gemfile +23 -23
 - data/Rakefile +11 -11
 - data/grape_oauth2.gemspec +26 -27
 - data/lib/grape_oauth2.rb +129 -129
 - data/lib/grape_oauth2/configuration.rb +143 -143
 - data/lib/grape_oauth2/configuration/class_accessors.rb +36 -36
 - data/lib/grape_oauth2/configuration/validation.rb +71 -71
 - data/lib/grape_oauth2/endpoints/authorize.rb +34 -34
 - data/lib/grape_oauth2/endpoints/token.rb +72 -72
 - data/lib/grape_oauth2/gem_version.rb +24 -24
 - data/lib/grape_oauth2/generators/authorization.rb +44 -44
 - data/lib/grape_oauth2/generators/base.rb +26 -26
 - data/lib/grape_oauth2/generators/token.rb +62 -62
 - data/lib/grape_oauth2/helpers/access_token_helpers.rb +52 -54
 - data/lib/grape_oauth2/helpers/oauth_params.rb +41 -41
 - data/lib/grape_oauth2/mixins/active_record/access_grant.rb +47 -47
 - data/lib/grape_oauth2/mixins/active_record/access_token.rb +75 -75
 - data/lib/grape_oauth2/mixins/active_record/client.rb +36 -35
 - data/lib/grape_oauth2/mixins/mongoid/access_grant.rb +58 -58
 - data/lib/grape_oauth2/mixins/mongoid/access_token.rb +88 -88
 - data/lib/grape_oauth2/mixins/mongoid/client.rb +44 -41
 - data/lib/grape_oauth2/mixins/sequel/access_grant.rb +68 -68
 - data/lib/grape_oauth2/mixins/sequel/access_token.rb +86 -86
 - data/lib/grape_oauth2/mixins/sequel/client.rb +54 -46
 - data/lib/grape_oauth2/responses/authorization.rb +11 -10
 - data/lib/grape_oauth2/responses/base.rb +56 -56
 - data/lib/grape_oauth2/responses/token.rb +10 -10
 - data/lib/grape_oauth2/scopes.rb +74 -74
 - data/lib/grape_oauth2/strategies/authorization_code.rb +38 -38
 - data/lib/grape_oauth2/strategies/base.rb +47 -47
 - data/lib/grape_oauth2/strategies/client_credentials.rb +20 -20
 - data/lib/grape_oauth2/strategies/password.rb +22 -22
 - data/lib/grape_oauth2/strategies/refresh_token.rb +47 -47
 - data/lib/grape_oauth2/unique_token.rb +20 -20
 - data/lib/grape_oauth2/version.rb +14 -14
 - data/spec/configuration/config_spec.rb +231 -231
 - data/spec/configuration/version_spec.rb +12 -12
 - data/spec/dummy/endpoints/custom_authorization.rb +25 -25
 - data/spec/dummy/endpoints/custom_token.rb +35 -35
 - data/spec/dummy/endpoints/status.rb +25 -25
 - data/spec/dummy/grape_oauth2_config.rb +11 -11
 - data/spec/dummy/orm/active_record/app/config/db.rb +7 -7
 - data/spec/dummy/orm/active_record/app/models/access_code.rb +3 -3
 - data/spec/dummy/orm/active_record/app/models/access_token.rb +3 -3
 - data/spec/dummy/orm/active_record/app/models/application.rb +3 -3
 - data/spec/dummy/orm/active_record/app/models/application_record.rb +3 -3
 - data/spec/dummy/orm/active_record/app/models/user.rb +10 -10
 - data/spec/dummy/orm/active_record/app/twitter.rb +36 -36
 - data/spec/dummy/orm/active_record/config.ru +7 -7
 - data/spec/dummy/orm/active_record/db/schema.rb +53 -53
 - data/spec/dummy/orm/mongoid/app/config/db.rb +6 -6
 - data/spec/dummy/orm/mongoid/app/config/mongoid.yml +21 -21
 - data/spec/dummy/orm/mongoid/app/models/access_code.rb +3 -3
 - data/spec/dummy/orm/mongoid/app/models/access_token.rb +3 -3
 - data/spec/dummy/orm/mongoid/app/models/application.rb +3 -3
 - data/spec/dummy/orm/mongoid/app/models/user.rb +11 -11
 - data/spec/dummy/orm/mongoid/app/twitter.rb +34 -34
 - data/spec/dummy/orm/mongoid/config.ru +5 -5
 - data/spec/dummy/orm/sequel/app/config/db.rb +1 -1
 - data/spec/dummy/orm/sequel/app/models/access_code.rb +4 -4
 - data/spec/dummy/orm/sequel/app/models/access_token.rb +4 -4
 - data/spec/dummy/orm/sequel/app/models/application.rb +4 -4
 - data/spec/dummy/orm/sequel/app/models/application_record.rb +2 -2
 - data/spec/dummy/orm/sequel/app/models/user.rb +11 -11
 - data/spec/dummy/orm/sequel/app/twitter.rb +47 -47
 - data/spec/dummy/orm/sequel/config.ru +5 -5
 - data/spec/dummy/orm/sequel/db/schema.rb +50 -50
 - data/spec/lib/scopes_spec.rb +50 -50
 - data/spec/mixins/active_record/access_token_spec.rb +185 -185
 - data/spec/mixins/active_record/client_spec.rb +104 -95
 - data/spec/mixins/mongoid/access_token_spec.rb +185 -185
 - data/spec/mixins/mongoid/client_spec.rb +104 -95
 - data/spec/mixins/sequel/access_token_spec.rb +185 -185
 - data/spec/mixins/sequel/client_spec.rb +105 -96
 - data/spec/requests/flows/authorization_code_spec.rb +67 -67
 - data/spec/requests/flows/client_credentials_spec.rb +101 -101
 - data/spec/requests/flows/password_spec.rb +210 -210
 - data/spec/requests/flows/refresh_token_spec.rb +222 -222
 - data/spec/requests/flows/revoke_token_spec.rb +103 -103
 - data/spec/requests/protected_resources_spec.rb +64 -64
 - data/spec/spec_helper.rb +60 -60
 - data/spec/support/api_helper.rb +11 -11
 - metadata +50 -52
 - data/.rspec +0 -2
 - data/.rubocop.yml +0 -18
 - data/.travis.yml +0 -42
 - data/README.md +0 -820
 - data/gemfiles/active_record.rb +0 -25
 - data/gemfiles/mongoid.rb +0 -14
 - data/gemfiles/sequel.rb +0 -24
 - data/grape_oauth2.png +0 -0
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: f8be2fa7c44c5993c1517344c6ececa9057a1977
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: b84d3fd751304e035128c215da6f028092c3298f
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 61b111e324a6e707c84ba24fcdf9d9a867b57ae88954b66fcb0950880ce69fc43606d0cf76a45c1160e386e73c8c78fadf126b7a130afb02f2697870cfeced24
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 0063cecbf7445cb61fbb58bb84efb21fe7b9b05cb868916333c4b0e7ea442898ba1e2fd6161abaf770d28c366714f63305a20bd660675013441ce88a1c7daba1
         
     | 
    
        data/.gitignore
    CHANGED
    
    | 
         @@ -1,11 +1,11 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            .bundle/
         
     | 
| 
       2 
     | 
    
         
            -
            .rbx
         
     | 
| 
       3 
     | 
    
         
            -
            *.rbc
         
     | 
| 
       4 
     | 
    
         
            -
            log/*.log
         
     | 
| 
       5 
     | 
    
         
            -
            .rvmrc
         
     | 
| 
       6 
     | 
    
         
            -
            /.idea
         
     | 
| 
       7 
     | 
    
         
            -
            gemfiles/*.lock
         
     | 
| 
       8 
     | 
    
         
            -
            Gemfile.lock
         
     | 
| 
       9 
     | 
    
         
            -
            coverage/
         
     | 
| 
       10 
     | 
    
         
            -
            .yardoc/
         
     | 
| 
       11 
     | 
    
         
            -
            doc/
         
     | 
| 
      
 1 
     | 
    
         
            +
            .bundle/
         
     | 
| 
      
 2 
     | 
    
         
            +
            .rbx
         
     | 
| 
      
 3 
     | 
    
         
            +
            *.rbc
         
     | 
| 
      
 4 
     | 
    
         
            +
            log/*.log
         
     | 
| 
      
 5 
     | 
    
         
            +
            .rvmrc
         
     | 
| 
      
 6 
     | 
    
         
            +
            /.idea
         
     | 
| 
      
 7 
     | 
    
         
            +
            gemfiles/*.lock
         
     | 
| 
      
 8 
     | 
    
         
            +
            Gemfile.lock
         
     | 
| 
      
 9 
     | 
    
         
            +
            coverage/
         
     | 
| 
      
 10 
     | 
    
         
            +
            .yardoc/
         
     | 
| 
      
 11 
     | 
    
         
            +
            doc/
         
     | 
    
        data/Gemfile
    CHANGED
    
    | 
         @@ -1,23 +1,23 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            source 'https://rubygems.org'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            gemspec
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            gem 'grape', '~> 0 
     | 
| 
       6 
     | 
    
         
            -
            gem 'rack-oauth2'
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
            gem 'activerecord'
         
     | 
| 
       9 
     | 
    
         
            -
            gem 'bcrypt'
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
            group :test do
         
     | 
| 
       12 
     | 
    
         
            -
              platforms :ruby, :mswin, :mswin64, :mingw, :x64_mingw do
         
     | 
| 
       13 
     | 
    
         
            -
                gem 'sqlite3'
         
     | 
| 
       14 
     | 
    
         
            -
              end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
              gem ' 
     | 
| 
       17 
     | 
    
         
            -
              gem ' 
     | 
| 
       18 
     | 
    
         
            -
              gem ' 
     | 
| 
       19 
     | 
    
         
            -
              gem 'rack-test', require: 'rack/test'
         
     | 
| 
       20 
     | 
    
         
            -
              gem ' 
     | 
| 
       21 
     | 
    
         
            -
            end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
            gem 'tzinfo-data', platforms: [ 
     | 
| 
      
 1 
     | 
    
         
            +
            source 'https://rubygems.org'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            gemspec
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            gem 'grape', '~> 1.0'
         
     | 
| 
      
 6 
     | 
    
         
            +
            gem 'rack-oauth2'
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            gem 'activerecord'
         
     | 
| 
      
 9 
     | 
    
         
            +
            gem 'bcrypt'
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            group :test do
         
     | 
| 
      
 12 
     | 
    
         
            +
              platforms :ruby, :mswin, :mswin64, :mingw, :x64_mingw do
         
     | 
| 
      
 13 
     | 
    
         
            +
                gem 'sqlite3'
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              gem 'coveralls', require: false
         
     | 
| 
      
 17 
     | 
    
         
            +
              gem 'database_cleaner'
         
     | 
| 
      
 18 
     | 
    
         
            +
              gem 'otr-activerecord'
         
     | 
| 
      
 19 
     | 
    
         
            +
              gem 'rack-test', require: 'rack/test'
         
     | 
| 
      
 20 
     | 
    
         
            +
              gem 'rspec-rails', '~> 3.5'
         
     | 
| 
      
 21 
     | 
    
         
            +
            end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
         
     | 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -1,11 +1,11 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'bundler/setup'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'rspec/core/rake_task'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            desc 'Default: run specs.'
         
     | 
| 
       5 
     | 
    
         
            -
            task default: :spec
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
            RSpec::Core::RakeTask.new(:spec) do |config|
         
     | 
| 
       8 
     | 
    
         
            -
              config.verbose = false
         
     | 
| 
       9 
     | 
    
         
            -
            end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
            Bundler::GemHelper.install_tasks
         
     | 
| 
      
 1 
     | 
    
         
            +
            require 'bundler/setup'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'rspec/core/rake_task'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            desc 'Default: run specs.'
         
     | 
| 
      
 5 
     | 
    
         
            +
            task default: :spec
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            RSpec::Core::RakeTask.new(:spec) do |config|
         
     | 
| 
      
 8 
     | 
    
         
            +
              config.verbose = false
         
     | 
| 
      
 9 
     | 
    
         
            +
            end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            Bundler::GemHelper.install_tasks
         
     | 
    
        data/grape_oauth2.gemspec
    CHANGED
    
    | 
         @@ -1,27 +1,26 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            $LOAD_PATH.push File.expand_path('../lib', __FILE__)
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            require 'grape_oauth2/version'
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            Gem::Specification.new do |gem|
         
     | 
| 
       6 
     | 
    
         
            -
              gem.name        = 'grape_oauth2'
         
     | 
| 
       7 
     | 
    
         
            -
              gem.version     = Grape::OAuth2.gem_version
         
     | 
| 
       8 
     | 
    
         
            -
              gem.authors     = ['Nikita Bulai']
         
     | 
| 
       9 
     | 
    
         
            -
              gem. 
     | 
| 
       10 
     | 
    
         
            -
              gem. 
     | 
| 
       11 
     | 
    
         
            -
              gem. 
     | 
| 
       12 
     | 
    
         
            -
              gem. 
     | 
| 
       13 
     | 
    
         
            -
              gem. 
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
              gem. 
     | 
| 
       17 
     | 
    
         
            -
              gem. 
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
              gem.add_runtime_dependency ' 
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
              gem.add_development_dependency ' 
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            $LOAD_PATH.push File.expand_path('../lib', __FILE__)
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'grape_oauth2/version'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            Gem::Specification.new do |gem|
         
     | 
| 
      
 6 
     | 
    
         
            +
              gem.name        = 'grape_oauth2'
         
     | 
| 
      
 7 
     | 
    
         
            +
              gem.version     = Grape::OAuth2.gem_version
         
     | 
| 
      
 8 
     | 
    
         
            +
              gem.authors     = ['Nikita Bulai']
         
     | 
| 
      
 9 
     | 
    
         
            +
              gem.email       = ['bulajnikita@gmail.com']
         
     | 
| 
      
 10 
     | 
    
         
            +
              gem.homepage    = 'http://github.com/nbulaj/grape-oauth2'
         
     | 
| 
      
 11 
     | 
    
         
            +
              gem.summary     = 'Grape OAuth2 provider'
         
     | 
| 
      
 12 
     | 
    
         
            +
              gem.description = 'Flexible, ORM-agnostic, fully customizable and simple OAuth2 provider support for Grape APIs'
         
     | 
| 
      
 13 
     | 
    
         
            +
              gem.license     = 'MIT'
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              gem.require_paths = %w[lib]
         
     | 
| 
      
 16 
     | 
    
         
            +
              gem.files = `git ls-files`.split($RS).reject { |f| f.include?('gemfiles') } - ['README.md', 'grape_oauth2.png', '.rspec', '.travis.yml', '.rubocop.yml']
         
     | 
| 
      
 17 
     | 
    
         
            +
              gem.test_files = Dir['spec/**/*']
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              gem.required_ruby_version = '>= 2.2.2'
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              gem.add_runtime_dependency 'grape', '~> 1.0', '>= 1.0'
         
     | 
| 
      
 22 
     | 
    
         
            +
              gem.add_runtime_dependency 'rack-oauth2', '~> 1.6.0', '>= 1.6.0'
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
              gem.add_development_dependency 'rspec-rails', '~> 3.6.0', '>= 3.6.0'
         
     | 
| 
      
 25 
     | 
    
         
            +
              gem.add_development_dependency 'database_cleaner', '~> 1.5.0', '>= 1.5.0'
         
     | 
| 
      
 26 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/grape_oauth2.rb
    CHANGED
    
    | 
         @@ -1,129 +1,129 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'grape'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'rack/oauth2'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            require 'grape_oauth2/version'
         
     | 
| 
       5 
     | 
    
         
            -
            require 'grape_oauth2/configuration/validation'
         
     | 
| 
       6 
     | 
    
         
            -
            require 'grape_oauth2/configuration/class_accessors'
         
     | 
| 
       7 
     | 
    
         
            -
            require 'grape_oauth2/configuration'
         
     | 
| 
       8 
     | 
    
         
            -
            require 'grape_oauth2/scopes'
         
     | 
| 
       9 
     | 
    
         
            -
            require 'grape_oauth2/unique_token'
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
            # NOTE: Extract to separate gems!!!
         
     | 
| 
       12 
     | 
    
         
            -
            # This gem should contains only the core functionality and all mixins
         
     | 
| 
       13 
     | 
    
         
            -
            # need to be moved to their own repos with their own tests.
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
            # Mixins
         
     | 
| 
       16 
     | 
    
         
            -
            if defined?(ActiveRecord::Base)
         
     | 
| 
       17 
     | 
    
         
            -
              require 'grape_oauth2/mixins/active_record/access_token'
         
     | 
| 
       18 
     | 
    
         
            -
              require 'grape_oauth2/mixins/active_record/access_grant'
         
     | 
| 
       19 
     | 
    
         
            -
              require 'grape_oauth2/mixins/active_record/client'
         
     | 
| 
       20 
     | 
    
         
            -
            end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
            if defined?(Sequel::Model)
         
     | 
| 
       23 
     | 
    
         
            -
              require 'grape_oauth2/mixins/sequel/access_token'
         
     | 
| 
       24 
     | 
    
         
            -
              require 'grape_oauth2/mixins/sequel/access_grant'
         
     | 
| 
       25 
     | 
    
         
            -
              require 'grape_oauth2/mixins/sequel/client'
         
     | 
| 
       26 
     | 
    
         
            -
            end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
            if defined?(Mongoid::Document)
         
     | 
| 
       29 
     | 
    
         
            -
              require 'grape_oauth2/mixins/mongoid/access_token'
         
     | 
| 
       30 
     | 
    
         
            -
              require 'grape_oauth2/mixins/mongoid/access_grant'
         
     | 
| 
       31 
     | 
    
         
            -
              require 'grape_oauth2/mixins/mongoid/client'
         
     | 
| 
       32 
     | 
    
         
            -
            end
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
            # Authorization Grants aka Flows (Strategies)
         
     | 
| 
       35 
     | 
    
         
            -
            require 'grape_oauth2/strategies/base'
         
     | 
| 
       36 
     | 
    
         
            -
            require 'grape_oauth2/strategies/authorization_code'
         
     | 
| 
       37 
     | 
    
         
            -
            require 'grape_oauth2/strategies/password'
         
     | 
| 
       38 
     | 
    
         
            -
            require 'grape_oauth2/strategies/client_credentials'
         
     | 
| 
       39 
     | 
    
         
            -
            require 'grape_oauth2/strategies/refresh_token'
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
            # Generators
         
     | 
| 
       42 
     | 
    
         
            -
            require 'grape_oauth2/generators/base'
         
     | 
| 
       43 
     | 
    
         
            -
            require 'grape_oauth2/generators/token'
         
     | 
| 
       44 
     | 
    
         
            -
            require 'grape_oauth2/generators/authorization'
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
            # Grape Helpers
         
     | 
| 
       47 
     | 
    
         
            -
            require 'grape_oauth2/helpers/access_token_helpers'
         
     | 
| 
       48 
     | 
    
         
            -
            require 'grape_oauth2/helpers/oauth_params'
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
            # Responses
         
     | 
| 
       51 
     | 
    
         
            -
            require 'grape_oauth2/responses/base'
         
     | 
| 
       52 
     | 
    
         
            -
            require 'grape_oauth2/responses/authorization'
         
     | 
| 
       53 
     | 
    
         
            -
            require 'grape_oauth2/responses/token'
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
            # Grape Endpoints
         
     | 
| 
       56 
     | 
    
         
            -
            require 'grape_oauth2/endpoints/token'
         
     | 
| 
       57 
     | 
    
         
            -
            require 'grape_oauth2/endpoints/authorize'
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
            # Use Grape namespace for the gem.
         
     | 
| 
       60 
     | 
    
         
            -
            module Grape
         
     | 
| 
       61 
     | 
    
         
            -
              # Main Grape::OAuth2 module.
         
     | 
| 
       62 
     | 
    
         
            -
              module OAuth2
         
     | 
| 
       63 
     | 
    
         
            -
                class << self
         
     | 
| 
       64 
     | 
    
         
            -
                  # Grape::OAuth2 configuration.
         
     | 
| 
       65 
     | 
    
         
            -
                  #
         
     | 
| 
       66 
     | 
    
         
            -
                  # @return [Grape::OAuth2::Configuration]
         
     | 
| 
       67 
     | 
    
         
            -
                  #   configuration object
         
     | 
| 
       68 
     | 
    
         
            -
                  #
         
     | 
| 
       69 
     | 
    
         
            -
                  def config
         
     | 
| 
       70 
     | 
    
         
            -
                    @config ||= Grape::OAuth2::Configuration.new
         
     | 
| 
       71 
     | 
    
         
            -
                  end
         
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
                  # Configures Grape::OAuth2.
         
     | 
| 
       74 
     | 
    
         
            -
                  # Yields Grape::OAuth2::Configuration instance to the block.
         
     | 
| 
       75 
     | 
    
         
            -
                  def configure
         
     | 
| 
       76 
     | 
    
         
            -
                    yield config
         
     | 
| 
       77 
     | 
    
         
            -
                  end
         
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
                  # Validates Grape::OAuth2 configuration to be set correctly.
         
     | 
| 
       80 
     | 
    
         
            -
                  def check_configuration!
         
     | 
| 
       81 
     | 
    
         
            -
                    config.check!
         
     | 
| 
       82 
     | 
    
         
            -
                  end
         
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
                  # Grape::OAuth2 default middleware.
         
     | 
| 
       85 
     | 
    
         
            -
                  def middleware
         
     | 
| 
       86 
     | 
    
         
            -
                    [Rack::OAuth2::Server::Resource::Bearer, config.realm, config.token_authenticator]
         
     | 
| 
       87 
     | 
    
         
            -
                  end
         
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
                  # Method for injecting Grape::OAuth2 endpoints and helpers
         
     | 
| 
       90 
     | 
    
         
            -
                  # into Grape API class. Automatically set required middleware,
         
     | 
| 
       91 
     | 
    
         
            -
                  # OAuth2 helpers and mounts all (or configured) endpoints.
         
     | 
| 
       92 
     | 
    
         
            -
                  #
         
     | 
| 
       93 
     | 
    
         
            -
                  # @param endpoints [Array<Symbol>, Array<String>] endpoints to add
         
     | 
| 
       94 
     | 
    
         
            -
                  #
         
     | 
| 
       95 
     | 
    
         
            -
                  def api(*endpoints)
         
     | 
| 
       96 
     | 
    
         
            -
                    inject_to_api do |api|
         
     | 
| 
       97 
     | 
    
         
            -
                      api.use(*Grape::OAuth2.middleware)
         
     | 
| 
       98 
     | 
    
         
            -
                      api.helpers(Grape::OAuth2::Helpers::AccessTokenHelpers)
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
                      (endpoints.presence || endpoints_mapping.keys).each do |name|
         
     | 
| 
       101 
     | 
    
         
            -
                        endpoint = endpoints_mapping[name.to_sym]
         
     | 
| 
       102 
     | 
    
         
            -
                        raise ArgumentError, "Unrecognized endpoint: #{endpoint}" if endpoint.nil?
         
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
                        api.mount(endpoint)
         
     | 
| 
       105 
     | 
    
         
            -
                      end
         
     | 
| 
       106 
     | 
    
         
            -
                    end
         
     | 
| 
       107 
     | 
    
         
            -
                  end
         
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
       109 
     | 
    
         
            -
                  private
         
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
                  def endpoints_mapping
         
     | 
| 
       112 
     | 
    
         
            -
                    {
         
     | 
| 
       113 
     | 
    
         
            -
                      token: ::Grape::OAuth2::Endpoints::Token,
         
     | 
| 
       114 
     | 
    
         
            -
                      authorize: ::Grape::OAuth2::Endpoints::Authorize
         
     | 
| 
       115 
     | 
    
         
            -
                    }
         
     | 
| 
       116 
     | 
    
         
            -
                  end
         
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
                  def inject_to_api(&_block)
         
     | 
| 
       119 
     | 
    
         
            -
                    raise ArgumentError, 'block must be specified!' unless block_given?
         
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
                    Module.new do |mod|
         
     | 
| 
       122 
     | 
    
         
            -
                      mod.define_singleton_method :included do |base|
         
     | 
| 
       123 
     | 
    
         
            -
                        yield base
         
     | 
| 
       124 
     | 
    
         
            -
                      end
         
     | 
| 
       125 
     | 
    
         
            -
                    end
         
     | 
| 
       126 
     | 
    
         
            -
                  end
         
     | 
| 
       127 
     | 
    
         
            -
                end
         
     | 
| 
       128 
     | 
    
         
            -
              end
         
     | 
| 
       129 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            require 'grape'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'rack/oauth2'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            require 'grape_oauth2/version'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'grape_oauth2/configuration/validation'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'grape_oauth2/configuration/class_accessors'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'grape_oauth2/configuration'
         
     | 
| 
      
 8 
     | 
    
         
            +
            require 'grape_oauth2/scopes'
         
     | 
| 
      
 9 
     | 
    
         
            +
            require 'grape_oauth2/unique_token'
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            # NOTE: Extract to separate gems!!!
         
     | 
| 
      
 12 
     | 
    
         
            +
            # This gem should contains only the core functionality and all mixins
         
     | 
| 
      
 13 
     | 
    
         
            +
            # need to be moved to their own repos with their own tests.
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            # Mixins
         
     | 
| 
      
 16 
     | 
    
         
            +
            if defined?(ActiveRecord::Base)
         
     | 
| 
      
 17 
     | 
    
         
            +
              require 'grape_oauth2/mixins/active_record/access_token'
         
     | 
| 
      
 18 
     | 
    
         
            +
              require 'grape_oauth2/mixins/active_record/access_grant'
         
     | 
| 
      
 19 
     | 
    
         
            +
              require 'grape_oauth2/mixins/active_record/client'
         
     | 
| 
      
 20 
     | 
    
         
            +
            end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
            if defined?(Sequel::Model)
         
     | 
| 
      
 23 
     | 
    
         
            +
              require 'grape_oauth2/mixins/sequel/access_token'
         
     | 
| 
      
 24 
     | 
    
         
            +
              require 'grape_oauth2/mixins/sequel/access_grant'
         
     | 
| 
      
 25 
     | 
    
         
            +
              require 'grape_oauth2/mixins/sequel/client'
         
     | 
| 
      
 26 
     | 
    
         
            +
            end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
            if defined?(Mongoid::Document)
         
     | 
| 
      
 29 
     | 
    
         
            +
              require 'grape_oauth2/mixins/mongoid/access_token'
         
     | 
| 
      
 30 
     | 
    
         
            +
              require 'grape_oauth2/mixins/mongoid/access_grant'
         
     | 
| 
      
 31 
     | 
    
         
            +
              require 'grape_oauth2/mixins/mongoid/client'
         
     | 
| 
      
 32 
     | 
    
         
            +
            end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            # Authorization Grants aka Flows (Strategies)
         
     | 
| 
      
 35 
     | 
    
         
            +
            require 'grape_oauth2/strategies/base'
         
     | 
| 
      
 36 
     | 
    
         
            +
            require 'grape_oauth2/strategies/authorization_code'
         
     | 
| 
      
 37 
     | 
    
         
            +
            require 'grape_oauth2/strategies/password'
         
     | 
| 
      
 38 
     | 
    
         
            +
            require 'grape_oauth2/strategies/client_credentials'
         
     | 
| 
      
 39 
     | 
    
         
            +
            require 'grape_oauth2/strategies/refresh_token'
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
            # Generators
         
     | 
| 
      
 42 
     | 
    
         
            +
            require 'grape_oauth2/generators/base'
         
     | 
| 
      
 43 
     | 
    
         
            +
            require 'grape_oauth2/generators/token'
         
     | 
| 
      
 44 
     | 
    
         
            +
            require 'grape_oauth2/generators/authorization'
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
            # Grape Helpers
         
     | 
| 
      
 47 
     | 
    
         
            +
            require 'grape_oauth2/helpers/access_token_helpers'
         
     | 
| 
      
 48 
     | 
    
         
            +
            require 'grape_oauth2/helpers/oauth_params'
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
            # Responses
         
     | 
| 
      
 51 
     | 
    
         
            +
            require 'grape_oauth2/responses/base'
         
     | 
| 
      
 52 
     | 
    
         
            +
            require 'grape_oauth2/responses/authorization'
         
     | 
| 
      
 53 
     | 
    
         
            +
            require 'grape_oauth2/responses/token'
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
            # Grape Endpoints
         
     | 
| 
      
 56 
     | 
    
         
            +
            require 'grape_oauth2/endpoints/token'
         
     | 
| 
      
 57 
     | 
    
         
            +
            require 'grape_oauth2/endpoints/authorize'
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
            # Use Grape namespace for the gem.
         
     | 
| 
      
 60 
     | 
    
         
            +
            module Grape
         
     | 
| 
      
 61 
     | 
    
         
            +
              # Main Grape::OAuth2 module.
         
     | 
| 
      
 62 
     | 
    
         
            +
              module OAuth2
         
     | 
| 
      
 63 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 64 
     | 
    
         
            +
                  # Grape::OAuth2 configuration.
         
     | 
| 
      
 65 
     | 
    
         
            +
                  #
         
     | 
| 
      
 66 
     | 
    
         
            +
                  # @return [Grape::OAuth2::Configuration]
         
     | 
| 
      
 67 
     | 
    
         
            +
                  #   configuration object
         
     | 
| 
      
 68 
     | 
    
         
            +
                  #
         
     | 
| 
      
 69 
     | 
    
         
            +
                  def config
         
     | 
| 
      
 70 
     | 
    
         
            +
                    @config ||= Grape::OAuth2::Configuration.new
         
     | 
| 
      
 71 
     | 
    
         
            +
                  end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                  # Configures Grape::OAuth2.
         
     | 
| 
      
 74 
     | 
    
         
            +
                  # Yields Grape::OAuth2::Configuration instance to the block.
         
     | 
| 
      
 75 
     | 
    
         
            +
                  def configure
         
     | 
| 
      
 76 
     | 
    
         
            +
                    yield config
         
     | 
| 
      
 77 
     | 
    
         
            +
                  end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                  # Validates Grape::OAuth2 configuration to be set correctly.
         
     | 
| 
      
 80 
     | 
    
         
            +
                  def check_configuration!
         
     | 
| 
      
 81 
     | 
    
         
            +
                    config.check!
         
     | 
| 
      
 82 
     | 
    
         
            +
                  end
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
                  # Grape::OAuth2 default middleware.
         
     | 
| 
      
 85 
     | 
    
         
            +
                  def middleware
         
     | 
| 
      
 86 
     | 
    
         
            +
                    [Rack::OAuth2::Server::Resource::Bearer, config.realm, config.token_authenticator]
         
     | 
| 
      
 87 
     | 
    
         
            +
                  end
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                  # Method for injecting Grape::OAuth2 endpoints and helpers
         
     | 
| 
      
 90 
     | 
    
         
            +
                  # into Grape API class. Automatically set required middleware,
         
     | 
| 
      
 91 
     | 
    
         
            +
                  # OAuth2 helpers and mounts all (or configured) endpoints.
         
     | 
| 
      
 92 
     | 
    
         
            +
                  #
         
     | 
| 
      
 93 
     | 
    
         
            +
                  # @param endpoints [Array<Symbol>, Array<String>] endpoints to add
         
     | 
| 
      
 94 
     | 
    
         
            +
                  #
         
     | 
| 
      
 95 
     | 
    
         
            +
                  def api(*endpoints)
         
     | 
| 
      
 96 
     | 
    
         
            +
                    inject_to_api do |api|
         
     | 
| 
      
 97 
     | 
    
         
            +
                      api.use(*Grape::OAuth2.middleware)
         
     | 
| 
      
 98 
     | 
    
         
            +
                      api.helpers(Grape::OAuth2::Helpers::AccessTokenHelpers)
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                      (endpoints.presence || endpoints_mapping.keys).each do |name|
         
     | 
| 
      
 101 
     | 
    
         
            +
                        endpoint = endpoints_mapping[name.to_sym]
         
     | 
| 
      
 102 
     | 
    
         
            +
                        raise ArgumentError, "Unrecognized endpoint: #{endpoint}" if endpoint.nil?
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                        api.mount(endpoint)
         
     | 
| 
      
 105 
     | 
    
         
            +
                      end
         
     | 
| 
      
 106 
     | 
    
         
            +
                    end
         
     | 
| 
      
 107 
     | 
    
         
            +
                  end
         
     | 
| 
      
 108 
     | 
    
         
            +
             
     | 
| 
      
 109 
     | 
    
         
            +
                  private
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
                  def endpoints_mapping
         
     | 
| 
      
 112 
     | 
    
         
            +
                    {
         
     | 
| 
      
 113 
     | 
    
         
            +
                      token: ::Grape::OAuth2::Endpoints::Token,
         
     | 
| 
      
 114 
     | 
    
         
            +
                      authorize: ::Grape::OAuth2::Endpoints::Authorize
         
     | 
| 
      
 115 
     | 
    
         
            +
                    }
         
     | 
| 
      
 116 
     | 
    
         
            +
                  end
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
                  def inject_to_api(&_block)
         
     | 
| 
      
 119 
     | 
    
         
            +
                    raise ArgumentError, 'block must be specified!' unless block_given?
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
                    Module.new do |mod|
         
     | 
| 
      
 122 
     | 
    
         
            +
                      mod.define_singleton_method :included do |base|
         
     | 
| 
      
 123 
     | 
    
         
            +
                        yield base
         
     | 
| 
      
 124 
     | 
    
         
            +
                      end
         
     | 
| 
      
 125 
     | 
    
         
            +
                    end
         
     | 
| 
      
 126 
     | 
    
         
            +
                  end
         
     | 
| 
      
 127 
     | 
    
         
            +
                end
         
     | 
| 
      
 128 
     | 
    
         
            +
              end
         
     | 
| 
      
 129 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,143 +1,143 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Grape
         
     | 
| 
       2 
     | 
    
         
            -
              module OAuth2
         
     | 
| 
       3 
     | 
    
         
            -
                # Grape::OAuth2 configuration class.
         
     | 
| 
       4 
     | 
    
         
            -
                # Contains default or customized options that would be used
         
     | 
| 
       5 
     | 
    
         
            -
                # in OAuth2 endpoints and helpers.
         
     | 
| 
       6 
     | 
    
         
            -
                class Configuration
         
     | 
| 
       7 
     | 
    
         
            -
                  # Default Grape::OAuth2 configuration error class.
         
     | 
| 
       8 
     | 
    
         
            -
                  Error = Class.new(StandardError)
         
     | 
| 
       9 
     | 
    
         
            -
                  # Grape::OAuth2 configuration error for missing API required for OAuth2 classes.
         
     | 
| 
       10 
     | 
    
         
            -
                  APIMissing = Class.new(Error)
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                  include Validation
         
     | 
| 
       13 
     | 
    
         
            -
                  include ClassAccessors
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                  # Default Access Token TTL (in seconds)
         
     | 
| 
       16 
     | 
    
         
            -
                  DEFAULT_TOKEN_LIFETIME = 7200
         
     | 
| 
       17 
     | 
    
         
            -
                  # Default Authorization Code TTL ()in seconds)
         
     | 
| 
       18 
     | 
    
         
            -
                  DEFAULT_CODE_LIFETIME = 1800
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
                  # Default realm value
         
     | 
| 
       21 
     | 
    
         
            -
                  DEFAULT_REALM = 'OAuth 2.0'.freeze
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                  # Currently supported ( 
     | 
| 
       24 
     | 
    
         
            -
                  SUPPORTED_GRANT_TYPES = %w 
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                  # The names of the classes that represents OAuth2 roles
         
     | 
| 
       27 
     | 
    
         
            -
                  #
         
     | 
| 
       28 
     | 
    
         
            -
                  # @return [String] class name
         
     | 
| 
       29 
     | 
    
         
            -
                  #
         
     | 
| 
       30 
     | 
    
         
            -
                  attr_accessor :access_token_class_name, :access_grant_class_name,
         
     | 
| 
       31 
     | 
    
         
            -
                                :client_class_name, :resource_owner_class_name
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                  # Class name for the OAuth2 helper class that validates requested scopes against Access Token scopes
         
     | 
| 
       34 
     | 
    
         
            -
                  #
         
     | 
| 
       35 
     | 
    
         
            -
                  # @return [String] scopes validator class name
         
     | 
| 
       36 
     | 
    
         
            -
                  #
         
     | 
| 
       37 
     | 
    
         
            -
                  attr_accessor :scopes_validator_class_name
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                  # Class name for the OAuth2 helper class that generates unique token values
         
     | 
| 
       40 
     | 
    
         
            -
                  #
         
     | 
| 
       41 
     | 
    
         
            -
                  # @return [String] token generator class name
         
     | 
| 
       42 
     | 
    
         
            -
                  #
         
     | 
| 
       43 
     | 
    
         
            -
                  attr_accessor :token_generator_class_name
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
                  #  OAuth2 grant types (flows) allowed to be processed
         
     | 
| 
       46 
     | 
    
         
            -
                  #
         
     | 
| 
       47 
     | 
    
         
            -
                  # @return [Array<String>] grant types
         
     | 
| 
       48 
     | 
    
         
            -
                  #
         
     | 
| 
       49 
     | 
    
         
            -
                  attr_accessor :allowed_grant_types
         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                  # Access Token and Authorization Code lifetime in seconds
         
     | 
| 
       52 
     | 
    
         
            -
                  attr_accessor :authorization_code_lifetime, :access_token_lifetime
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
                  # Specifies whether to generate a Refresh Token when creating an Access Token
         
     | 
| 
       55 
     | 
    
         
            -
                  #
         
     | 
| 
       56 
     | 
    
         
            -
                  # @return [Boolean] true if need to generate refresh token, false in other case
         
     | 
| 
       57 
     | 
    
         
            -
                  #
         
     | 
| 
       58 
     | 
    
         
            -
                  attr_accessor :issue_refresh_token
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
                  # Realm value
         
     | 
| 
       61 
     | 
    
         
            -
                  #
         
     | 
| 
       62 
     | 
    
         
            -
                  # @return [String] realm
         
     | 
| 
       63 
     | 
    
         
            -
                  #
         
     | 
| 
       64 
     | 
    
         
            -
                  attr_accessor :realm
         
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
                  # Access Token authenticator block option for customization
         
     | 
| 
       67 
     | 
    
         
            -
                  attr_accessor :token_authenticator
         
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
                  # Callback that would be invoked during processing of Refresh Token request for
         
     | 
| 
       70 
     | 
    
         
            -
                  # the original Access Token found by token value
         
     | 
| 
       71 
     | 
    
         
            -
                  attr_accessor :on_refresh
         
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
                  def initialize
         
     | 
| 
       74 
     | 
    
         
            -
                    reset!
         
     | 
| 
       75 
     | 
    
         
            -
                  end
         
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
                  # Default Access Token authenticator block.
         
     | 
| 
       78 
     | 
    
         
            -
                  # Validates token value passed with the request params.
         
     | 
| 
       79 
     | 
    
         
            -
                  def default_token_authenticator
         
     | 
| 
       80 
     | 
    
         
            -
                    lambda do |request|
         
     | 
| 
       81 
     | 
    
         
            -
                      access_token_class.authenticate(request.access_token) || request.invalid_token!
         
     | 
| 
       82 
     | 
    
         
            -
                    end
         
     | 
| 
       83 
     | 
    
         
            -
                  end
         
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
                  # Accessor for Access Token authenticator block. Set it to proc
         
     | 
| 
       86 
     | 
    
         
            -
                  # if called with block or returns current value of the accessor.
         
     | 
| 
       87 
     | 
    
         
            -
                  def token_authenticator(&block)
         
     | 
| 
       88 
     | 
    
         
            -
                    if block_given?
         
     | 
| 
       89 
     | 
    
         
            -
                      instance_variable_set(:'@token_authenticator', block)
         
     | 
| 
       90 
     | 
    
         
            -
                    else
         
     | 
| 
       91 
     | 
    
         
            -
                      instance_variable_get(:'@token_authenticator')
         
     | 
| 
       92 
     | 
    
         
            -
                    end
         
     | 
| 
       93 
     | 
    
         
            -
                  end
         
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
                  # Accessor for on_refresh callback. Set callback proc
         
     | 
| 
       96 
     | 
    
         
            -
                  # if called with block or returns current value of the accessor.
         
     | 
| 
       97 
     | 
    
         
            -
                  def on_refresh(&block)
         
     | 
| 
       98 
     | 
    
         
            -
                    if block_given?
         
     | 
| 
       99 
     | 
    
         
            -
                      instance_variable_set(:'@on_refresh', block)
         
     | 
| 
       100 
     | 
    
         
            -
                    else
         
     | 
| 
       101 
     | 
    
         
            -
                      instance_variable_get(:'@on_refresh')
         
     | 
| 
       102 
     | 
    
         
            -
                    end
         
     | 
| 
       103 
     | 
    
         
            -
                  end
         
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
                  # Indicates if on_refresh callback can be invoked.
         
     | 
| 
       106 
     | 
    
         
            -
                  #
         
     | 
| 
       107 
     | 
    
         
            -
                  # @return [Boolean]
         
     | 
| 
       108 
     | 
    
         
            -
                  #   true if callback can be invoked and false in other cases
         
     | 
| 
       109 
     | 
    
         
            -
                  #
         
     | 
| 
       110 
     | 
    
         
            -
                  def on_refresh_runnable?
         
     | 
| 
       111 
     | 
    
         
            -
                    !on_refresh.nil? && on_refresh != :nothing
         
     | 
| 
       112 
     | 
    
         
            -
                  end
         
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
                  # Reset configuration to default options values.
         
     | 
| 
       115 
     | 
    
         
            -
                  def reset!
         
     | 
| 
       116 
     | 
    
         
            -
                    initialize_classes
         
     | 
| 
       117 
     | 
    
         
            -
                    initialize_authenticators
         
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
                    self.access_token_lifetime = DEFAULT_TOKEN_LIFETIME
         
     | 
| 
       120 
     | 
    
         
            -
                    self.authorization_code_lifetime = DEFAULT_CODE_LIFETIME
         
     | 
| 
       121 
     | 
    
         
            -
                    self.allowed_grant_types = %w 
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
                    self.issue_refresh_token = false
         
     | 
| 
       124 
     | 
    
         
            -
                    self.on_refresh = :nothing
         
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
                    self.realm = DEFAULT_REALM
         
     | 
| 
       127 
     | 
    
         
            -
                  end
         
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
                  private
         
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
                  # Sets OAuth2 helpers classes to gem defaults.
         
     | 
| 
       132 
     | 
    
         
            -
                  def initialize_classes
         
     | 
| 
       133 
     | 
    
         
            -
                    self.scopes_validator_class_name = Grape::OAuth2::Scopes.name
         
     | 
| 
       134 
     | 
    
         
            -
                    self.token_generator_class_name = Grape::OAuth2::UniqueToken.name
         
     | 
| 
       135 
     | 
    
         
            -
                  end
         
     | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
       137 
     | 
    
         
            -
                  # Sets authenticators to gem defaults.
         
     | 
| 
       138 
     | 
    
         
            -
                  def initialize_authenticators
         
     | 
| 
       139 
     | 
    
         
            -
                    self.token_authenticator = default_token_authenticator
         
     | 
| 
       140 
     | 
    
         
            -
                  end
         
     | 
| 
       141 
     | 
    
         
            -
                end
         
     | 
| 
       142 
     | 
    
         
            -
              end
         
     | 
| 
       143 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            module Grape
         
     | 
| 
      
 2 
     | 
    
         
            +
              module OAuth2
         
     | 
| 
      
 3 
     | 
    
         
            +
                # Grape::OAuth2 configuration class.
         
     | 
| 
      
 4 
     | 
    
         
            +
                # Contains default or customized options that would be used
         
     | 
| 
      
 5 
     | 
    
         
            +
                # in OAuth2 endpoints and helpers.
         
     | 
| 
      
 6 
     | 
    
         
            +
                class Configuration
         
     | 
| 
      
 7 
     | 
    
         
            +
                  # Default Grape::OAuth2 configuration error class.
         
     | 
| 
      
 8 
     | 
    
         
            +
                  Error = Class.new(StandardError)
         
     | 
| 
      
 9 
     | 
    
         
            +
                  # Grape::OAuth2 configuration error for missing API required for OAuth2 classes.
         
     | 
| 
      
 10 
     | 
    
         
            +
                  APIMissing = Class.new(Error)
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  include Validation
         
     | 
| 
      
 13 
     | 
    
         
            +
                  include ClassAccessors
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                  # Default Access Token TTL (in seconds)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  DEFAULT_TOKEN_LIFETIME = 7200
         
     | 
| 
      
 17 
     | 
    
         
            +
                  # Default Authorization Code TTL ()in seconds)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  DEFAULT_CODE_LIFETIME = 1800
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  # Default realm value
         
     | 
| 
      
 21 
     | 
    
         
            +
                  DEFAULT_REALM = 'OAuth 2.0'.freeze
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                  # Currently supported (by the gem) OAuth2 grant types
         
     | 
| 
      
 24 
     | 
    
         
            +
                  SUPPORTED_GRANT_TYPES = %w[password client_credentials refresh_token].freeze
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  # The names of the classes that represents OAuth2 roles
         
     | 
| 
      
 27 
     | 
    
         
            +
                  #
         
     | 
| 
      
 28 
     | 
    
         
            +
                  # @return [String] class name
         
     | 
| 
      
 29 
     | 
    
         
            +
                  #
         
     | 
| 
      
 30 
     | 
    
         
            +
                  attr_accessor :access_token_class_name, :access_grant_class_name,
         
     | 
| 
      
 31 
     | 
    
         
            +
                                :client_class_name, :resource_owner_class_name
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                  # Class name for the OAuth2 helper class that validates requested scopes against Access Token scopes
         
     | 
| 
      
 34 
     | 
    
         
            +
                  #
         
     | 
| 
      
 35 
     | 
    
         
            +
                  # @return [String] scopes validator class name
         
     | 
| 
      
 36 
     | 
    
         
            +
                  #
         
     | 
| 
      
 37 
     | 
    
         
            +
                  attr_accessor :scopes_validator_class_name
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                  # Class name for the OAuth2 helper class that generates unique token values
         
     | 
| 
      
 40 
     | 
    
         
            +
                  #
         
     | 
| 
      
 41 
     | 
    
         
            +
                  # @return [String] token generator class name
         
     | 
| 
      
 42 
     | 
    
         
            +
                  #
         
     | 
| 
      
 43 
     | 
    
         
            +
                  attr_accessor :token_generator_class_name
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                  #  OAuth2 grant types (flows) allowed to be processed
         
     | 
| 
      
 46 
     | 
    
         
            +
                  #
         
     | 
| 
      
 47 
     | 
    
         
            +
                  # @return [Array<String>] grant types
         
     | 
| 
      
 48 
     | 
    
         
            +
                  #
         
     | 
| 
      
 49 
     | 
    
         
            +
                  attr_accessor :allowed_grant_types
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                  # Access Token and Authorization Code lifetime in seconds
         
     | 
| 
      
 52 
     | 
    
         
            +
                  attr_accessor :authorization_code_lifetime, :access_token_lifetime
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                  # Specifies whether to generate a Refresh Token when creating an Access Token
         
     | 
| 
      
 55 
     | 
    
         
            +
                  #
         
     | 
| 
      
 56 
     | 
    
         
            +
                  # @return [Boolean] true if need to generate refresh token, false in other case
         
     | 
| 
      
 57 
     | 
    
         
            +
                  #
         
     | 
| 
      
 58 
     | 
    
         
            +
                  attr_accessor :issue_refresh_token
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                  # Realm value
         
     | 
| 
      
 61 
     | 
    
         
            +
                  #
         
     | 
| 
      
 62 
     | 
    
         
            +
                  # @return [String] realm
         
     | 
| 
      
 63 
     | 
    
         
            +
                  #
         
     | 
| 
      
 64 
     | 
    
         
            +
                  attr_accessor :realm
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                  # Access Token authenticator block option for customization
         
     | 
| 
      
 67 
     | 
    
         
            +
                  attr_accessor :token_authenticator
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                  # Callback that would be invoked during processing of Refresh Token request for
         
     | 
| 
      
 70 
     | 
    
         
            +
                  # the original Access Token found by token value
         
     | 
| 
      
 71 
     | 
    
         
            +
                  attr_accessor :on_refresh
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                  def initialize
         
     | 
| 
      
 74 
     | 
    
         
            +
                    reset!
         
     | 
| 
      
 75 
     | 
    
         
            +
                  end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                  # Default Access Token authenticator block.
         
     | 
| 
      
 78 
     | 
    
         
            +
                  # Validates token value passed with the request params.
         
     | 
| 
      
 79 
     | 
    
         
            +
                  def default_token_authenticator
         
     | 
| 
      
 80 
     | 
    
         
            +
                    lambda do |request|
         
     | 
| 
      
 81 
     | 
    
         
            +
                      access_token_class.authenticate(request.access_token) || request.invalid_token!
         
     | 
| 
      
 82 
     | 
    
         
            +
                    end
         
     | 
| 
      
 83 
     | 
    
         
            +
                  end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                  # Accessor for Access Token authenticator block. Set it to proc
         
     | 
| 
      
 86 
     | 
    
         
            +
                  # if called with block or returns current value of the accessor.
         
     | 
| 
      
 87 
     | 
    
         
            +
                  def token_authenticator(&block)
         
     | 
| 
      
 88 
     | 
    
         
            +
                    if block_given?
         
     | 
| 
      
 89 
     | 
    
         
            +
                      instance_variable_set(:'@token_authenticator', block)
         
     | 
| 
      
 90 
     | 
    
         
            +
                    else
         
     | 
| 
      
 91 
     | 
    
         
            +
                      instance_variable_get(:'@token_authenticator')
         
     | 
| 
      
 92 
     | 
    
         
            +
                    end
         
     | 
| 
      
 93 
     | 
    
         
            +
                  end
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                  # Accessor for on_refresh callback. Set callback proc
         
     | 
| 
      
 96 
     | 
    
         
            +
                  # if called with block or returns current value of the accessor.
         
     | 
| 
      
 97 
     | 
    
         
            +
                  def on_refresh(&block)
         
     | 
| 
      
 98 
     | 
    
         
            +
                    if block_given?
         
     | 
| 
      
 99 
     | 
    
         
            +
                      instance_variable_set(:'@on_refresh', block)
         
     | 
| 
      
 100 
     | 
    
         
            +
                    else
         
     | 
| 
      
 101 
     | 
    
         
            +
                      instance_variable_get(:'@on_refresh')
         
     | 
| 
      
 102 
     | 
    
         
            +
                    end
         
     | 
| 
      
 103 
     | 
    
         
            +
                  end
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
                  # Indicates if on_refresh callback can be invoked.
         
     | 
| 
      
 106 
     | 
    
         
            +
                  #
         
     | 
| 
      
 107 
     | 
    
         
            +
                  # @return [Boolean]
         
     | 
| 
      
 108 
     | 
    
         
            +
                  #   true if callback can be invoked and false in other cases
         
     | 
| 
      
 109 
     | 
    
         
            +
                  #
         
     | 
| 
      
 110 
     | 
    
         
            +
                  def on_refresh_runnable?
         
     | 
| 
      
 111 
     | 
    
         
            +
                    !on_refresh.nil? && on_refresh != :nothing
         
     | 
| 
      
 112 
     | 
    
         
            +
                  end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                  # Reset configuration to default options values.
         
     | 
| 
      
 115 
     | 
    
         
            +
                  def reset!
         
     | 
| 
      
 116 
     | 
    
         
            +
                    initialize_classes
         
     | 
| 
      
 117 
     | 
    
         
            +
                    initialize_authenticators
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
                    self.access_token_lifetime = DEFAULT_TOKEN_LIFETIME
         
     | 
| 
      
 120 
     | 
    
         
            +
                    self.authorization_code_lifetime = DEFAULT_CODE_LIFETIME
         
     | 
| 
      
 121 
     | 
    
         
            +
                    self.allowed_grant_types = %w[password client_credentials]
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
                    self.issue_refresh_token = false
         
     | 
| 
      
 124 
     | 
    
         
            +
                    self.on_refresh = :nothing
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                    self.realm = DEFAULT_REALM
         
     | 
| 
      
 127 
     | 
    
         
            +
                  end
         
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
      
 129 
     | 
    
         
            +
                  private
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
                  # Sets OAuth2 helpers classes to gem defaults.
         
     | 
| 
      
 132 
     | 
    
         
            +
                  def initialize_classes
         
     | 
| 
      
 133 
     | 
    
         
            +
                    self.scopes_validator_class_name = Grape::OAuth2::Scopes.name
         
     | 
| 
      
 134 
     | 
    
         
            +
                    self.token_generator_class_name = Grape::OAuth2::UniqueToken.name
         
     | 
| 
      
 135 
     | 
    
         
            +
                  end
         
     | 
| 
      
 136 
     | 
    
         
            +
             
     | 
| 
      
 137 
     | 
    
         
            +
                  # Sets authenticators to gem defaults.
         
     | 
| 
      
 138 
     | 
    
         
            +
                  def initialize_authenticators
         
     | 
| 
      
 139 
     | 
    
         
            +
                    self.token_authenticator = default_token_authenticator
         
     | 
| 
      
 140 
     | 
    
         
            +
                  end
         
     | 
| 
      
 141 
     | 
    
         
            +
                end
         
     | 
| 
      
 142 
     | 
    
         
            +
              end
         
     | 
| 
      
 143 
     | 
    
         
            +
            end
         
     |