omniauth-gov 0.1.0 → 0.1.1
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/.github/workflows/ruby.yml +24 -0
 - data/.gitignore +17 -0
 - data/.rspec +1 -0
 - data/Gemfile +13 -0
 - data/Guardfile +10 -0
 - data/LICENSE.txt +7 -0
 - data/README.md +73 -0
 - data/Rakefile +8 -0
 - data/lib/omniauth/strategies/gov.rb +52 -0
 - data/lib/omniauth-gov/version.rb +5 -0
 - data/lib/omniauth-gov.rb +2 -0
 - data/omniauth-gov.gemspec +25 -0
 - data/spec/omniauth/strategies/github_spec.rb +183 -0
 - data/spec/spec_helper.rb +16 -0
 - metadata +18 -4
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 2c9a9ae0696ab3fb7d9222da4661a679b1bc42066249a45b6afc6a1afde776bc
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: bbf1941d7543a850a32ca0866123b72d458a5a9219cba7111b4b867d6772a14d
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: f6b50defa7d35e5a31a071e4a01a3ef57d739757d87a261b3a6b00a77a62c2b9816cad787b54de8f1b5c60b640c873b22734b5e54b7c0e940a2c6bb4fd5991c7
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 672a6a0cdaeaa2c1274a698918f667f65816a3db2f0382e8d0d0e1ef50e96c9d5cd8ffcc4a5703a9b964b1d49cc1b9c59deb4f34b4bd532c3f4c8456d0ac1ac3
         
     | 
| 
         @@ -0,0 +1,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            name: Ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            on:
         
     | 
| 
      
 4 
     | 
    
         
            +
              push:
         
     | 
| 
      
 5 
     | 
    
         
            +
                branches: [ main ]
         
     | 
| 
      
 6 
     | 
    
         
            +
              pull_request:
         
     | 
| 
      
 7 
     | 
    
         
            +
                branches: [ main ]
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            jobs:
         
     | 
| 
      
 10 
     | 
    
         
            +
              test:
         
     | 
| 
      
 11 
     | 
    
         
            +
                runs-on: ubuntu-latest
         
     | 
| 
      
 12 
     | 
    
         
            +
                strategy:
         
     | 
| 
      
 13 
     | 
    
         
            +
                  matrix:
         
     | 
| 
      
 14 
     | 
    
         
            +
                    ruby-version: ['2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2', 'truffleruby-head']
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                steps:
         
     | 
| 
      
 17 
     | 
    
         
            +
                - uses: actions/checkout@v3
         
     | 
| 
      
 18 
     | 
    
         
            +
                - name: Set up Ruby ${{ matrix.ruby-version }}
         
     | 
| 
      
 19 
     | 
    
         
            +
                  uses: ruby/setup-ruby@v1
         
     | 
| 
      
 20 
     | 
    
         
            +
                  with:
         
     | 
| 
      
 21 
     | 
    
         
            +
                    ruby-version: ${{ matrix.ruby-version }}
         
     | 
| 
      
 22 
     | 
    
         
            +
                    bundler-cache: true
         
     | 
| 
      
 23 
     | 
    
         
            +
                - name: Build and test with Rake
         
     | 
| 
      
 24 
     | 
    
         
            +
                  run: bundle exec rake
         
     | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.rspec
    ADDED
    
    | 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --colour
         
     | 
    
        data/Gemfile
    ADDED
    
    
    
        data/Guardfile
    ADDED
    
    
    
        data/LICENSE.txt
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            Copyright (c) 2011 Michael Bleigh and Intridea, Inc.
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         
     | 
    
        data/README.md
    ADDED
    
    | 
         @@ -0,0 +1,73 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            # OmniAuth Gov
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            This is the official OmniAuth strategy for authenticating to GitHub. To
         
     | 
| 
      
 6 
     | 
    
         
            +
            use it, you'll need to sign up for an OAuth2 Application ID and Secret
         
     | 
| 
      
 7 
     | 
    
         
            +
            on the [GitHub OAuth Apps Page](https://github.com/settings/developers).
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            ## Installation
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 12 
     | 
    
         
            +
            gem 'omniauth-gov', '~> 0.1.0'
         
     | 
| 
      
 13 
     | 
    
         
            +
            ```
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            ## Basic Usage
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 18 
     | 
    
         
            +
            use OmniAuth::Builder do
         
     | 
| 
      
 19 
     | 
    
         
            +
              provider :gov, ENV['GOV_KEY'], ENV['GOV_SECRET']
         
     | 
| 
      
 20 
     | 
    
         
            +
            end
         
     | 
| 
      
 21 
     | 
    
         
            +
            ```
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
            ## Basic Usage Rails
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            In `config/initializers/gov.rb`
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 29 
     | 
    
         
            +
              Rails.application.config.middleware.use OmniAuth::Builder do
         
     | 
| 
      
 30 
     | 
    
         
            +
                provider :gov, ENV['GOV_KEY'], ENV['GOV_SECRET']
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
            ```
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
            ## Gov Enterprise Usage
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 38 
     | 
    
         
            +
            provider :gov, ENV['GOV_KEY'], ENV['GOV_SECRET'],
         
     | 
| 
      
 39 
     | 
    
         
            +
                {
         
     | 
| 
      
 40 
     | 
    
         
            +
                  :client_options => {
         
     | 
| 
      
 41 
     | 
    
         
            +
                    :site => 'https://YOURDOMAIN.com/api/v3',
         
     | 
| 
      
 42 
     | 
    
         
            +
                    :authorize_url => 'https://YOURDOMAIN.com/login/oauth/authorize',
         
     | 
| 
      
 43 
     | 
    
         
            +
                    :token_url => 'https://YOURDOMAIN.com/login/oauth/access_token',
         
     | 
| 
      
 44 
     | 
    
         
            +
                  }
         
     | 
| 
      
 45 
     | 
    
         
            +
                }
         
     | 
| 
      
 46 
     | 
    
         
            +
            ```
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
            ## Scopes
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
            GitHub API v3 lets you set scopes to provide granular access to different types of data: 
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 53 
     | 
    
         
            +
            use OmniAuth::Builder do
         
     | 
| 
      
 54 
     | 
    
         
            +
              provider :gov, ENV['GOV_KEY'], ENV['GOV_SECRET'], scope: "openid+email+profile+govbr_confiabilidades"
         
     | 
| 
      
 55 
     | 
    
         
            +
            end
         
     | 
| 
      
 56 
     | 
    
         
            +
            ```
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
            More info on [Scopes](https://docs.github.com/en/developers/apps/scopes-for-oauth-apps).
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
            ## Semver
         
     | 
| 
      
 62 
     | 
    
         
            +
            This project adheres to Semantic Versioning 2.0.0. Any violations of this scheme are considered to be bugs. 
         
     | 
| 
      
 63 
     | 
    
         
            +
            All changes will be tracked [here](https://github.com/omniauth/omniauth-gov/releases).
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
            ## License
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
            Copyright (c) 2011 Michael Bleigh and Intridea, Inc.
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
            Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
            The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         
     | 
    
        data/Rakefile
    ADDED
    
    
| 
         @@ -0,0 +1,52 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'omniauth-oauth2'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module OmniAuth
         
     | 
| 
      
 4 
     | 
    
         
            +
              module Strategies
         
     | 
| 
      
 5 
     | 
    
         
            +
                class Gov < OmniAuth::Strategies::OAuth2
         
     | 
| 
      
 6 
     | 
    
         
            +
                  option :client_options, {
         
     | 
| 
      
 7 
     | 
    
         
            +
                    site: 'https://sso.staging.acesso.gov.br',
         
     | 
| 
      
 8 
     | 
    
         
            +
                    authorize_url: 'https://sso.staging.acesso.gov.br/authorize',
         
     | 
| 
      
 9 
     | 
    
         
            +
                    token_url: 'https://sso.staging.acesso.gov.br/token'
         
     | 
| 
      
 10 
     | 
    
         
            +
                  }
         
     | 
| 
      
 11 
     | 
    
         
            +
                  
         
     | 
| 
      
 12 
     | 
    
         
            +
                  option :pkce, true
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                  option :pkce_options, {
         
     | 
| 
      
 15 
     | 
    
         
            +
                    :code_challenge => proc { |verifier|
         
     | 
| 
      
 16 
     | 
    
         
            +
                      Base64.urlsafe_encode64(
         
     | 
| 
      
 17 
     | 
    
         
            +
                        Digest::SHA2.digest(verifier),
         
     | 
| 
      
 18 
     | 
    
         
            +
                        :padding => false,
         
     | 
| 
      
 19 
     | 
    
         
            +
                      )
         
     | 
| 
      
 20 
     | 
    
         
            +
                    },
         
     | 
| 
      
 21 
     | 
    
         
            +
                    :code_challenge_method => "S256",
         
     | 
| 
      
 22 
     | 
    
         
            +
                  }
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                  uid{ raw_info['id'] }
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  info do
         
     | 
| 
      
 27 
     | 
    
         
            +
                    {
         
     | 
| 
      
 28 
     | 
    
         
            +
                      :name => raw_info['name'],
         
     | 
| 
      
 29 
     | 
    
         
            +
                      :email => raw_info['email'],
         
     | 
| 
      
 30 
     | 
    
         
            +
                      :cpf => raw_info['sub']
         
     | 
| 
      
 31 
     | 
    
         
            +
                    }
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                  extra do
         
     | 
| 
      
 35 
     | 
    
         
            +
                    {
         
     | 
| 
      
 36 
     | 
    
         
            +
                      'raw_info' => raw_info, 'uid' => uid
         
     | 
| 
      
 37 
     | 
    
         
            +
                    }
         
     | 
| 
      
 38 
     | 
    
         
            +
                  end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                  def raw_info
         
     | 
| 
      
 41 
     | 
    
         
            +
                    @raw_info ||= access_token.get('id_token').parsed
         
     | 
| 
      
 42 
     | 
    
         
            +
                  end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                  def uid
         
     | 
| 
      
 45 
     | 
    
         
            +
                    @uid ||= access_token.get('access_token/jti').parsed
         
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
            end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
            OmniAuth.config.add_camelization 'gov', 'Gov'
         
     | 
    
        data/lib/omniauth-gov.rb
    ADDED
    
    
| 
         @@ -0,0 +1,25 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # -*- encoding: utf-8 -*-
         
     | 
| 
      
 2 
     | 
    
         
            +
            require File.expand_path('../lib/omniauth-gov/version', __FILE__)
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            Gem::Specification.new do |gem|
         
     | 
| 
      
 5 
     | 
    
         
            +
              gem.authors       = ["Jonas Ricardo"]
         
     | 
| 
      
 6 
     | 
    
         
            +
              gem.email         = ["jonas.campos@yahoo.com.br"]
         
     | 
| 
      
 7 
     | 
    
         
            +
              gem.description   = %q{Official OmniAuth strategy for GitHub.}
         
     | 
| 
      
 8 
     | 
    
         
            +
              gem.summary       = %q{Official OmniAuth strategy for GitHub.}
         
     | 
| 
      
 9 
     | 
    
         
            +
              gem.homepage      = "https://github.com/jonasrscampos/omniauth-gov"
         
     | 
| 
      
 10 
     | 
    
         
            +
              gem.license       = "MIT"
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
              gem.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
         
     | 
| 
      
 13 
     | 
    
         
            +
              gem.files         = `git ls-files`.split("\n")
         
     | 
| 
      
 14 
     | 
    
         
            +
              gem.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
         
     | 
| 
      
 15 
     | 
    
         
            +
              gem.name          = "omniauth-gov"
         
     | 
| 
      
 16 
     | 
    
         
            +
              gem.require_paths = ["lib"]
         
     | 
| 
      
 17 
     | 
    
         
            +
              gem.version       = OmniAuth::Gov::VERSION
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              gem.add_dependency 'omniauth', '1.9.1' 
         
     | 
| 
      
 20 
     | 
    
         
            +
              gem.add_dependency 'omniauth-oauth2'
         
     | 
| 
      
 21 
     | 
    
         
            +
              gem.add_development_dependency 'rspec', '~> 3.5'
         
     | 
| 
      
 22 
     | 
    
         
            +
              gem.add_development_dependency 'rack-test'
         
     | 
| 
      
 23 
     | 
    
         
            +
              gem.add_development_dependency 'simplecov'
         
     | 
| 
      
 24 
     | 
    
         
            +
              gem.add_development_dependency 'webmock'
         
     | 
| 
      
 25 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,183 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe OmniAuth::Strategies::GitHub do
         
     | 
| 
      
 4 
     | 
    
         
            +
              let(:access_token) { instance_double('AccessToken', :options => {}, :[] => 'user') }
         
     | 
| 
      
 5 
     | 
    
         
            +
              let(:parsed_response) { instance_double('ParsedResponse') }
         
     | 
| 
      
 6 
     | 
    
         
            +
              let(:response) { instance_double('Response', :parsed => parsed_response) }
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              let(:enterprise_site)          { 'https://some.other.site.com/api/v3' }
         
     | 
| 
      
 9 
     | 
    
         
            +
              let(:enterprise_authorize_url) { 'https://some.other.site.com/login/oauth/authorize' }
         
     | 
| 
      
 10 
     | 
    
         
            +
              let(:enterprise_token_url)     { 'https://some.other.site.com/login/oauth/access_token' }
         
     | 
| 
      
 11 
     | 
    
         
            +
              let(:enterprise) do
         
     | 
| 
      
 12 
     | 
    
         
            +
                OmniAuth::Strategies::GitHub.new('GITHUB_KEY', 'GITHUB_SECRET',
         
     | 
| 
      
 13 
     | 
    
         
            +
                    {
         
     | 
| 
      
 14 
     | 
    
         
            +
                        :client_options => {
         
     | 
| 
      
 15 
     | 
    
         
            +
                            :site => enterprise_site,
         
     | 
| 
      
 16 
     | 
    
         
            +
                            :authorize_url => enterprise_authorize_url,
         
     | 
| 
      
 17 
     | 
    
         
            +
                            :token_url => enterprise_token_url
         
     | 
| 
      
 18 
     | 
    
         
            +
                        }
         
     | 
| 
      
 19 
     | 
    
         
            +
                    }
         
     | 
| 
      
 20 
     | 
    
         
            +
                )
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
              subject do
         
     | 
| 
      
 24 
     | 
    
         
            +
                OmniAuth::Strategies::GitHub.new({})
         
     | 
| 
      
 25 
     | 
    
         
            +
              end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
              before(:each) do
         
     | 
| 
      
 28 
     | 
    
         
            +
                allow(subject).to receive(:access_token).and_return(access_token)
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
              context 'client options' do
         
     | 
| 
      
 32 
     | 
    
         
            +
                it 'should have correct site' do
         
     | 
| 
      
 33 
     | 
    
         
            +
                  expect(subject.options.client_options.site).to eq('https://api.github.com')
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                it 'should have correct authorize url' do
         
     | 
| 
      
 37 
     | 
    
         
            +
                  expect(subject.options.client_options.authorize_url).to eq('https://github.com/login/oauth/authorize')
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                it 'should have correct token url' do
         
     | 
| 
      
 41 
     | 
    
         
            +
                  expect(subject.options.client_options.token_url).to eq('https://github.com/login/oauth/access_token')
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                describe 'should be overrideable' do
         
     | 
| 
      
 45 
     | 
    
         
            +
                  it 'for site' do
         
     | 
| 
      
 46 
     | 
    
         
            +
                    expect(enterprise.options.client_options.site).to eq(enterprise_site)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                  it 'for authorize url' do
         
     | 
| 
      
 50 
     | 
    
         
            +
                    expect(enterprise.options.client_options.authorize_url).to eq(enterprise_authorize_url)
         
     | 
| 
      
 51 
     | 
    
         
            +
                  end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                  it 'for token url' do
         
     | 
| 
      
 54 
     | 
    
         
            +
                    expect(enterprise.options.client_options.token_url).to eq(enterprise_token_url)
         
     | 
| 
      
 55 
     | 
    
         
            +
                  end
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
              end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
              context '#email_access_allowed?' do
         
     | 
| 
      
 60 
     | 
    
         
            +
                it 'should not allow email if scope is nil' do
         
     | 
| 
      
 61 
     | 
    
         
            +
                  expect(subject.options['scope']).to be_nil
         
     | 
| 
      
 62 
     | 
    
         
            +
                  expect(subject).to_not be_email_access_allowed
         
     | 
| 
      
 63 
     | 
    
         
            +
                end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                it 'should allow email if scope is user' do
         
     | 
| 
      
 66 
     | 
    
         
            +
                  subject.options['scope'] = 'user'
         
     | 
| 
      
 67 
     | 
    
         
            +
                  expect(subject).to be_email_access_allowed
         
     | 
| 
      
 68 
     | 
    
         
            +
                end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                it 'should allow email if scope is a bunch of stuff including user' do
         
     | 
| 
      
 71 
     | 
    
         
            +
                  subject.options['scope'] = 'public_repo,user,repo,delete_repo,gist'
         
     | 
| 
      
 72 
     | 
    
         
            +
                  expect(subject).to be_email_access_allowed
         
     | 
| 
      
 73 
     | 
    
         
            +
                end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                it 'should not allow email if scope does not grant email access' do
         
     | 
| 
      
 76 
     | 
    
         
            +
                  subject.options['scope'] = 'repo,user:follow'
         
     | 
| 
      
 77 
     | 
    
         
            +
                  expect(subject).to_not be_email_access_allowed
         
     | 
| 
      
 78 
     | 
    
         
            +
                end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                it 'should assume email access not allowed if scope is something currently not documented' do
         
     | 
| 
      
 81 
     | 
    
         
            +
                  subject.options['scope'] = 'currently_not_documented'
         
     | 
| 
      
 82 
     | 
    
         
            +
                  expect(subject).to_not be_email_access_allowed
         
     | 
| 
      
 83 
     | 
    
         
            +
                end
         
     | 
| 
      
 84 
     | 
    
         
            +
              end
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
              context '#email' do
         
     | 
| 
      
 87 
     | 
    
         
            +
                it 'should return email from raw_info if available' do
         
     | 
| 
      
 88 
     | 
    
         
            +
                  allow(subject).to receive(:raw_info).and_return({ 'email' => 'you@example.com' })
         
     | 
| 
      
 89 
     | 
    
         
            +
                  expect(subject.email).to eq('you@example.com')
         
     | 
| 
      
 90 
     | 
    
         
            +
                end
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                it 'should return nil if there is no raw_info and email access is not allowed' do
         
     | 
| 
      
 93 
     | 
    
         
            +
                  allow(subject).to receive(:raw_info).and_return({})
         
     | 
| 
      
 94 
     | 
    
         
            +
                  expect(subject.email).to be_nil
         
     | 
| 
      
 95 
     | 
    
         
            +
                end
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
                it 'should not return the primary email if there is no raw_info and email access is allowed' do
         
     | 
| 
      
 98 
     | 
    
         
            +
                  emails = [
         
     | 
| 
      
 99 
     | 
    
         
            +
                    { 'email' => 'secondary@example.com', 'primary' => false },
         
     | 
| 
      
 100 
     | 
    
         
            +
                    { 'email' => 'primary@example.com',   'primary' => true }
         
     | 
| 
      
 101 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 102 
     | 
    
         
            +
                  allow(subject).to receive(:raw_info).and_return({})
         
     | 
| 
      
 103 
     | 
    
         
            +
                  subject.options['scope'] = 'user'
         
     | 
| 
      
 104 
     | 
    
         
            +
                  allow(subject).to receive(:emails).and_return(emails)
         
     | 
| 
      
 105 
     | 
    
         
            +
                  expect(subject.email).to be_nil
         
     | 
| 
      
 106 
     | 
    
         
            +
                end
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
                it 'should not return the first email if there is no raw_info and email access is allowed' do
         
     | 
| 
      
 109 
     | 
    
         
            +
                  emails = [
         
     | 
| 
      
 110 
     | 
    
         
            +
                    { 'email' => 'first@example.com',   'primary' => false },
         
     | 
| 
      
 111 
     | 
    
         
            +
                    { 'email' => 'second@example.com',  'primary' => false }
         
     | 
| 
      
 112 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 113 
     | 
    
         
            +
                  allow(subject).to receive(:raw_info).and_return({})
         
     | 
| 
      
 114 
     | 
    
         
            +
                  subject.options['scope'] = 'user'
         
     | 
| 
      
 115 
     | 
    
         
            +
                  allow(subject).to receive(:emails).and_return(emails)
         
     | 
| 
      
 116 
     | 
    
         
            +
                  expect(subject.email).to be_nil
         
     | 
| 
      
 117 
     | 
    
         
            +
                end
         
     | 
| 
      
 118 
     | 
    
         
            +
              end
         
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
| 
      
 120 
     | 
    
         
            +
              context '#raw_info' do
         
     | 
| 
      
 121 
     | 
    
         
            +
                it 'should use relative paths' do
         
     | 
| 
      
 122 
     | 
    
         
            +
                  expect(access_token).to receive(:get).with('user').and_return(response)
         
     | 
| 
      
 123 
     | 
    
         
            +
                  expect(subject.raw_info).to eq(parsed_response)
         
     | 
| 
      
 124 
     | 
    
         
            +
                end
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                it 'should use the header auth mode' do
         
     | 
| 
      
 127 
     | 
    
         
            +
                  expect(access_token).to receive(:get).with('user').and_return(response)
         
     | 
| 
      
 128 
     | 
    
         
            +
                  subject.raw_info
         
     | 
| 
      
 129 
     | 
    
         
            +
                  expect(access_token.options[:mode]).to eq(:header)
         
     | 
| 
      
 130 
     | 
    
         
            +
                end
         
     | 
| 
      
 131 
     | 
    
         
            +
              end
         
     | 
| 
      
 132 
     | 
    
         
            +
             
     | 
| 
      
 133 
     | 
    
         
            +
              context '#emails' do
         
     | 
| 
      
 134 
     | 
    
         
            +
                it 'should use relative paths' do
         
     | 
| 
      
 135 
     | 
    
         
            +
                  expect(access_token).to receive(:get).with('user/emails', :headers => {
         
     | 
| 
      
 136 
     | 
    
         
            +
                    'Accept' => 'application/vnd.github.v3'
         
     | 
| 
      
 137 
     | 
    
         
            +
                  }).and_return(response)
         
     | 
| 
      
 138 
     | 
    
         
            +
             
     | 
| 
      
 139 
     | 
    
         
            +
                  subject.options['scope'] = 'user'
         
     | 
| 
      
 140 
     | 
    
         
            +
                  expect(subject.emails).to eq(parsed_response)
         
     | 
| 
      
 141 
     | 
    
         
            +
                end
         
     | 
| 
      
 142 
     | 
    
         
            +
             
     | 
| 
      
 143 
     | 
    
         
            +
                it 'should use the header auth mode' do
         
     | 
| 
      
 144 
     | 
    
         
            +
                  expect(access_token).to receive(:get).with('user/emails', :headers => {
         
     | 
| 
      
 145 
     | 
    
         
            +
                    'Accept' => 'application/vnd.github.v3'
         
     | 
| 
      
 146 
     | 
    
         
            +
                  }).and_return(response)
         
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
                  subject.options['scope'] = 'user'
         
     | 
| 
      
 149 
     | 
    
         
            +
                  subject.emails
         
     | 
| 
      
 150 
     | 
    
         
            +
                  expect(access_token.options[:mode]).to eq(:header)
         
     | 
| 
      
 151 
     | 
    
         
            +
                end
         
     | 
| 
      
 152 
     | 
    
         
            +
              end
         
     | 
| 
      
 153 
     | 
    
         
            +
             
     | 
| 
      
 154 
     | 
    
         
            +
              context '#info.email' do
         
     | 
| 
      
 155 
     | 
    
         
            +
                it 'should use any available email' do
         
     | 
| 
      
 156 
     | 
    
         
            +
                  allow(subject).to receive(:raw_info).and_return({})
         
     | 
| 
      
 157 
     | 
    
         
            +
                  allow(subject).to receive(:email).and_return('you@example.com')
         
     | 
| 
      
 158 
     | 
    
         
            +
                  expect(subject.info['email']).to eq('you@example.com')
         
     | 
| 
      
 159 
     | 
    
         
            +
                end
         
     | 
| 
      
 160 
     | 
    
         
            +
              end
         
     | 
| 
      
 161 
     | 
    
         
            +
             
     | 
| 
      
 162 
     | 
    
         
            +
              context '#info.urls' do
         
     | 
| 
      
 163 
     | 
    
         
            +
                it 'should use html_url from raw_info' do
         
     | 
| 
      
 164 
     | 
    
         
            +
                  allow(subject).to receive(:raw_info).and_return({ 'login' => 'me', 'html_url' => 'http://enterprise/me' })
         
     | 
| 
      
 165 
     | 
    
         
            +
                  expect(subject.info['urls']['GitHub']).to eq('http://enterprise/me')
         
     | 
| 
      
 166 
     | 
    
         
            +
                end
         
     | 
| 
      
 167 
     | 
    
         
            +
              end
         
     | 
| 
      
 168 
     | 
    
         
            +
             
     | 
| 
      
 169 
     | 
    
         
            +
              context '#extra.scope' do
         
     | 
| 
      
 170 
     | 
    
         
            +
                it 'returns the scope on the returned access_token' do
         
     | 
| 
      
 171 
     | 
    
         
            +
                  expect(subject.scope).to eq('user')
         
     | 
| 
      
 172 
     | 
    
         
            +
                end
         
     | 
| 
      
 173 
     | 
    
         
            +
              end
         
     | 
| 
      
 174 
     | 
    
         
            +
             
     | 
| 
      
 175 
     | 
    
         
            +
              describe '#callback_url' do
         
     | 
| 
      
 176 
     | 
    
         
            +
                it 'is a combination of host, script name, and callback path' do
         
     | 
| 
      
 177 
     | 
    
         
            +
                  allow(subject).to receive(:full_host).and_return('https://example.com')
         
     | 
| 
      
 178 
     | 
    
         
            +
                  allow(subject).to receive(:script_name).and_return('/sub_uri')
         
     | 
| 
      
 179 
     | 
    
         
            +
             
     | 
| 
      
 180 
     | 
    
         
            +
                  expect(subject.callback_url).to eq('https://example.com/sub_uri/auth/github/callback')
         
     | 
| 
      
 181 
     | 
    
         
            +
                end
         
     | 
| 
      
 182 
     | 
    
         
            +
              end
         
     | 
| 
      
 183 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | 
         @@ -0,0 +1,16 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            $:.unshift File.expand_path('..', __FILE__)
         
     | 
| 
      
 2 
     | 
    
         
            +
            $:.unshift File.expand_path('../../lib', __FILE__)
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'simplecov'
         
     | 
| 
      
 4 
     | 
    
         
            +
            SimpleCov.start
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'rspec'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'rack/test'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'webmock/rspec'
         
     | 
| 
      
 8 
     | 
    
         
            +
            require 'omniauth'
         
     | 
| 
      
 9 
     | 
    
         
            +
            require 'omniauth-gov'
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            RSpec.configure do |config|
         
     | 
| 
      
 12 
     | 
    
         
            +
              config.include WebMock::API
         
     | 
| 
      
 13 
     | 
    
         
            +
              config.include Rack::Test::Methods
         
     | 
| 
      
 14 
     | 
    
         
            +
              config.extend  OmniAuth::Test::StrategyMacros, :type => :strategy
         
     | 
| 
      
 15 
     | 
    
         
            +
            end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: omniauth-gov
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Jonas Ricardo
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2023-12- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2023-12-08 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: omniauth
         
     | 
| 
         @@ -100,7 +100,21 @@ email: 
     | 
|
| 
       100 
100 
     | 
    
         
             
            executables: []
         
     | 
| 
       101 
101 
     | 
    
         
             
            extensions: []
         
     | 
| 
       102 
102 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       103 
     | 
    
         
            -
            files: 
     | 
| 
      
 103 
     | 
    
         
            +
            files:
         
     | 
| 
      
 104 
     | 
    
         
            +
            - ".github/workflows/ruby.yml"
         
     | 
| 
      
 105 
     | 
    
         
            +
            - ".gitignore"
         
     | 
| 
      
 106 
     | 
    
         
            +
            - ".rspec"
         
     | 
| 
      
 107 
     | 
    
         
            +
            - Gemfile
         
     | 
| 
      
 108 
     | 
    
         
            +
            - Guardfile
         
     | 
| 
      
 109 
     | 
    
         
            +
            - LICENSE.txt
         
     | 
| 
      
 110 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 111 
     | 
    
         
            +
            - Rakefile
         
     | 
| 
      
 112 
     | 
    
         
            +
            - lib/omniauth-gov.rb
         
     | 
| 
      
 113 
     | 
    
         
            +
            - lib/omniauth-gov/version.rb
         
     | 
| 
      
 114 
     | 
    
         
            +
            - lib/omniauth/strategies/gov.rb
         
     | 
| 
      
 115 
     | 
    
         
            +
            - omniauth-gov.gemspec
         
     | 
| 
      
 116 
     | 
    
         
            +
            - spec/omniauth/strategies/github_spec.rb
         
     | 
| 
      
 117 
     | 
    
         
            +
            - spec/spec_helper.rb
         
     | 
| 
       104 
118 
     | 
    
         
             
            homepage: https://github.com/jonasrscampos/omniauth-gov
         
     | 
| 
       105 
119 
     | 
    
         
             
            licenses:
         
     | 
| 
       106 
120 
     | 
    
         
             
            - MIT
         
     | 
| 
         @@ -120,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       120 
134 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       121 
135 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       122 
136 
     | 
    
         
             
            requirements: []
         
     | 
| 
       123 
     | 
    
         
            -
            rubygems_version: 3. 
     | 
| 
      
 137 
     | 
    
         
            +
            rubygems_version: 3.3.5
         
     | 
| 
       124 
138 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       125 
139 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       126 
140 
     | 
    
         
             
            summary: Official OmniAuth strategy for GitHub.
         
     |