omniauth 0.2.4 → 0.2.5
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.
Potentially problematic release.
This version of omniauth might be problematic. Click here for more details.
- data/.autotest +9 -0
- data/.document +5 -0
- data/.gitignore +36 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/.yardopts +4 -0
- data/Gemfile +6 -1
- data/README.markdown +121 -0
- data/Rakefile +50 -2
- data/lib/omniauth/version.rb +18 -4
- data/oa-basic/.gemtest +0 -0
- data/oa-basic/.rspec +3 -0
- data/oa-basic/.yardopts +4 -0
- data/oa-basic/LICENSE +19 -0
- data/oa-basic/README.rdoc +34 -0
- data/oa-basic/Rakefile +6 -0
- data/oa-basic/lib/oa-basic.rb +1 -0
- data/oa-basic/lib/omniauth/basic.rb +8 -0
- data/oa-basic/lib/omniauth/strategies/http_basic.rb +56 -0
- data/oa-basic/lib/omniauth/version.rb +19 -0
- data/oa-basic/oa-basic.gemspec +28 -0
- data/oa-basic/spec/omniauth/strategies/basic_spec.rb +7 -0
- data/oa-basic/spec/spec_helper.rb +11 -0
- data/oa-core/.gemtest +0 -0
- data/oa-core/.rspec +3 -0
- data/oa-core/.yardopts +4 -0
- data/oa-core/LICENSE +19 -0
- data/oa-core/Rakefile +6 -0
- data/oa-core/autotest/discover.rb +1 -0
- data/oa-core/lib/oa-core.rb +1 -0
- data/oa-core/lib/omniauth/builder.rb +33 -0
- data/oa-core/lib/omniauth/core.rb +135 -0
- data/oa-core/lib/omniauth/form.rb +184 -0
- data/oa-core/lib/omniauth/strategy.rb +227 -0
- data/oa-core/lib/omniauth/test.rb +12 -0
- data/oa-core/lib/omniauth/test/phony_session.rb +8 -0
- data/oa-core/lib/omniauth/test/strategy_macros.rb +34 -0
- data/oa-core/lib/omniauth/test/strategy_test_case.rb +49 -0
- data/oa-core/lib/omniauth/version.rb +19 -0
- data/oa-core/oa-core.gemspec +24 -0
- data/oa-core/spec/omniauth/builder_spec.rb +20 -0
- data/oa-core/spec/omniauth/core_spec.rb +79 -0
- data/oa-core/spec/omniauth/strategy_spec.rb +358 -0
- data/oa-core/spec/spec_helper.rb +12 -0
- data/oa-enterprise/.gemtest +0 -0
- data/oa-enterprise/.rspec +3 -0
- data/oa-enterprise/.yardopts +4 -0
- data/oa-enterprise/LICENSE +19 -0
- data/oa-enterprise/README.rdoc +82 -0
- data/oa-enterprise/Rakefile +6 -0
- data/oa-enterprise/lib/oa-enterprise.rb +1 -0
- data/oa-enterprise/lib/omniauth/enterprise.rb +8 -0
- data/oa-enterprise/lib/omniauth/strategies/cas.rb +47 -0
- data/oa-enterprise/lib/omniauth/strategies/cas/configuration.rb +98 -0
- data/oa-enterprise/lib/omniauth/strategies/cas/service_ticket_validator.rb +84 -0
- data/oa-enterprise/lib/omniauth/strategies/ldap.rb +111 -0
- data/oa-enterprise/lib/omniauth/strategies/ldap/adaptor.rb +279 -0
- data/oa-enterprise/lib/omniauth/version.rb +19 -0
- data/oa-enterprise/oa-enterprise.gemspec +32 -0
- data/oa-enterprise/spec/fixtures/cas_failure.xml +4 -0
- data/oa-enterprise/spec/fixtures/cas_success.xml +8 -0
- data/oa-enterprise/spec/omniauth/strategies/cas_spec.rb +94 -0
- data/oa-enterprise/spec/spec_helper.rb +14 -0
- data/oa-more/.gemtest +0 -0
- data/oa-more/.rspec +3 -0
- data/oa-more/.yardopts +4 -0
- data/oa-more/LICENSE +19 -0
- data/oa-more/README.rdoc +22 -0
- data/oa-more/Rakefile +6 -0
- data/oa-more/lib/oa-more.rb +1 -0
- data/oa-more/lib/omniauth/more.rb +9 -0
- data/oa-more/lib/omniauth/strategies/flickr.rb +86 -0
- data/oa-more/lib/omniauth/strategies/windows_live.rb +39 -0
- data/oa-more/lib/omniauth/strategies/windows_live/windowslivelogin.rb +1143 -0
- data/oa-more/lib/omniauth/strategies/yupoo.rb +67 -0
- data/oa-more/lib/omniauth/version.rb +19 -0
- data/oa-more/oa-more.gemspec +30 -0
- data/oa-more/spec/omniauth/strategies/flickr_spec.rb +7 -0
- data/oa-more/spec/spec_helper.rb +11 -0
- data/oa-oauth/.gemtest +0 -0
- data/oa-oauth/.rspec +3 -0
- data/oa-oauth/.yardopts +4 -0
- data/oa-oauth/LICENSE +19 -0
- data/oa-oauth/README.rdoc +35 -0
- data/oa-oauth/Rakefile +6 -0
- data/oa-oauth/autotest/discover.rb +1 -0
- data/oa-oauth/lib/oa-oauth.rb +1 -0
- data/oa-oauth/lib/omniauth/oauth.rb +53 -0
- data/oa-oauth/lib/omniauth/strategies/bitly.rb +46 -0
- data/oa-oauth/lib/omniauth/strategies/dailymile.rb +64 -0
- data/oa-oauth/lib/omniauth/strategies/doit.rb +60 -0
- data/oa-oauth/lib/omniauth/strategies/dopplr.rb +53 -0
- data/oa-oauth/lib/omniauth/strategies/douban.rb +60 -0
- data/oa-oauth/lib/omniauth/strategies/evernote.rb +54 -0
- data/oa-oauth/lib/omniauth/strategies/facebook.rb +70 -0
- data/oa-oauth/lib/omniauth/strategies/foursquare.rb +62 -0
- data/oa-oauth/lib/omniauth/strategies/github.rb +50 -0
- data/oa-oauth/lib/omniauth/strategies/goodreads.rb +44 -0
- data/oa-oauth/lib/omniauth/strategies/google.rb +80 -0
- data/oa-oauth/lib/omniauth/strategies/gowalla.rb +64 -0
- data/oa-oauth/lib/omniauth/strategies/hyves.rb +67 -0
- data/oa-oauth/lib/omniauth/strategies/identica.rb +49 -0
- data/oa-oauth/lib/omniauth/strategies/instagram.rb +56 -0
- data/oa-oauth/lib/omniauth/strategies/instapaper.rb +40 -0
- data/oa-oauth/lib/omniauth/strategies/linked_in.rb +55 -0
- data/oa-oauth/lib/omniauth/strategies/meetup.rb +56 -0
- data/oa-oauth/lib/omniauth/strategies/miso.rb +41 -0
- data/oa-oauth/lib/omniauth/strategies/mixi.rb +59 -0
- data/oa-oauth/lib/omniauth/strategies/netflix.rb +65 -0
- data/oa-oauth/lib/omniauth/strategies/oauth.rb +85 -0
- data/oa-oauth/lib/omniauth/strategies/oauth2.rb +98 -0
- data/oa-oauth/lib/omniauth/strategies/qzone.rb +69 -0
- data/oa-oauth/lib/omniauth/strategies/rdio.rb +45 -0
- data/oa-oauth/lib/omniauth/strategies/renren.rb +87 -0
- data/oa-oauth/lib/omniauth/strategies/salesforce.rb +44 -0
- data/oa-oauth/lib/omniauth/strategies/smug_mug.rb +42 -0
- data/oa-oauth/lib/omniauth/strategies/sound_cloud.rb +46 -0
- data/oa-oauth/lib/omniauth/strategies/t163.rb +57 -0
- data/oa-oauth/lib/omniauth/strategies/teambox.rb +49 -0
- data/oa-oauth/lib/omniauth/strategies/thirty_seven_signals.rb +41 -0
- data/oa-oauth/lib/omniauth/strategies/tqq.rb +64 -0
- data/oa-oauth/lib/omniauth/strategies/trade_me.rb +45 -0
- data/oa-oauth/lib/omniauth/strategies/trip_it.rb +22 -0
- data/oa-oauth/lib/omniauth/strategies/tsina.rb +79 -0
- data/oa-oauth/lib/omniauth/strategies/tsohu.rb +57 -0
- data/oa-oauth/lib/omniauth/strategies/tumblr.rb +60 -0
- data/oa-oauth/lib/omniauth/strategies/twitter.rb +57 -0
- data/oa-oauth/lib/omniauth/strategies/type_pad.rb +76 -0
- data/oa-oauth/lib/omniauth/strategies/vimeo.rb +54 -0
- data/oa-oauth/lib/omniauth/strategies/vkontakte.rb +84 -0
- data/oa-oauth/lib/omniauth/strategies/xauth.rb +67 -0
- data/oa-oauth/lib/omniauth/strategies/yahoo.rb +55 -0
- data/oa-oauth/lib/omniauth/strategies/yammer.rb +43 -0
- data/oa-oauth/lib/omniauth/strategies/you_tube.rb +73 -0
- data/oa-oauth/lib/omniauth/version.rb +19 -0
- data/oa-oauth/oa-oauth.gemspec +33 -0
- data/oa-oauth/spec/fixtures/basecamp_200.xml +24 -0
- data/oa-oauth/spec/fixtures/campfire_200.json +10 -0
- data/oa-oauth/spec/omniauth/strategies/bitly_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/dailymile_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/doit_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/dopplr_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/douban_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/evernote_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/facebook_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/foursquare_spec.rb +18 -0
- data/oa-oauth/spec/omniauth/strategies/github_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/goodreads_spec.rb +6 -0
- data/oa-oauth/spec/omniauth/strategies/google_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/gowalla_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/hyves_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/identica_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/linked_in_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/meetup_spec.rb +14 -0
- data/oa-oauth/spec/omniauth/strategies/miso_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/netflix_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/oauth2_spec.rb +0 -0
- data/oa-oauth/spec/omniauth/strategies/oauth_spec.rb +77 -0
- data/oa-oauth/spec/omniauth/strategies/rdio_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/salesforce_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/smug_mug_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/sound_cloud_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/t163_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/teambox_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/thirty_seven_signals_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/trade_me_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/trip_it_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/tsina_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/tumblr_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/twitter_spec.rb +20 -0
- data/oa-oauth/spec/omniauth/strategies/type_pad_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/vimeo_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/vkontakte_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/yahoo_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/yammer_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/you_tube_spec.rb +5 -0
- data/oa-oauth/spec/spec_helper.rb +27 -0
- data/oa-oauth/spec/support/shared_examples.rb +29 -0
- data/oa-openid/.gemtest +0 -0
- data/oa-openid/.rspec +3 -0
- data/oa-openid/.yardopts +4 -0
- data/oa-openid/LICENSE +19 -0
- data/oa-openid/README.rdoc +51 -0
- data/oa-openid/Rakefile +6 -0
- data/oa-openid/lib/oa-openid.rb +1 -0
- data/oa-openid/lib/omniauth/openid.rb +59 -0
- data/oa-openid/lib/omniauth/openid/gapps.rb +32 -0
- data/oa-openid/lib/omniauth/strategies/google_apps.rb +23 -0
- data/oa-openid/lib/omniauth/strategies/open_id.rb +132 -0
- data/oa-openid/lib/omniauth/version.rb +19 -0
- data/oa-openid/oa-openid.gemspec +29 -0
- data/oa-openid/spec/omniauth/strategies/open_id_spec.rb +71 -0
- data/oa-openid/spec/spec_helper.rb +14 -0
- data/omniauth.gemspec +3 -3
- data/tasks/all.rb +134 -0
- metadata +199 -9
- data/README.rdoc +0 -17
| @@ -0,0 +1,227 @@ | |
| 1 | 
            +
            require 'omniauth/core'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module OmniAuth
         | 
| 4 | 
            +
              class NoSessionError < StandardError; end
         | 
| 5 | 
            +
              # The Strategy is the base unit of OmniAuth's ability to
         | 
| 6 | 
            +
              # wrangle multiple providers. Each strategy provided by 
         | 
| 7 | 
            +
              # OmniAuth includes this mixin to gain the default functionality
         | 
| 8 | 
            +
              # necessary to be compatible with the OmniAuth library.
         | 
| 9 | 
            +
              module Strategy
         | 
| 10 | 
            +
                def self.included(base)
         | 
| 11 | 
            +
                  OmniAuth.strategies << base
         | 
| 12 | 
            +
                  base.class_eval do
         | 
| 13 | 
            +
                    attr_reader :app, :name, :env, :options, :response
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def initialize(app, name, *args, &block)
         | 
| 18 | 
            +
                  @app = app
         | 
| 19 | 
            +
                  @name = name.to_sym
         | 
| 20 | 
            +
                  @options = args.last.is_a?(Hash) ? args.pop : {}
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  yield self if block_given?
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                def inspect
         | 
| 26 | 
            +
                  "#<#{self.class.to_s}>"
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                def call(env)
         | 
| 30 | 
            +
                  dup.call!(env)
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                def call!(env)
         | 
| 34 | 
            +
                  raise OmniAuth::NoSessionError.new("You must provide a session to use OmniAuth.") unless env['rack.session']
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  @env = env
         | 
| 37 | 
            +
                  @env['omniauth.strategy'] = self if on_auth_path?
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  return mock_call!(env) if OmniAuth.config.test_mode
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  return request_call if on_request_path? && OmniAuth.config.allowed_request_methods.include?(request.request_method.downcase.to_sym)
         | 
| 42 | 
            +
                  return callback_call if on_callback_path?
         | 
| 43 | 
            +
                  return other_phase if respond_to?(:other_phase)
         | 
| 44 | 
            +
                  @app.call(env)  
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
                
         | 
| 47 | 
            +
                # Performs the steps necessary to run the request phase of a strategy.
         | 
| 48 | 
            +
                def request_call
         | 
| 49 | 
            +
                  setup_phase
         | 
| 50 | 
            +
                  if response = call_through_to_app
         | 
| 51 | 
            +
                    response
         | 
| 52 | 
            +
                  else
         | 
| 53 | 
            +
                    if request.params['origin']
         | 
| 54 | 
            +
                      @env['rack.session']['omniauth.origin'] = request.params['origin']
         | 
| 55 | 
            +
                    elsif env['HTTP_REFERER'] && !env['HTTP_REFERER'].match(/#{request_path}$/)
         | 
| 56 | 
            +
                      @env['rack.session']['omniauth.origin'] = env['HTTP_REFERER']
         | 
| 57 | 
            +
                    end
         | 
| 58 | 
            +
                    request_phase
         | 
| 59 | 
            +
                  end
         | 
| 60 | 
            +
                end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                # Performs the steps necessary to run the callback phase of a strategy.
         | 
| 63 | 
            +
                def callback_call
         | 
| 64 | 
            +
                  setup_phase
         | 
| 65 | 
            +
                  @env['omniauth.origin'] = session.delete('omniauth.origin')
         | 
| 66 | 
            +
                  @env['omniauth.origin'] = nil if env['omniauth.origin'] == ''
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                  callback_phase
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                def on_auth_path?
         | 
| 72 | 
            +
                  on_request_path? || on_callback_path?
         | 
| 73 | 
            +
                end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                def on_request_path?
         | 
| 76 | 
            +
                  current_path.casecmp(request_path) == 0
         | 
| 77 | 
            +
                end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                def on_callback_path?
         | 
| 80 | 
            +
                  current_path.casecmp(callback_path) == 0
         | 
| 81 | 
            +
                end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                def mock_call!(env)
         | 
| 84 | 
            +
                  return mock_request_call if on_request_path? 
         | 
| 85 | 
            +
                  return mock_callback_call if on_callback_path?
         | 
| 86 | 
            +
                  call_app!
         | 
| 87 | 
            +
                end
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                def mock_request_call
         | 
| 90 | 
            +
                  setup_phase
         | 
| 91 | 
            +
                  return response if response = call_through_to_app
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                  if request.params['origin']
         | 
| 94 | 
            +
                    @env['rack.session']['omniauth.origin'] = request.params['origin']
         | 
| 95 | 
            +
                  elsif env['HTTP_REFERER'] && !env['HTTP_REFERER'].match(/#{request_path}$/)
         | 
| 96 | 
            +
                    @env['rack.session']['omniauth.origin'] = env['HTTP_REFERER']
         | 
| 97 | 
            +
                  end
         | 
| 98 | 
            +
                  redirect(callback_path)
         | 
| 99 | 
            +
                end
         | 
| 100 | 
            +
             | 
| 101 | 
            +
                def mock_callback_call
         | 
| 102 | 
            +
                  setup_phase
         | 
| 103 | 
            +
                  mocked_auth = OmniAuth.mock_auth_for(name.to_sym)
         | 
| 104 | 
            +
                  if mocked_auth.is_a?(Symbol)
         | 
| 105 | 
            +
                    fail!(mocked_auth)
         | 
| 106 | 
            +
                  else
         | 
| 107 | 
            +
                    @env['omniauth.auth'] = mocked_auth
         | 
| 108 | 
            +
                    @env['omniauth.origin'] = session.delete('omniauth.origin')
         | 
| 109 | 
            +
                    @env['omniauth.origin'] = nil if env['omniauth.origin'] == ''
         | 
| 110 | 
            +
                    call_app!
         | 
| 111 | 
            +
                  end
         | 
| 112 | 
            +
                end
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                def setup_phase
         | 
| 115 | 
            +
                  if options[:setup].respond_to?(:call)
         | 
| 116 | 
            +
                    options[:setup].call(env)
         | 
| 117 | 
            +
                  elsif options[:setup]
         | 
| 118 | 
            +
                    setup_env = env.merge('PATH_INFO' => setup_path, 'REQUEST_METHOD' => 'GET')
         | 
| 119 | 
            +
                    call_app!(setup_env)
         | 
| 120 | 
            +
                  end
         | 
| 121 | 
            +
                end
         | 
| 122 | 
            +
             | 
| 123 | 
            +
                def request_phase
         | 
| 124 | 
            +
                  raise NotImplementedError
         | 
| 125 | 
            +
                end
         | 
| 126 | 
            +
             | 
| 127 | 
            +
                def callback_phase
         | 
| 128 | 
            +
                  @env['omniauth.auth'] = auth_hash
         | 
| 129 | 
            +
                  call_app!
         | 
| 130 | 
            +
                end
         | 
| 131 | 
            +
             | 
| 132 | 
            +
                def path_prefix
         | 
| 133 | 
            +
                  options[:path_prefix] || OmniAuth.config.path_prefix
         | 
| 134 | 
            +
                end
         | 
| 135 | 
            +
             | 
| 136 | 
            +
                def request_path
         | 
| 137 | 
            +
                  options[:request_path] || "#{path_prefix}/#{name}"
         | 
| 138 | 
            +
                end
         | 
| 139 | 
            +
             | 
| 140 | 
            +
                def callback_path
         | 
| 141 | 
            +
                  options[:callback_path] || "#{path_prefix}/#{name}/callback"
         | 
| 142 | 
            +
                end
         | 
| 143 | 
            +
             | 
| 144 | 
            +
                def setup_path
         | 
| 145 | 
            +
                  options[:setup_path] || "#{path_prefix}/#{name}/setup"
         | 
| 146 | 
            +
                end
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                def current_path
         | 
| 149 | 
            +
                  request.path_info.downcase.sub(/\/$/,'')
         | 
| 150 | 
            +
                end
         | 
| 151 | 
            +
             | 
| 152 | 
            +
                def query_string
         | 
| 153 | 
            +
                  request.query_string.empty? ? "" : "?#{request.query_string}"
         | 
| 154 | 
            +
                end
         | 
| 155 | 
            +
             | 
| 156 | 
            +
                def call_through_to_app
         | 
| 157 | 
            +
                  status, headers, body = *call_app!
         | 
| 158 | 
            +
                  @response = Rack::Response.new(body, status, headers)
         | 
| 159 | 
            +
             | 
| 160 | 
            +
                  status == 404 ? nil : @response.finish
         | 
| 161 | 
            +
                end
         | 
| 162 | 
            +
             | 
| 163 | 
            +
                def call_app!(env = @env)
         | 
| 164 | 
            +
                  @app.call(env)
         | 
| 165 | 
            +
                end
         | 
| 166 | 
            +
             | 
| 167 | 
            +
                def auth_hash
         | 
| 168 | 
            +
                  {
         | 
| 169 | 
            +
                    'provider' => name.to_s,
         | 
| 170 | 
            +
                    'uid' => nil
         | 
| 171 | 
            +
                  }
         | 
| 172 | 
            +
                end
         | 
| 173 | 
            +
             | 
| 174 | 
            +
                def full_host
         | 
| 175 | 
            +
                  case OmniAuth.config.full_host
         | 
| 176 | 
            +
                    when String
         | 
| 177 | 
            +
                      OmniAuth.config.full_host
         | 
| 178 | 
            +
                    when Proc
         | 
| 179 | 
            +
                      OmniAuth.config.full_host.call(env)
         | 
| 180 | 
            +
                    else
         | 
| 181 | 
            +
                      uri = URI.parse(request.url.gsub(/\?.*$/,''))
         | 
| 182 | 
            +
                      uri.path = ''
         | 
| 183 | 
            +
                      uri.query = nil
         | 
| 184 | 
            +
                      uri.to_s
         | 
| 185 | 
            +
                  end
         | 
| 186 | 
            +
                end
         | 
| 187 | 
            +
             | 
| 188 | 
            +
                def callback_url
         | 
| 189 | 
            +
                  full_host + script_name + callback_path + query_string
         | 
| 190 | 
            +
                end
         | 
| 191 | 
            +
             | 
| 192 | 
            +
                def script_name
         | 
| 193 | 
            +
                  @env['SCRIPT_NAME'] || ''
         | 
| 194 | 
            +
                end
         | 
| 195 | 
            +
             | 
| 196 | 
            +
                def session
         | 
| 197 | 
            +
                  @env['rack.session']
         | 
| 198 | 
            +
                end
         | 
| 199 | 
            +
             | 
| 200 | 
            +
                def request
         | 
| 201 | 
            +
                  @request ||= Rack::Request.new(@env)
         | 
| 202 | 
            +
                end
         | 
| 203 | 
            +
             | 
| 204 | 
            +
                def redirect(uri)
         | 
| 205 | 
            +
                  r = Rack::Response.new
         | 
| 206 | 
            +
             | 
| 207 | 
            +
                  if options[:iframe]
         | 
| 208 | 
            +
                    r.write("<script type='text/javascript' charset='utf-8'>top.location.href = '#{uri}';</script>")
         | 
| 209 | 
            +
                  else
         | 
| 210 | 
            +
                    r.write("Redirecting to #{uri}...")
         | 
| 211 | 
            +
                    r.redirect(uri)
         | 
| 212 | 
            +
                  end
         | 
| 213 | 
            +
             | 
| 214 | 
            +
                  r.finish
         | 
| 215 | 
            +
                end
         | 
| 216 | 
            +
             | 
| 217 | 
            +
                def user_info; {} end
         | 
| 218 | 
            +
             | 
| 219 | 
            +
                def fail!(message_key, exception = nil)
         | 
| 220 | 
            +
                  self.env['omniauth.error'] = exception
         | 
| 221 | 
            +
                  self.env['omniauth.error.type'] = message_key.to_sym
         | 
| 222 | 
            +
                  self.env['omniauth.error.strategy'] = self
         | 
| 223 | 
            +
             | 
| 224 | 
            +
                  OmniAuth.config.on_failure.call(self.env)
         | 
| 225 | 
            +
                end
         | 
| 226 | 
            +
              end
         | 
| 227 | 
            +
            end
         | 
| @@ -0,0 +1,12 @@ | |
| 1 | 
            +
            module OmniAuth
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              # Support for testing OmniAuth strategies.
         | 
| 4 | 
            +
              module Test
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                autoload :PhonySession,     'omniauth/test/phony_session'
         | 
| 7 | 
            +
                autoload :StrategyMacros,   'omniauth/test/strategy_macros'
         | 
| 8 | 
            +
                autoload :StrategyTestCase, 'omniauth/test/strategy_test_case'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            end
         | 
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            module OmniAuth
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              module Test
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                module StrategyMacros
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                  def sets_an_auth_hash
         | 
| 8 | 
            +
                    it 'should set an auth hash' do
         | 
| 9 | 
            +
                      last_request.env['omniauth.auth'].should be_kind_of(Hash)
         | 
| 10 | 
            +
                    end
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  def sets_provider_to(provider)
         | 
| 14 | 
            +
                    it "should set the provider to #{provider}" do
         | 
| 15 | 
            +
                      (last_request.env['omniauth.auth'] || {})['provider'].should == provider
         | 
| 16 | 
            +
                    end
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  def sets_uid_to(uid)
         | 
| 20 | 
            +
                    it "should set the UID to #{uid}" do
         | 
| 21 | 
            +
                      (last_request.env['omniauth.auth'] || {})['uid'].should == uid
         | 
| 22 | 
            +
                    end
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  def sets_user_info_to(user_info)
         | 
| 26 | 
            +
                    it "should set the user_info to #{user_info}" do
         | 
| 27 | 
            +
                      (last_request.env['omniauth.auth'] || {})['user_info'].should == user_info
         | 
| 28 | 
            +
                    end
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            end
         | 
| @@ -0,0 +1,49 @@ | |
| 1 | 
            +
            require 'rack'
         | 
| 2 | 
            +
            require 'omniauth/test'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module OmniAuth
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              module Test
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                # Support for testing OmniAuth strategies.
         | 
| 9 | 
            +
                #
         | 
| 10 | 
            +
                # @example Usage
         | 
| 11 | 
            +
                #   class MyStrategyTest < Test::Unit::TestCase
         | 
| 12 | 
            +
                #     include OmniAuth::Test::StrategyTestCase
         | 
| 13 | 
            +
                #     def strategy
         | 
| 14 | 
            +
                #       # return the parameters to a Rack::Builder map call:
         | 
| 15 | 
            +
                #       [MyStrategy.new, :some, :configuration, :options => 'here']
         | 
| 16 | 
            +
                #     end
         | 
| 17 | 
            +
                #     setup do
         | 
| 18 | 
            +
                #       post '/auth/my_strategy/callback', :user => { 'name' => 'Dylan', 'id' => '445' }
         | 
| 19 | 
            +
                #     end
         | 
| 20 | 
            +
                #   end
         | 
| 21 | 
            +
                module StrategyTestCase
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  def app
         | 
| 24 | 
            +
                    strat = self.strategy
         | 
| 25 | 
            +
                    resp = self.app_response
         | 
| 26 | 
            +
                    Rack::Builder.new {
         | 
| 27 | 
            +
                      use OmniAuth::Test::PhonySession
         | 
| 28 | 
            +
                      use *strat
         | 
| 29 | 
            +
                      run lambda {|env| [404, {'Content-Type' => 'text/plain'}, [resp || env.key?('omniauth.auth').to_s]] }
         | 
| 30 | 
            +
                    }.to_app
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  def app_response
         | 
| 34 | 
            +
                    nil
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  def session
         | 
| 38 | 
            +
                    last_request.env['rack.session']
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  def strategy
         | 
| 42 | 
            +
                    raise NotImplementedError.new('Including specs must define #strategy')
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            module OmniAuth
         | 
| 2 | 
            +
              module Version
         | 
| 3 | 
            +
                unless defined?(::OmniAuth::Version::MAJOR)
         | 
| 4 | 
            +
                  MAJOR = 0
         | 
| 5 | 
            +
                end
         | 
| 6 | 
            +
                unless defined?(::OmniAuth::Version::MINOR)
         | 
| 7 | 
            +
                  MINOR = 2
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
                unless defined?(::OmniAuth::Version::PATCH)
         | 
| 10 | 
            +
                  PATCH = 5
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
                unless defined?(::OmniAuth::Version::PRE)
         | 
| 13 | 
            +
                  PRE   = nil
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
                unless defined?(::OmniAuth::Version::STRING)
         | 
| 16 | 
            +
                  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            require File.expand_path('../lib/omniauth/version', __FILE__)
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            Gem::Specification.new do |gem|
         | 
| 5 | 
            +
              gem.add_development_dependency 'maruku', '~> 0.6'
         | 
| 6 | 
            +
              gem.add_development_dependency 'simplecov', '~> 0.4'
         | 
| 7 | 
            +
              gem.add_development_dependency 'rack-test', '~> 0.5'
         | 
| 8 | 
            +
              gem.add_development_dependency 'rake', '~> 0.8'
         | 
| 9 | 
            +
              gem.add_development_dependency 'rspec', '~> 2.5'
         | 
| 10 | 
            +
              gem.add_development_dependency 'yard', '~> 0.6'
         | 
| 11 | 
            +
              gem.add_development_dependency 'ZenTest', '~> 4.5'
         | 
| 12 | 
            +
              gem.name = 'oa-core'
         | 
| 13 | 
            +
              gem.version = OmniAuth::Version::STRING
         | 
| 14 | 
            +
              gem.description = %q{Core strategies for OmniAuth.}
         | 
| 15 | 
            +
              gem.summary = gem.description
         | 
| 16 | 
            +
              gem.email = ['michael@intridea.com', 'sferik@gmail.com']
         | 
| 17 | 
            +
              gem.homepage = 'http://github.com/intridea/omniauth'
         | 
| 18 | 
            +
              gem.authors = ['Michael Bleigh', 'Erik Michaels-Ober']
         | 
| 19 | 
            +
              gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
         | 
| 20 | 
            +
              gem.files = `git ls-files`.split("\n")
         | 
| 21 | 
            +
              gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
         | 
| 22 | 
            +
              gem.require_paths = ['lib']
         | 
| 23 | 
            +
              gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if gem.respond_to? :required_rubygems_version=
         | 
| 24 | 
            +
            end
         | 
| @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            require File.expand_path('../../spec_helper', __FILE__)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe OmniAuth::Builder do
         | 
| 4 | 
            +
              describe '#provider' do
         | 
| 5 | 
            +
                it 'should translate a symbol to a constant' do
         | 
| 6 | 
            +
                  OmniAuth::Strategies.should_receive(:const_get).with('MyStrategy').and_return(Class.new)
         | 
| 7 | 
            +
                  OmniAuth::Builder.new(nil) do
         | 
| 8 | 
            +
                    provider :my_strategy
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                it 'should also just accept a class' do
         | 
| 13 | 
            +
                  class ::ExampleClass; end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  lambda{ OmniAuth::Builder.new(nil) do
         | 
| 16 | 
            +
                    provider ::ExampleClass
         | 
| 17 | 
            +
                  end }.should_not raise_error
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            end
         | 
| @@ -0,0 +1,79 @@ | |
| 1 | 
            +
            require File.expand_path('../../spec_helper', __FILE__)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe OmniAuth do
         | 
| 4 | 
            +
              describe '.strategies' do
         | 
| 5 | 
            +
                it 'should increase when a new strategy is made' do
         | 
| 6 | 
            +
                  lambda{ class ExampleStrategy
         | 
| 7 | 
            +
                    include OmniAuth::Strategy
         | 
| 8 | 
            +
                  end }.should change(OmniAuth.strategies, :size).by(1)
         | 
| 9 | 
            +
                  OmniAuth.strategies.last.should == ExampleStrategy
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              context 'configuration' do
         | 
| 14 | 
            +
                it 'should be callable from .configure' do
         | 
| 15 | 
            +
                  OmniAuth.configure do |c|
         | 
| 16 | 
            +
                    c.should be_kind_of(OmniAuth::Configuration)
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                before do
         | 
| 21 | 
            +
                  @old_path_prefix = OmniAuth.config.path_prefix
         | 
| 22 | 
            +
                  @old_on_failure  = OmniAuth.config.on_failure
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                after do
         | 
| 26 | 
            +
                  OmniAuth.configure do |config|
         | 
| 27 | 
            +
                    config.path_prefix = @old_path_prefix
         | 
| 28 | 
            +
                    config.on_failure  = @old_on_failure
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                it 'should be able to set the path' do
         | 
| 33 | 
            +
                  OmniAuth.configure do |config|
         | 
| 34 | 
            +
                    config.path_prefix = '/awesome'
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  OmniAuth.config.path_prefix.should == '/awesome'
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                it 'should be able to set the on_failure rack app' do
         | 
| 41 | 
            +
                  OmniAuth.configure do |config|
         | 
| 42 | 
            +
                    config.on_failure do
         | 
| 43 | 
            +
                      'yoyo'
         | 
| 44 | 
            +
                    end
         | 
| 45 | 
            +
                  end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                  OmniAuth.config.on_failure.call.should == 'yoyo'
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
              end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
              describe '::Utils' do
         | 
| 52 | 
            +
                describe '.deep_merge' do
         | 
| 53 | 
            +
                  it 'should combine hashes' do
         | 
| 54 | 
            +
                    OmniAuth::Utils.deep_merge({'abc' => {'def' => 123}}, {'abc' => {'foo' => 'bar'}}).should == {
         | 
| 55 | 
            +
                      'abc' => {'def' => 123, 'foo' => 'bar'}
         | 
| 56 | 
            +
                    }
         | 
| 57 | 
            +
                  end
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                describe '.camelize' do
         | 
| 61 | 
            +
                  it 'should work on normal cases' do
         | 
| 62 | 
            +
                    {
         | 
| 63 | 
            +
                      'some_word' => 'SomeWord',
         | 
| 64 | 
            +
                      'AnotherWord' => 'AnotherWord',
         | 
| 65 | 
            +
                      'one' => 'One',
         | 
| 66 | 
            +
                      'three_words_now' => 'ThreeWordsNow'
         | 
| 67 | 
            +
                    }.each_pair{ |k,v| OmniAuth::Utils.camelize(k).should == v }
         | 
| 68 | 
            +
                  end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                  it 'should work in special cases' do
         | 
| 71 | 
            +
                    {
         | 
| 72 | 
            +
                      'oauth' => "OAuth",
         | 
| 73 | 
            +
                      'openid' => 'OpenID',
         | 
| 74 | 
            +
                      'open_id' => 'OpenID'
         | 
| 75 | 
            +
                    }.each_pair{ |k,v| OmniAuth::Utils.camelize(k).should == v}
         | 
| 76 | 
            +
                  end
         | 
| 77 | 
            +
                end
         | 
| 78 | 
            +
              end
         | 
| 79 | 
            +
            end
         |