omniauth-37signals 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
data/Gemfile ADDED
@@ -0,0 +1,13 @@
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
+
data/Guardfile ADDED
@@ -0,0 +1,11 @@
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-github.gemspec')
11
+ end
data/README.md ADDED
@@ -0,0 +1,31 @@
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
+
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
@@ -0,0 +1,85 @@
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
+ # :header_format => 'Token %s',
12
+ # :param_name => 'Authorization',
13
+ }
14
+
15
+ option :authorize_params, {
16
+ :type => 'web_server',
17
+ :response_type => 'web_server'
18
+ }
19
+
20
+ option :name, '37signals'
21
+
22
+ def request_phase
23
+ super
24
+ end
25
+
26
+ # def callback_phase
27
+ # if request.params['error'] || request.params['error_reason']
28
+ # raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'])
29
+ # end
30
+
31
+ # self.access_token = build_access_token
32
+ # self.access_token = client.auth_code.refresh_token(access_token.refresh_token) if access_token.expired?
33
+
34
+ # rescue ::OAuth2::Error, CallbackError => e
35
+ # fail!(e.response.body, e)
36
+ # rescue ::MultiJson::DecodeError => e
37
+ # fail!(:invalid_response, e)
38
+ # rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
39
+ # fail!(:timeout, e)
40
+ # end
41
+
42
+ # def build_access_token
43
+ # verifier = request.params['code']
44
+ # client.get_token({:code => verifier, :client_id => client.id, :client_secret => client.secret, :type => 'web_server', :redirect_uri => "http://localhost:4567/auth/37signals/callback"})
45
+ # end
46
+
47
+ def build_access_token
48
+ token_params = {
49
+ :code => request.params['code'],
50
+ :redirect_uri => callback_url,
51
+ :client_id => client.id,
52
+ :client_secret => client.secret,
53
+ :type => 'web_server'
54
+ }
55
+ client.get_token(token_params)
56
+ end
57
+
58
+ uid { raw_info.parsed['identity']['id'] }
59
+
60
+ info do
61
+ {
62
+ 'email' => raw_info.parsed['identity']['email_address'],
63
+ 'first_name' => raw_info.parsed['identity']['first_name'],
64
+ 'last_name' => raw_info.parsed['identity']['last_name'],
65
+ 'name' => [raw_info.parsed['identity']['first_name'], raw_info.parsed['identity']['last_name']].join(' ').strip
66
+ }
67
+ end
68
+
69
+ extra do
70
+ {
71
+ 'accounts' => raw_info.parsed['accounts'],
72
+ 'raw_info' => raw_info.parsed
73
+ }
74
+ end
75
+
76
+ def raw_info
77
+ access_token.options[:parse] = :json
78
+ @raw_info ||= access_token.get('/authorization.json')
79
+ end
80
+
81
+ end
82
+ end
83
+ end
84
+
85
+ OmniAuth.config.add_camelization '37signals', 'ThirtySevenSignals'
@@ -0,0 +1,6 @@
1
+ module OmniAuth
2
+ module ThirtySevenSignals
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
6
+
@@ -0,0 +1,2 @@
1
+ require "omniauth-37signals/version"
2
+ require "omniauth/strategies/37signals"
@@ -0,0 +1,26 @@
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_dependency 'multi_json', '~> 1.0.3'
21
+ gem.add_development_dependency 'rspec', '~> 2.7'
22
+ gem.add_development_dependency 'rack-test'
23
+ gem.add_development_dependency 'simplecov'
24
+ gem.add_development_dependency 'webmock'
25
+ end
26
+
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-37signals'
3
+
4
+ describe OmniAuth::Strategies::ThirtySevenSignals do
5
+ subject do
6
+ OmniAuth::Strategies::ThirtySevenSignals.new(nil, @options || {})
7
+ end
8
+
9
+ it_should_behave_like 'an oauth2 strategy'
10
+
11
+ describe '#client' do
12
+ it 'should have the correct 37signals site' do
13
+ subject.client.site.should eq("https://launchpad.37signals.com")
14
+ end
15
+
16
+ it 'should have the correct authorization url' do
17
+ subject.client.options[:authorize_url].should eq("/authorization/new")
18
+ end
19
+
20
+ it 'should have the correct token url' do
21
+ subject.client.options[:token_url].should eq('/authorization/token')
22
+ end
23
+ end
24
+
25
+ describe '#callback_path' do
26
+ it 'should have the correct callback path' do
27
+ subject.callback_path.should eq('/auth/37signals/callback')
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,16 @@
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
+
@@ -0,0 +1,40 @@
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
+
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-37signals
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Will Barrett
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-11 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: &2156180580 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2156180580
25
+ - !ruby/object:Gem::Dependency
26
+ name: omniauth-oauth2
27
+ requirement: &2156180060 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '1.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2156180060
36
+ - !ruby/object:Gem::Dependency
37
+ name: multi_json
38
+ requirement: &2156179600 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.3
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2156179600
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &2156179140 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.7'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2156179140
58
+ - !ruby/object:Gem::Dependency
59
+ name: rack-test
60
+ requirement: &2156178740 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2156178740
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: &2156178280 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2156178280
80
+ - !ruby/object:Gem::Dependency
81
+ name: webmock
82
+ requirement: &2156177860 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *2156177860
91
+ description: OmniAuth strategy for 37signals.
92
+ email:
93
+ - william.barrett@tallgreentree.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - .gitignore
99
+ - Gemfile
100
+ - Guardfile
101
+ - README.md
102
+ - Rakefile
103
+ - lib/omniauth-37signals.rb
104
+ - lib/omniauth-37signals/version.rb
105
+ - lib/omniauth/strategies/37signals.rb
106
+ - omniauth-37signals.gemspec
107
+ - spec/omniauth/strategies/37signals_spec.rb
108
+ - spec/spec_helper.rb
109
+ - spec/support/shared_examples.rb
110
+ homepage: https://github.com/tallgreentree/omniauth-37signals
111
+ licenses: []
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 1.8.10
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: OmniAuth strategy for 37signals.
134
+ test_files:
135
+ - spec/omniauth/strategies/37signals_spec.rb
136
+ - spec/spec_helper.rb
137
+ - spec/support/shared_examples.rb