pax_global_header00006660000000000000000000000064121560717000014511gustar00rootroot0000000000000052 comment=cfc180b669df636011a05e58be2db238ff17258b ruby-omniauth-oauth-1.0.1/000077500000000000000000000000001215607170000154315ustar00rootroot00000000000000ruby-omniauth-oauth-1.0.1/.gitignore000066400000000000000000000002321215607170000174160ustar00rootroot00000000000000*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp ruby-omniauth-oauth-1.0.1/.rspec000066400000000000000000000000321215607170000165410ustar00rootroot00000000000000--color --format=progress ruby-omniauth-oauth-1.0.1/Gemfile000066400000000000000000000002411215607170000167210ustar00rootroot00000000000000source 'http://rubygems.org' gemspec group :development, :test do gem 'guard' gem 'guard-rspec' gem 'guard-bundler' gem 'growl' gem 'rb-fsevent' end ruby-omniauth-oauth-1.0.1/Guardfile000066400000000000000000000003621215607170000172570ustar00rootroot00000000000000guard 'rspec', :version => 2 do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } watch('spec/spec_helper.rb') { "spec" } end guard 'bundler' do watch('Gemfile') watch(/^.+\.gemspec/) end ruby-omniauth-oauth-1.0.1/README.md000066400000000000000000000053641215607170000167200ustar00rootroot00000000000000# OmniAuth OAuth **Note:** This gem is designed to work with the in-beta OmniAuth 1.0 library. It will not be officially released on RubyGems.org until OmniAuth 1.0 is released. This gem contains a generic OAuth strategy for OmniAuth. It is meant to serve as a building block strategy for other strategies and not to be used independently (since it has no inherent way to gather uid and user info). ## Creating an OAuth Strategy To create an OmniAuth OAuth strategy using this gem, you can simply subclass it and add a few extra methods like so: require 'omniauth-oauth' module OmniAuth module Strategies class SomeSite < OmniAuth::Strategies::OAuth # Give your strategy a name. option :name, "some_site" # This is where you pass the options you would pass when # initializing your consumer from the OAuth gem. option :client_options, {:site => "https://api.somesite.com"} # These are called after authentication has succeeded. If # possible, you should try to set the UID without making # additional calls (if the user id is returned with the token # or as a URI parameter). This may not be possible with all # providers. uid{ request.params['user_id'] } info do { :name => raw_info['name'], :location => raw_info['city'] } end extra do { 'raw_info' => raw_info } end def raw_info @raw_info ||= MultiJson.decode(access_token.get('/me.json')).body end end end end That's pretty much it! ## License Copyright (C) 2012 by Michael Bleigh and Intridea, Inc. 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 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. ruby-omniauth-oauth-1.0.1/Rakefile000066400000000000000000000002561215607170000171010ustar00rootroot00000000000000#!/usr/bin/env rake require "bundler/gem_tasks" require 'rspec/core/rake_task' desc 'Default: run specs.' task :default => :spec desc "Run specs" RSpec::Core::RakeTask.new ruby-omniauth-oauth-1.0.1/lib/000077500000000000000000000000001215607170000161775ustar00rootroot00000000000000ruby-omniauth-oauth-1.0.1/lib/omniauth-oauth.rb000066400000000000000000000001061215607170000214630ustar00rootroot00000000000000require "omniauth-oauth/version" require 'omniauth/strategies/oauth' ruby-omniauth-oauth-1.0.1/lib/omniauth-oauth/000077500000000000000000000000001215607170000211415ustar00rootroot00000000000000ruby-omniauth-oauth-1.0.1/lib/omniauth-oauth/version.rb000066400000000000000000000000771215607170000231570ustar00rootroot00000000000000module OmniAuth module OAuth VERSION = "1.0.1" end end ruby-omniauth-oauth-1.0.1/lib/omniauth/000077500000000000000000000000001215607170000200235ustar00rootroot00000000000000ruby-omniauth-oauth-1.0.1/lib/omniauth/strategies/000077500000000000000000000000001215607170000221755ustar00rootroot00000000000000ruby-omniauth-oauth-1.0.1/lib/omniauth/strategies/oauth.rb000066400000000000000000000053401215607170000236440ustar00rootroot00000000000000require 'multi_json' require 'oauth' require 'omniauth' module OmniAuth module Strategies class OAuth include OmniAuth::Strategy args [:consumer_key, :consumer_secret] option :consumer_key, nil option :consumer_secret, nil option :client_options, {} option :open_timeout, 30 option :read_timeout, 30 option :authorize_params, {} option :request_params, {} attr_reader :access_token def consumer consumer = ::OAuth::Consumer.new(options.consumer_key, options.consumer_secret, options.client_options) consumer.http.open_timeout = options.open_timeout if options.open_timeout consumer.http.read_timeout = options.read_timeout if options.read_timeout consumer end def request_phase request_token = consumer.get_request_token({:oauth_callback => callback_url}, options.request_params) session['oauth'] ||= {} session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret} if request_token.callback_confirmed? redirect request_token.authorize_url(options[:authorize_params]) else redirect request_token.authorize_url(options[:authorize_params].merge(:oauth_callback => callback_url)) end rescue ::Timeout::Error => e fail!(:timeout, e) rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e fail!(:service_unavailable, e) end def callback_phase raise OmniAuth::NoSessionError.new("Session Expired") if session['oauth'].nil? request_token = ::OAuth::RequestToken.new(consumer, session['oauth'][name.to_s].delete('request_token'), session['oauth'][name.to_s].delete('request_secret')) opts = {} if session['oauth'][name.to_s]['callback_confirmed'] opts[:oauth_verifier] = request['oauth_verifier'] else opts[:oauth_callback] = callback_url end @access_token = request_token.get_access_token(opts) super rescue ::Timeout::Error => e fail!(:timeout, e) rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e fail!(:service_unavailable, e) rescue ::OAuth::Unauthorized => e fail!(:invalid_credentials, e) rescue ::MultiJson::DecodeError => e fail!(:invalid_response, e) rescue ::OmniAuth::NoSessionError => e fail!(:session_expired, e) end credentials do {'token' => access_token.token, 'secret' => access_token.secret} end extra do {'access_token' => access_token} end end end end OmniAuth.config.add_camelization 'oauth', 'OAuth' ruby-omniauth-oauth-1.0.1/metadata.yml000066400000000000000000000060021215607170000177320ustar00rootroot00000000000000--- !ruby/object:Gem::Specification name: omniauth-oauth version: !ruby/object:Gem::Version version: 1.0.1 prerelease: platform: ruby authors: - Michael Bleigh autorequire: bindir: bin cert_chain: [] date: 2012-03-02 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: omniauth requirement: &70329159031760 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '1.0' type: :runtime prerelease: false version_requirements: *70329159031760 - !ruby/object:Gem::Dependency name: oauth requirement: &70329159031340 !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :runtime prerelease: false version_requirements: *70329159031340 - !ruby/object:Gem::Dependency name: rspec requirement: &70329159030800 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '2.6' type: :development prerelease: false version_requirements: *70329159030800 - !ruby/object:Gem::Dependency name: webmock requirement: &70329159030380 !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: *70329159030380 - !ruby/object:Gem::Dependency name: simplecov requirement: &70329159029920 !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: *70329159029920 - !ruby/object:Gem::Dependency name: rack-test requirement: &70329159029500 !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: *70329159029500 description: A generic OAuth (1.0/1.0a) strategy for OmniAuth. email: - michael@intridea.com executables: [] extensions: [] extra_rdoc_files: [] files: - .gitignore - .rspec - Gemfile - Guardfile - README.md - Rakefile - lib/omniauth-oauth.rb - lib/omniauth-oauth/version.rb - lib/omniauth/strategies/oauth.rb - omniauth-oauth.gemspec - spec/omniauth/strategies/oauth_spec.rb - spec/spec_helper.rb homepage: https://github.com/intridea/omniauth-oauth licenses: [] post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 1.8.11 signing_key: specification_version: 3 summary: A generic OAuth (1.0/1.0a) strategy for OmniAuth. test_files: - spec/omniauth/strategies/oauth_spec.rb - spec/spec_helper.rb has_rdoc: ruby-omniauth-oauth-1.0.1/omniauth-oauth.gemspec000066400000000000000000000020251215607170000217370ustar00rootroot00000000000000# -*- encoding: utf-8 -*- require File.expand_path('../lib/omniauth-oauth/version', __FILE__) Gem::Specification.new do |gem| gem.authors = ["Michael Bleigh"] gem.email = ["michael@intridea.com"] gem.description = %q{A generic OAuth (1.0/1.0a) strategy for OmniAuth.} gem.summary = %q{A generic OAuth (1.0/1.0a) strategy for OmniAuth.} gem.homepage = "https://github.com/intridea/omniauth-oauth" gem.add_runtime_dependency 'omniauth', '~> 1.0' gem.add_runtime_dependency 'oauth' gem.add_development_dependency 'rspec', '~> 2.6' gem.add_development_dependency 'webmock' gem.add_development_dependency 'simplecov' gem.add_development_dependency 'rack-test' gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } gem.files = `git ls-files`.split("\n") gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") gem.name = "omniauth-oauth" gem.require_paths = ["lib"] gem.version = OmniAuth::OAuth::VERSION end ruby-omniauth-oauth-1.0.1/spec/000077500000000000000000000000001215607170000163635ustar00rootroot00000000000000ruby-omniauth-oauth-1.0.1/spec/omniauth/000077500000000000000000000000001215607170000202075ustar00rootroot00000000000000ruby-omniauth-oauth-1.0.1/spec/omniauth/strategies/000077500000000000000000000000001215607170000223615ustar00rootroot00000000000000ruby-omniauth-oauth-1.0.1/spec/omniauth/strategies/oauth_spec.rb000066400000000000000000000144461215607170000250510ustar00rootroot00000000000000require 'spec_helper' describe "OmniAuth::Strategies::OAuth" do class MyOAuthProvider < OmniAuth::Strategies::OAuth uid{ access_token.token } info{ {'name' => access_token.token} } end def app Rack::Builder.new { use OmniAuth::Test::PhonySession use OmniAuth::Builder do provider MyOAuthProvider, 'abc', 'def', :client_options => {:site => 'https://api.example.org'}, :name => 'example.org' provider MyOAuthProvider, 'abc', 'def', :client_options => {:site => 'https://api.example.org'}, :authorize_params => {:abc => 'def'}, :name => 'example.org_with_authorize_params' provider MyOAuthProvider, 'abc', 'def', :client_options => {:site => 'https://api.example.org'}, :request_params => {:scope => 'http://foobar.example.org'}, :name => 'example.org_with_request_params' end run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [env.key?('omniauth.auth').to_s]] } }.to_app end def session last_request.env['rack.session'] end before do stub_request(:post, 'https://api.example.org/oauth/request_token'). to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret&oauth_callback_confirmed=true") end it 'should add a camelization for itself' do OmniAuth::Utils.camelize('oauth').should == 'OAuth' end describe '/auth/{name}' do context 'successful' do before do get '/auth/example.org' end it 'should redirect to authorize_url' do last_response.should be_redirect last_response.headers['Location'].should == 'https://api.example.org/oauth/authorize?oauth_token=yourtoken' end it 'should redirect to authorize_url with authorize_params when set' do get '/auth/example.org_with_authorize_params' last_response.should be_redirect [ 'https://api.example.org/oauth/authorize?abc=def&oauth_token=yourtoken', 'https://api.example.org/oauth/authorize?oauth_token=yourtoken&abc=def' ].should be_include(last_response.headers['Location']) end it 'should set appropriate session variables' do session['oauth'].should == {"example.org" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}} end it 'should pass request_params to get_request_token' do get '/auth/example.org_with_request_params' WebMock.should have_requested(:post, 'https://api.example.org/oauth/request_token'). with {|req| req.body == "scope=http%3a%2f%2ffoobar.example.org" } end end context 'unsuccessful' do before do stub_request(:post, 'https://api.example.org/oauth/request_token'). to_raise(::Net::HTTPFatalError.new(%Q{502 "Bad Gateway"}, nil)) get '/auth/example.org' end it 'should call fail! with :service_unavailable' do last_request.env['omniauth.error'].should be_kind_of(::Net::HTTPFatalError) last_request.env['omniauth.error.type'] = :service_unavailable end context "SSL failure" do before do stub_request(:post, 'https://api.example.org/oauth/request_token'). to_raise(::OpenSSL::SSL::SSLError.new("SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed")) get '/auth/example.org' end it 'should call fail! with :service_unavailable' do last_request.env['omniauth.error'].should be_kind_of(::OpenSSL::SSL::SSLError) last_request.env['omniauth.error.type'] = :service_unavailable end end end end describe '/auth/{name}/callback' do before do stub_request(:post, 'https://api.example.org/oauth/access_token'). to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret") get '/auth/example.org/callback', {:oauth_verifier => 'dudeman'}, {'rack.session' => {'oauth' => {"example.org" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}}} end it 'should exchange the request token for an access token' do last_request.env['omniauth.auth']['provider'].should == 'example.org' last_request.env['omniauth.auth']['extra']['access_token'].should be_kind_of(OAuth::AccessToken) end it 'should call through to the master app' do last_response.body.should == 'true' end context "bad gateway (or any 5xx) for access_token" do before do stub_request(:post, 'https://api.example.org/oauth/access_token'). to_raise(::Net::HTTPFatalError.new(%Q{502 "Bad Gateway"}, nil)) get '/auth/example.org/callback', {:oauth_verifier => 'dudeman'}, {'rack.session' => {'oauth' => {"example.org" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}}} end it 'should call fail! with :service_unavailable' do last_request.env['omniauth.error'].should be_kind_of(::Net::HTTPFatalError) last_request.env['omniauth.error.type'] = :service_unavailable end end context "SSL failure" do before do stub_request(:post, 'https://api.example.org/oauth/access_token'). to_raise(::OpenSSL::SSL::SSLError.new("SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed")) get '/auth/example.org/callback', {:oauth_verifier => 'dudeman'}, {'rack.session' => {'oauth' => {"example.org" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}}} end it 'should call fail! with :service_unavailable' do last_request.env['omniauth.error'].should be_kind_of(::OpenSSL::SSL::SSLError) last_request.env['omniauth.error.type'] = :service_unavailable end end end describe '/auth/{name}/callback with expired session' do before do stub_request(:post, 'https://api.example.org/oauth/access_token'). to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret") get '/auth/example.org/callback', {:oauth_verifier => 'dudeman'}, {'rack.session' => {}} end it 'should call fail! with :session_expired' do last_request.env['omniauth.error'].should be_kind_of(::OmniAuth::NoSessionError) last_request.env['omniauth.error.type'] = :session_expired end end end ruby-omniauth-oauth-1.0.1/spec/spec_helper.rb000066400000000000000000000006241215607170000212030ustar00rootroot00000000000000$:.unshift File.expand_path('..', __FILE__) $:.unshift File.expand_path('../../lib', __FILE__) require 'simplecov' SimpleCov.start require 'rspec' require 'rack/test' require 'webmock/rspec' require 'omniauth' require 'omniauth-oauth' RSpec.configure do |config| config.include WebMock::API config.include Rack::Test::Methods config.extend OmniAuth::Test::StrategyMacros, :type => :strategy end