omniauth-basecamp 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +48 -0
- data/README.md +77 -0
- data/Rakefile +6 -0
- data/lib/omniauth-basecamp.rb +1 -0
- data/lib/omniauth/basecamp.rb +2 -0
- data/lib/omniauth/basecamp/version.rb +5 -0
- data/lib/omniauth/strategies/basecamp.rb +37 -0
- data/omniauth-basecamp.gemspec +22 -0
- data/spec/omniauth/strategies/basecamp_spec.rb +75 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/support/shared_examples.rb +36 -0
- metadata +109 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
omniauth-basecamp (0.1.0)
|
5
|
+
omniauth-oauth2 (~> 1.0.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.1.3)
|
11
|
+
faraday (0.8.4)
|
12
|
+
multipart-post (~> 1.1)
|
13
|
+
hashie (1.2.0)
|
14
|
+
httpauth (0.2.0)
|
15
|
+
jwt (0.1.5)
|
16
|
+
multi_json (>= 1.0)
|
17
|
+
multi_json (1.5.0)
|
18
|
+
multipart-post (1.1.5)
|
19
|
+
oauth2 (0.8.0)
|
20
|
+
faraday (~> 0.8)
|
21
|
+
httpauth (~> 0.1)
|
22
|
+
jwt (~> 0.1.4)
|
23
|
+
multi_json (~> 1.0)
|
24
|
+
rack (~> 1.2)
|
25
|
+
omniauth (1.1.1)
|
26
|
+
hashie (~> 1.2)
|
27
|
+
rack
|
28
|
+
omniauth-oauth2 (1.0.3)
|
29
|
+
oauth2 (~> 0.8.0)
|
30
|
+
omniauth (~> 1.0)
|
31
|
+
rack (1.4.4)
|
32
|
+
rake (0.9.2.2)
|
33
|
+
rspec (2.10.0)
|
34
|
+
rspec-core (~> 2.10.0)
|
35
|
+
rspec-expectations (~> 2.10.0)
|
36
|
+
rspec-mocks (~> 2.10.0)
|
37
|
+
rspec-core (2.10.0)
|
38
|
+
rspec-expectations (2.10.0)
|
39
|
+
diff-lcs (~> 1.1.3)
|
40
|
+
rspec-mocks (2.10.1)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
omniauth-basecamp!
|
47
|
+
rake
|
48
|
+
rspec
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# OmniAuth Basecamp
|
2
|
+
|
3
|
+
Basecamp OAuth2 Strategy for OmniAuth 1.0. Largely inspired by Shopify's OmniAuth strategy: https://github.com/Shopify/omniauth-shopify-oauth2
|
4
|
+
|
5
|
+
Totally inspired by corewebdesign OmniAuth gem for Harvest
|
6
|
+
https://github.com/corewebdesign/omniauth-harvest
|
7
|
+
|
8
|
+
## Installing
|
9
|
+
|
10
|
+
Add to your `Gemfile`:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'omniauth-basecamp'
|
14
|
+
```
|
15
|
+
|
16
|
+
Then run `bundle install`.
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Read the OmniAuth 1.0 docs for detailed instructions on using OmniAuth: https://github.com/intridea/omniauth.
|
21
|
+
|
22
|
+
Other useful resources:
|
23
|
+
https://github.com/intridea/omniauth-oauth2
|
24
|
+
https://github.com/37signals/bcx-api
|
25
|
+
|
26
|
+
You will need to set up your application using 37signals integration portal `https://integrate.37signals.com/apps`.
|
27
|
+
|
28
|
+
To use this in Rails, for example, add the following in `config/initializers/omniauth.rb`:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
32
|
+
provider :basecamp, ENV['BASECAMP_IDENTIFIER'], ENV['BASECAMP_SECRET']
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
## Authentication Hash
|
37
|
+
|
38
|
+
Here's an example *Authentication Hash* available in `request.env['omniauth.auth']`:
|
39
|
+
|
40
|
+
```json
|
41
|
+
{
|
42
|
+
"provider": "basecamp",
|
43
|
+
"credentials": {
|
44
|
+
"token": "...I6MzRaIiwidXNlcl9pZHMiO...", // OAuth 2.0 access_token; use this for authenticating API requests
|
45
|
+
"refresh_token": "...YyIsImFwYm9sdCI6IjQzYjN...",
|
46
|
+
"expires_at": 1359624154,
|
47
|
+
"expires": true
|
48
|
+
}
|
49
|
+
}
|
50
|
+
```
|
51
|
+
|
52
|
+
## License
|
53
|
+
Copyright (c) 2013 by Verano Software SA
|
54
|
+
|
55
|
+
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:
|
56
|
+
|
57
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
58
|
+
|
59
|
+
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.
|
60
|
+
|
61
|
+
### Based on the Core OmniAuth Harvest gem
|
62
|
+
Copyright (c) 2012 by Core
|
63
|
+
|
64
|
+
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:
|
65
|
+
|
66
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
67
|
+
|
68
|
+
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.
|
69
|
+
|
70
|
+
### Based on the Shopify OmniAuth Strategy
|
71
|
+
Copyright (c) 2012 by Shopify Inc
|
72
|
+
|
73
|
+
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:
|
74
|
+
|
75
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
76
|
+
|
77
|
+
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.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'omniauth/basecamp'
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'omniauth/strategies/oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class Basecamp < OmniAuth::Strategies::OAuth2
|
6
|
+
option :client_options, {
|
7
|
+
:site => 'https://launchpad.37signals.com',
|
8
|
+
:authorize_url => '/authorization/new',
|
9
|
+
:token_url => '/authorization/token'
|
10
|
+
}
|
11
|
+
|
12
|
+
def authorize_params
|
13
|
+
super.tap do |params|
|
14
|
+
params[:response_type] = 'code'
|
15
|
+
params[:client_id] = client.id
|
16
|
+
params[:redirect_uri] ||= callback_url
|
17
|
+
params[:type] = 'web_server'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def request_phase
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
def build_access_token
|
26
|
+
token_params = {
|
27
|
+
:code => request.params['code'],
|
28
|
+
:redirect_uri => callback_url,
|
29
|
+
:client_id => client.id,
|
30
|
+
:client_secret => client.secret,
|
31
|
+
:type => 'web_server'
|
32
|
+
}
|
33
|
+
client.get_token(token_params)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'omniauth/basecamp/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'omniauth-basecamp'
|
7
|
+
s.version = OmniAuth::Basecamp::VERSION
|
8
|
+
s.authors = ['Jerome Lambercy']
|
9
|
+
s.email = ['jerome.lambercy@gmail.com']
|
10
|
+
s.summary = 'Basecamp strategy for OmniAuth'
|
11
|
+
s.homepage = 'https://github.com/jlamberc/omniauth-basecamp.git'
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
16
|
+
s.require_paths = ['lib']
|
17
|
+
|
18
|
+
s.add_runtime_dependency 'omniauth-oauth2', '~> 1.0.0'
|
19
|
+
|
20
|
+
s.add_development_dependency 'rspec'
|
21
|
+
s.add_development_dependency 'rake'
|
22
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'omniauth-basecamp'
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
describe OmniAuth::Strategies::Basecamp do
|
6
|
+
before :each do
|
7
|
+
@request = double('Request')
|
8
|
+
@request.stub(:params) { {} }
|
9
|
+
@request.stub(:cookies) { {} }
|
10
|
+
|
11
|
+
@client_id = '123'
|
12
|
+
@client_secret = '53cr3tz'
|
13
|
+
@options = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
subject do
|
17
|
+
args = [@client_id, @client_secret, @options].compact
|
18
|
+
OmniAuth::Strategies::Basecamp.new(nil, *args).tap do |strategy|
|
19
|
+
strategy.stub(:request) { @request }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#client' do
|
24
|
+
it 'has correct authorize url' do
|
25
|
+
subject.client.options[:authorize_url].should eq('/authorization/new')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'has correct token url' do
|
29
|
+
subject.client.options[:token_url].should eq('/authorization/token')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#credentials' do
|
34
|
+
before :each do
|
35
|
+
@access_token = double('OAuth2::AccessToken')
|
36
|
+
@access_token.stub(:token)
|
37
|
+
@access_token.stub(:expires?)
|
38
|
+
@access_token.stub(:expires_at)
|
39
|
+
@access_token.stub(:refresh_token)
|
40
|
+
subject.stub(:access_token) { @access_token }
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns a Hash' do
|
44
|
+
subject.credentials.should be_a(Hash)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'returns the token' do
|
48
|
+
@access_token.stub(:token) { 'I6MzRaIiwidXNlcl9pZHMiO' }
|
49
|
+
subject.credentials['token'].should eq('I6MzRaIiwidXNlcl9pZHMiO')
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'returns the expiry status' do
|
53
|
+
@access_token.stub(:expires?) { true }
|
54
|
+
subject.credentials['expires'].should eq(true)
|
55
|
+
|
56
|
+
@access_token.stub(:expires?) { false }
|
57
|
+
subject.credentials['expires'].should eq(false)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns the expiry timestamp' do
|
61
|
+
@access_token.stub(:expires?) { true }
|
62
|
+
@access_token.stub(:expires_at) { 1359624154 }
|
63
|
+
subject.credentials['expires_at'].should eq(1359624154)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns the refresh token' do
|
67
|
+
@access_token.stub(:expires?) { true }
|
68
|
+
@access_token.stub(:expires_at) { 1359624154 }
|
69
|
+
@access_token.stub(:token) { 'I6MzRaIiwidXNlcl9pZHMiO' }
|
70
|
+
@access_token.stub(:refresh_token) { 'YyIsImFwYm9sdCI6IjQzYjN' }
|
71
|
+
subject.credentials['refresh_token'].should eq('YyIsImFwYm9sdCI6IjQzYjN')
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
shared_examples 'an oauth2 strategy' do
|
2
|
+
describe '#client' do
|
3
|
+
it 'should be initialized with symbolized client_options' do
|
4
|
+
@options = { :client_options => { 'authorize_url' => 'https://example.com' } }
|
5
|
+
subject.client.options[:authorize_url].should == 'https://example.com'
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#authorize_params' do
|
10
|
+
it 'should include any authorize params passed in the :authorize_params option' do
|
11
|
+
@options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
|
12
|
+
subject.authorize_params['foo'].should eq('bar')
|
13
|
+
subject.authorize_params['baz'].should eq('zip')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should include top-level options that are marked as :authorize_options' do
|
17
|
+
@options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
|
18
|
+
subject.authorize_params['scope'].should eq('bar')
|
19
|
+
subject.authorize_params['foo'].should eq('baz')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#token_params' do
|
24
|
+
it 'should include any token params passed in the :token_params option' do
|
25
|
+
@options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
|
26
|
+
subject.token_params['foo'].should eq('bar')
|
27
|
+
subject.token_params['baz'].should eq('zip')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should include top-level options that are marked as :token_options' do
|
31
|
+
@options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
|
32
|
+
subject.token_params['scope'].should eq('bar')
|
33
|
+
subject.token_params['foo'].should eq('baz')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-basecamp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jerome Lambercy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: omniauth-oauth2
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description:
|
63
|
+
email:
|
64
|
+
- jerome.lambercy@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- Gemfile.lock
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- lib/omniauth-basecamp.rb
|
75
|
+
- lib/omniauth/basecamp.rb
|
76
|
+
- lib/omniauth/basecamp/version.rb
|
77
|
+
- lib/omniauth/strategies/basecamp.rb
|
78
|
+
- omniauth-basecamp.gemspec
|
79
|
+
- spec/omniauth/strategies/basecamp_spec.rb
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
- spec/support/shared_examples.rb
|
82
|
+
homepage: https://github.com/jlamberc/omniauth-basecamp.git
|
83
|
+
licenses: []
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.24
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Basecamp strategy for OmniAuth
|
106
|
+
test_files:
|
107
|
+
- spec/omniauth/strategies/basecamp_spec.rb
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
- spec/support/shared_examples.rb
|