Skip to content
Browse files

Initial import of work.

  • Loading branch information...
0 parents commit f6aa3c51a6682e361bf2366ee668df19ab8aabe8 Will Barrett committed Nov 10, 2011
18 .gitignore
@@ -0,0 +1,18 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+/pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
+.rvmrc
13 Gemfile
@@ -0,0 +1,13 @@
+source 'http://rubygems.org'
+
+# Specify your gem's dependencies in omniauth-github.gemspec
+gemspec
+
+group :development, :test do
+ gem 'guard'
+ gem 'guard-rspec'
+ gem 'guard-bundler'
+ gem 'rb-fsevent'
+ gem 'growl'
+end
+
11 Guardfile
@@ -0,0 +1,11 @@
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^spec/support/.+\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+end
+
+guard 'bundler' do
+ watch('Gemfile')
+ watch('omniauth-github.gemspec')
+end
0 README.md
No changes.
0 Rakefile
No changes.
2 lib/omniauth-37signals.rb
@@ -0,0 +1,2 @@
+require "omniauth-37signals/version"
+require "omniauth/strategies/37signals"
6 lib/omniauth-37signals/version.rb
@@ -0,0 +1,6 @@
+module OmniAuth
+ module ThirtySevenSignals
+ VERSION = "0.0.1"
+ end
+end
+
85 lib/omniauth/strategies/37signals.rb
@@ -0,0 +1,85 @@
+require 'omniauth-oauth2'
+require 'multi_json'
+
+module OmniAuth
+ module Strategies
+ class ThirtySevenSignals < OmniAuth::Strategies::OAuth2
+ option :client_options, {
+ :site => 'https://launchpad.37signals.com',
+ :authorize_url => '/authorization/new',
+ :token_url => '/authorization/token',
+ # :header_format => 'Token %s',
+ # :param_name => 'Authorization',
+ }
+
+ option :authorize_params, {
+ :type => 'web_server',
+ :response_type => 'web_server'
+ }
+
+ option :name, '37signals'
+
+ def request_phase
+ super
+ end
+
+ # def callback_phase
+ # if request.params['error'] || request.params['error_reason']
+ # raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'])
+ # end
+
+ # self.access_token = build_access_token
+ # self.access_token = client.auth_code.refresh_token(access_token.refresh_token) if access_token.expired?
+
+ # rescue ::OAuth2::Error, CallbackError => e
+ # fail!(e.response.body, e)
+ # rescue ::MultiJson::DecodeError => e
+ # fail!(:invalid_response, e)
+ # rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
+ # fail!(:timeout, e)
+ # end
+
+ # def build_access_token
+ # verifier = request.params['code']
+ # client.get_token({:code => verifier, :client_id => client.id, :client_secret => client.secret, :type => 'web_server', :redirect_uri => "http://localhost:4567/auth/37signals/callback"})
+ # end
+
+ def build_access_token
+ token_params = {
+ :code => request.params['code'],
+ :redirect_uri => callback_url,
+ :client_id => client.id,
+ :client_secret => client.secret,
+ :type => 'web_server'
+ }
+ client.get_token(token_params)
+ end
+
+ uid { raw_info.parsed['identity']['id'] }
+
+ info do
+ {
+ 'email' => raw_info.parsed['identity']['email_address'],
+ 'first_name' => raw_info.parsed['identity']['first_name'],
+ 'last_name' => raw_info.parsed['identity']['last_name'],
+ 'name' => [raw_info.parsed['identity']['first_name'], raw_info.parsed['identity']['last_name']].join(' ').strip
+ }
+ end
+
+ extra do
+ {
+ 'accounts' => raw_info.parsed['accounts'],
+ 'raw_info' => raw_info.response
+ }
+ end
+
+ def raw_info
+ access_token.options[:parse] = :json
+ @raw_info ||= access_token.get('/authorization.json')
+ end
+
+ end
+ end
+end
+
+OmniAuth.config.add_camelization '37signals', 'ThirtySevenSignals'
26 omniauth-37signals.gemspec
@@ -0,0 +1,26 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/omniauth-37signals/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Will Barrett"]
+ gem.email = ["william.barrett@tallgreentree.com"]
+ gem.description = %q{OmniAuth strategy for 37signals.}
+ gem.summary = %q{OmniAuth strategy for 37signals.}
+ gem.homepage = "https://github.com/tallgreentree/omniauth-37signals"
+
+ 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-37signals"
+ gem.require_paths = ["lib"]
+ gem.version = OmniAuth::ThirtySevenSignals::VERSION
+
+ gem.add_dependency 'omniauth', '~> 1.0'
+ gem.add_dependency 'omniauth-oauth2', '~> 1.0'
+ gem.add_dependency 'multi_json', '~> 1.0.3'
+ gem.add_development_dependency 'rspec', '~> 2.7'
+ gem.add_development_dependency 'rack-test'
+ gem.add_development_dependency 'simplecov'
+ gem.add_development_dependency 'webmock'
+end
+
30 spec/omniauth/strategies/37signals_spec.rb
@@ -0,0 +1,30 @@
+require 'spec_helper'
+require 'omniauth-37signals'
+
+describe OmniAuth::Strategies::ThirtySevenSignals do
+ subject do
+ OmniAuth::Strategies::ThirtySevenSignals.new(nil, @options || {})
+ end
+
+ it_should_behave_like 'an oauth2 strategy'
+
+ describe '#client' do
+ it 'should have the correct 37signals site' do
+ subject.client.site.should eq("https://launchpad.37signals.com")
+ end
+
+ it 'should have the correct authorization url' do
+ subject.client.options[:authorize_url].should eq("/authorization/new")
+ end
+
+ it 'should have the correct token url' do
+ subject.client.options[:token_url].should eq('/authorization/token')
+ end
+ end
+
+ describe '#callback_path' do
+ it 'should have the correct callback path' do
+ subject.callback_path.should eq('/auth/37signals/callback')
+ end
+ end
+end
16 spec/spec_helper.rb
@@ -0,0 +1,16 @@
+$:.unshift File.expand_path('..', __FILE__)
+$:.unshift File.expand_path('../../lib', __FILE__)
+require 'simplecov'
+SimpleCov.start
+require 'rspec'
+require 'rack/test'
+require 'omniauth'
+require 'omniauth-37signals'
+
+Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
+
+RSpec.configure do |config|
+ config.include Rack::Test::Methods
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
+end
+
40 spec/support/shared_examples.rb
@@ -0,0 +1,40 @@
+# NOTE it would be useful if this lived in omniauth-oauth2 eventually
+# Thanks to Josh Ellithorpe for this file -Will
+
+shared_examples 'an oauth2 strategy' do
+ describe '#client' do
+ it 'should be initialized with symbolized client_options' do
+ @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
+ subject.client.options[:authorize_url].should == 'https://example.com'
+ end
+ end
+
+ describe '#authorize_params' do
+ it 'should include any authorize params passed in the :authorize_params option' do
+ @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
+ subject.authorize_params['foo'].should eq('bar')
+ subject.authorize_params['baz'].should eq('zip')
+ end
+
+ it 'should include top-level options that are marked as :authorize_options' do
+ @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
+ subject.authorize_params['scope'].should eq('bar')
+ subject.authorize_params['foo'].should eq('baz')
+ end
+ end
+
+ describe '#token_params' do
+ it 'should include any token params passed in the :token_params option' do
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
+ subject.token_params['foo'].should eq('bar')
+ subject.token_params['baz'].should eq('zip')
+ end
+
+ it 'should include top-level options that are marked as :token_options' do
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
+ subject.token_params['scope'].should eq('bar')
+ subject.token_params['foo'].should eq('baz')
+ end
+ end
+end
+

0 comments on commit f6aa3c5

Please sign in to comment.
Something went wrong with that request. Please try again.