authinator 0.1.0 → 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
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: acaccc767c48cd514add3e18e616718f04d3a023
         | 
| 4 | 
            +
              data.tar.gz: d3309ca0fb8b6d79ba307894cc4c05ddf866a3e7
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 57960a2ddfffe2722a030f19dbac1f1a70f069f70587572a5b1147342a8be3a83e370449143335680db888859a8012a26eeede6263c8b0a3b015c666b2cd1104
         | 
| 7 | 
            +
              data.tar.gz: 0a42070c92fac997b6aac313a0149e598aaea4486596634b959111382ff267805d546739a102054fbc5fabb36f85c804f646118c7a14b74dd45b219f6aaf1089
         | 
| @@ -23,15 +23,16 @@ module Authinator | |
| 23 23 | 
             
                  @provider.site + @provider.token_url
         | 
| 24 24 | 
             
                end
         | 
| 25 25 |  | 
| 26 | 
            -
                def exchange(auth_code)
         | 
| 26 | 
            +
                def exchange(auth_code, redirect_uri)
         | 
| 27 27 | 
             
                  # auth_code = params[:code]
         | 
| 28 | 
            -
                   | 
| 28 | 
            +
                  fail 'Cannot Exchange Auth Code (auth_code missing)' if auth_code.nil? || auth_code.empty?
         | 
| 29 | 
            +
                  fail 'Cannot Exchange Auth Code (redirect_uri missing)' if redirect_uri.nil? || redirect_uri.empty?
         | 
| 29 30 |  | 
| 30 31 | 
             
                  case @provider.name
         | 
| 31 32 | 
             
                  when :google
         | 
| 32 | 
            -
                    exchange_with_google(auth_code)
         | 
| 33 | 
            +
                    exchange_with_google(auth_code, redirect_uri)
         | 
| 33 34 | 
             
                  when :stub
         | 
| 34 | 
            -
                    exchange_with_stub(auth_code)
         | 
| 35 | 
            +
                    exchange_with_stub(auth_code, redirect_uri)
         | 
| 35 36 | 
             
                  end
         | 
| 36 37 | 
             
                end
         | 
| 37 38 |  | 
| @@ -43,10 +44,10 @@ module Authinator | |
| 43 44 | 
             
                #   @provider_hash[:client_secret] = client_options.delete(:client_secret) if client_options[:client_secret]
         | 
| 44 45 | 
             
                # end
         | 
| 45 46 |  | 
| 46 | 
            -
                def exchange_with_google(code)
         | 
| 47 | 
            +
                def exchange_with_google(code, redirect_uri)
         | 
| 47 48 | 
             
                  @client = OAuth2::Client.new(@provider.client_id, @provider.client_secret, @provider.to_hash)
         | 
| 48 49 |  | 
| 49 | 
            -
                  token = @client.auth_code.get_token(code, redirect_uri:  | 
| 50 | 
            +
                  token = @client.auth_code.get_token(code, redirect_uri: redirect_uri)
         | 
| 50 51 |  | 
| 51 52 | 
             
                  # response = token.get('/api/resource', :params => { 'query_foo' => 'bar' })
         | 
| 52 53 | 
             
                  # response.class.name
         | 
| @@ -55,7 +56,7 @@ module Authinator | |
| 55 56 | 
             
                  token
         | 
| 56 57 | 
             
                end
         | 
| 57 58 |  | 
| 58 | 
            -
                def exchange_with_stub(_code)
         | 
| 59 | 
            +
                def exchange_with_stub(_code, _redirect_uri)
         | 
| 59 60 | 
             
                  @client = OAuth2::Client.new(
         | 
| 60 61 | 
             
                      @provider.client_id,
         | 
| 61 62 | 
             
                      @provider.client_secret,
         | 
| @@ -24,6 +24,7 @@ module Authinator | |
| 24 24 | 
             
                  @provider = Authinator.configuration.provider_for(provider_name)
         | 
| 25 25 |  | 
| 26 26 | 
             
                  @auth_code = (options.delete :auth_code if options[:auth_code]) || @params['code']
         | 
| 27 | 
            +
                  @redirect_uri = (options.delete :redirect_uri if options[:redirect_uri]) || @params['redirect_uri']
         | 
| 27 28 | 
             
                  @app_name = (options.delete :app_name if options[:app_name]) || application_name
         | 
| 28 29 | 
             
                  @valid_applications = (options.delete :valid_applications if options[:valid_applications]) || Authinator.configuration.valid_applications
         | 
| 29 30 | 
             
                end
         | 
| @@ -54,7 +55,7 @@ module Authinator | |
| 54 55 | 
             
                def handle(options = {})
         | 
| 55 56 | 
             
                  application = Doorkeeper::Application.where(name: @app_name)
         | 
| 56 57 | 
             
                  token_issuer = AuthCodeExchanger.new @provider
         | 
| 57 | 
            -
                  provider_access_token = token_issuer.exchange @auth_code
         | 
| 58 | 
            +
                  provider_access_token = token_issuer.exchange @auth_code, @redirect_uri
         | 
| 58 59 |  | 
| 59 60 | 
             
                  begin
         | 
| 60 61 | 
             
                    info = load_info(provider_access_token)
         | 
| @@ -72,6 +73,7 @@ module Authinator | |
| 72 73 | 
             
                    resource_owner_id: user.id,
         | 
| 73 74 | 
             
                    expires_in: expires_in,
         | 
| 74 75 | 
             
                    use_refresh_token: true,
         | 
| 76 | 
            +
                    scopes: :user,
         | 
| 75 77 | 
             
                  )
         | 
| 76 78 |  | 
| 77 79 | 
             
                  token_data = {
         | 
    
        data/lib/authinator/version.rb
    CHANGED
    
    
| @@ -19,12 +19,12 @@ describe Authinator::AuthCodeExchanger do | |
| 19 19 | 
             
                  client_secret: 'cl_sec',
         | 
| 20 20 | 
             
                  code: '4/code',
         | 
| 21 21 | 
             
                  grant_type: 'authorization_code',
         | 
| 22 | 
            +
                  redirect_uri: 'http://localhost:4200',
         | 
| 22 23 | 
             
                }
         | 
| 23 24 |  | 
| 24 25 | 
             
                @req_headers = {
         | 
| 25 26 | 
             
                  accept: '*/*',
         | 
| 26 27 | 
             
                  content_type: 'application/x-www-form-urlencoded',
         | 
| 27 | 
            -
                  user_agent: 'Faraday v0.9.0',
         | 
| 28 28 | 
             
                }
         | 
| 29 29 |  | 
| 30 30 | 
             
                @req_response = {
         | 
| @@ -60,7 +60,7 @@ describe Authinator::AuthCodeExchanger do | |
| 60 60 | 
             
                       headers: @req_headers).
         | 
| 61 61 | 
             
                  to_return(@req_response)
         | 
| 62 62 |  | 
| 63 | 
            -
                result = ace.exchange(@test_env[:code])
         | 
| 63 | 
            +
                result = ace.exchange(@test_env[:code], @test_env[:redirect_uri])
         | 
| 64 64 |  | 
| 65 65 | 
             
                expect(result.token).to eq @token_hash[:access_token]
         | 
| 66 66 | 
             
                expect(result.refresh_token).to eq @token_hash[:refresh_token]
         | 
| @@ -78,7 +78,7 @@ describe Authinator::AuthCodeExchanger do | |
| 78 78 | 
             
                         headers: @req_headers).
         | 
| 79 79 | 
             
                    to_return(@req_response)
         | 
| 80 80 |  | 
| 81 | 
            -
                  expect(ace.exchange(@test_env[:code])).to be_a klass
         | 
| 81 | 
            +
                  expect(ace.exchange(@test_env[:code], @test_env[:redirect_uri])).to be_a klass
         | 
| 82 82 | 
             
                end
         | 
| 83 83 | 
             
              end
         | 
| 84 84 |  | 
| @@ -89,7 +89,7 @@ describe Authinator::AuthCodeExchanger do | |
| 89 89 | 
             
                       headers: @req_headers).
         | 
| 90 90 | 
             
                  to_return(@req_response)
         | 
| 91 91 |  | 
| 92 | 
            -
                result = ace.exchange(@test_env[:code])
         | 
| 92 | 
            +
                result = ace.exchange(@test_env[:code], @test_env[:redirect_uri])
         | 
| 93 93 |  | 
| 94 94 | 
             
                expect(result.token).to eq @token_hash[:access_token]
         | 
| 95 95 | 
             
                expect(result.refresh_token).to eq @token_hash[:refresh_token]
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: authinator
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Alexander Bradner
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015- | 
| 11 | 
            +
            date: 2015-02-05 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: oauth2
         |