├── lib ├── omniauth-37signals.rb ├── omniauth-37signals │ └── version.rb └── omniauth │ └── strategies │ └── 37signals.rb ├── Rakefile ├── .gitignore ├── Gemfile ├── Guardfile ├── spec ├── spec_helper.rb ├── omniauth │ └── strategies │ │ └── 37signals_spec.rb └── support │ └── shared_examples.rb ├── omniauth-37signals.gemspec └── README.md /lib/omniauth-37signals.rb: -------------------------------------------------------------------------------- 1 | require "omniauth-37signals/version" 2 | require "omniauth/strategies/37signals" 3 | -------------------------------------------------------------------------------- /lib/omniauth-37signals/version.rb: -------------------------------------------------------------------------------- 1 | module OmniAuth 2 | module ThirtySevenSignals 3 | VERSION = "1.0.5" 4 | end 5 | end 6 | 7 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | require "bundler/gem_tasks" 3 | require "rspec/core/rake_task" 4 | 5 | RSpec::Core::RakeTask.new do |t| 6 | end 7 | 8 | task :default => :spec 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | /pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | .rvmrc 19 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'http://rubygems.org' 2 | 3 | # Specify your gem's dependencies in omniauth-github.gemspec 4 | gemspec 5 | 6 | group :development, :test do 7 | gem 'guard' 8 | gem 'guard-rspec' 9 | gem 'guard-bundler' 10 | gem 'rb-fsevent' 11 | gem 'growl' 12 | end 13 | 14 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | guard 'rspec', :version => 2 do 2 | watch(%r{^spec/.+_spec\.rb$}) 3 | watch(%r{^spec/support/.+\.rb$}) 4 | watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } 5 | watch('spec/spec_helper.rb') { "spec" } 6 | end 7 | 8 | guard 'bundler' do 9 | watch('Gemfile') 10 | watch('omniauth-37signals.gemspec') 11 | end 12 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 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 'omniauth' 8 | require 'omniauth-37signals' 9 | 10 | Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f } 11 | 12 | RSpec.configure do |config| 13 | config.include Rack::Test::Methods 14 | config.extend OmniAuth::Test::StrategyMacros, :type => :strategy 15 | end 16 | 17 | -------------------------------------------------------------------------------- /spec/omniauth/strategies/37signals_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'omniauth-37signals' 3 | 4 | describe OmniAuth::Strategies::ThirtySevenSignals do 5 | subject do 6 | strategy = OmniAuth::Strategies::ThirtySevenSignals.new(nil, @options || {}) 7 | strategy.stub(:session) { {} } 8 | strategy 9 | end 10 | 11 | it_should_behave_like 'an oauth2 strategy' 12 | 13 | describe '#client' do 14 | it 'should have the correct 37signals site' do 15 | subject.client.site.should eq("https://launchpad.37signals.com") 16 | end 17 | 18 | it 'should have the correct authorization url' do 19 | subject.client.options[:authorize_url].should eq("/authorization/new") 20 | end 21 | 22 | it 'should have the correct token url' do 23 | subject.client.options[:token_url].should eq('/authorization/token') 24 | end 25 | end 26 | 27 | describe '#callback_path' do 28 | it 'should have the correct callback path' do 29 | subject.callback_path.should eq('/auth/37signals/callback') 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /omniauth-37signals.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | require File.expand_path('../lib/omniauth-37signals/version', __FILE__) 3 | 4 | Gem::Specification.new do |gem| 5 | gem.authors = ["Will Barrett"] 6 | gem.email = ["william.barrett@tallgreentree.com"] 7 | gem.description = %q{OmniAuth strategy for 37signals.} 8 | gem.summary = %q{OmniAuth strategy for 37signals.} 9 | gem.homepage = "https://github.com/tallgreentree/omniauth-37signals" 10 | 11 | gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } 12 | gem.files = `git ls-files`.split("\n") 13 | gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") 14 | gem.name = "omniauth-37signals" 15 | gem.require_paths = ["lib"] 16 | gem.version = OmniAuth::ThirtySevenSignals::VERSION 17 | 18 | gem.add_dependency 'omniauth', '~> 1.0' 19 | gem.add_dependency 'omniauth-oauth2', '~> 1.0' 20 | gem.add_development_dependency 'rspec', '~> 2.7' 21 | gem.add_development_dependency 'rack-test' 22 | gem.add_development_dependency 'simplecov' 23 | gem.add_development_dependency 'webmock' 24 | end 25 | 26 | -------------------------------------------------------------------------------- /spec/support/shared_examples.rb: -------------------------------------------------------------------------------- 1 | # NOTE it would be useful if this lived in omniauth-oauth2 eventually 2 | # Thanks to Josh Ellithorpe for this file -Will 3 | 4 | shared_examples 'an oauth2 strategy' do 5 | describe '#client' do 6 | it 'should be initialized with symbolized client_options' do 7 | @options = { :client_options => { 'authorize_url' => 'https://example.com' } } 8 | subject.client.options[:authorize_url].should == 'https://example.com' 9 | end 10 | end 11 | 12 | describe '#authorize_params' do 13 | it 'should include any authorize params passed in the :authorize_params option' do 14 | @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } } 15 | subject.authorize_params['foo'].should eq('bar') 16 | subject.authorize_params['baz'].should eq('zip') 17 | end 18 | 19 | it 'should include top-level options that are marked as :authorize_options' do 20 | @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' } 21 | subject.authorize_params['scope'].should eq('bar') 22 | subject.authorize_params['foo'].should eq('baz') 23 | end 24 | end 25 | 26 | describe '#token_params' do 27 | it 'should include any token params passed in the :token_params option' do 28 | @options = { :token_params => { :foo => 'bar', :baz => 'zip' } } 29 | subject.token_params['foo'].should eq('bar') 30 | subject.token_params['baz'].should eq('zip') 31 | end 32 | 33 | it 'should include top-level options that are marked as :token_options' do 34 | @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' } 35 | subject.token_params['scope'].should eq('bar') 36 | subject.token_params['foo'].should eq('baz') 37 | end 38 | end 39 | end 40 | 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OmniAuth 37signals 2 | 3 | This gem contains the unofficial 37signals strategy for OmniAuth. 4 | 5 | ## Basic Usage 6 | 7 | use OmniAuth::Builder do 8 | provider "37signals", ENV['37SIGNALS_CLIENT_ID'], ENV['37SIGNALS_SECRET'] 9 | end 10 | 11 | ## Supported Flows 12 | 13 | Supports the server flow as described in the draft spec at [http://tools.ietf.org/html/draft-ietf-oauth-v2-05](http://tools.ietf.org/html/draft-ietf-oauth-v2-05). See [this Google Groups discussion](http://groups.google.com/group/37signals-api/browse_thread/thread/86b0da52134c1b7e) for more information. 14 | 15 | ## Ruby 16 | 17 | Tested with the following Ruby versions: 18 | 19 | - MRI 1.9.2 20 | - MRI 1.8.7 21 | 22 | ## License 23 | 24 | Copyright (c) 2011 by Will Barrett and Tall Green Tree Inc. 25 | 26 | 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: 27 | 28 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 29 | 30 | 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. 31 | 32 | -------------------------------------------------------------------------------- /lib/omniauth/strategies/37signals.rb: -------------------------------------------------------------------------------- 1 | require 'omniauth-oauth2' 2 | require 'multi_json' 3 | 4 | module OmniAuth 5 | module Strategies 6 | class ThirtySevenSignals < OmniAuth::Strategies::OAuth2 7 | option :client_options, { 8 | :site => 'https://launchpad.37signals.com', 9 | :authorize_url => '/authorization/new', 10 | :token_url => '/authorization/token' 11 | } 12 | 13 | option :authorize_params, { 14 | :type => 'web_server', 15 | :response_type => 'web_server' 16 | } 17 | 18 | option :name, '37signals' 19 | 20 | def request_phase 21 | super 22 | end 23 | 24 | def build_access_token 25 | token_params = { 26 | :code => request.params['code'], 27 | :redirect_uri => callback_url, 28 | :client_id => client.id, 29 | :client_secret => client.secret, 30 | :type => 'web_server' 31 | } 32 | client.get_token(token_params) 33 | end 34 | 35 | uid { raw_info.parsed['identity']['id'] } 36 | 37 | info do 38 | { 39 | 'email' => raw_info.parsed['identity']['email_address'], 40 | 'first_name' => raw_info.parsed['identity']['first_name'], 41 | 'last_name' => raw_info.parsed['identity']['last_name'], 42 | 'name' => [raw_info.parsed['identity']['first_name'], raw_info.parsed['identity']['last_name']].join(' ').strip 43 | } 44 | end 45 | 46 | extra do 47 | { 48 | 'accounts' => raw_info.parsed['accounts'], 49 | 'raw_info' => raw_info.parsed 50 | } 51 | end 52 | 53 | def raw_info 54 | access_token.options[:parse] = :json 55 | @raw_info ||= access_token.get('/authorization.json') 56 | end 57 | 58 | end 59 | end 60 | end 61 | 62 | OmniAuth.config.add_camelization '37signals', 'ThirtySevenSignals' 63 | --------------------------------------------------------------------------------