omniauth-taskrabbit 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ .rvmrc
3
+ .bundle
4
+ .rspec
5
+ /Gemfile.lock
6
+ pkg/*
7
+ .powenv
8
+ tmp
9
+ bin
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ gem 'jruby-openssl', :platform => :jruby
6
+ gem 'debugger'
7
+ gem 'sinatra'
@@ -0,0 +1,88 @@
1
+ # OmniAuth TaskRabbit
2
+
3
+ TaskRabbit OAuth2 Strategy for OmniAuth 1.0.
4
+
5
+ Supports the OAuth 2.0 server-side and client-side flows.
6
+
7
+ ## Installing
8
+
9
+ Add to your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem 'omniauth-taskrabbit'
13
+ ```
14
+
15
+ Then `bundle install`.
16
+
17
+ ## Usage
18
+
19
+ Add to a Rails app in `config/initializers/omniauth.rb`:
20
+
21
+ ```ruby
22
+ Rails.application.config.middleware.use OmniAuth::Builder do
23
+ provider :taskrabbit, ENV['TR_API_KEY'], ENV['TR_SECRET']
24
+ end
25
+ ```
26
+
27
+ ## Auth Hash
28
+
29
+ Here's an example *Auth Hash* available in `request.env['omniauth.auth']`:
30
+
31
+ ```ruby
32
+ {
33
+ :provider => 'taskrabbit',
34
+ :uid => 283559,
35
+ :info => {
36
+ :email => "sponge.bob@example.com"
37
+ :first_name => "Bob",
38
+ :last_name => "Sponge",
39
+ :full_name => "Bob Sponge",
40
+ :zip_code => "21314",
41
+ :city: {
42
+ :id: 1,
43
+ :name: "Boston"
44
+ },
45
+ },
46
+ :credentials => {
47
+ :token => 'oXOIDNEOInwiewniwnaiNSiocnione', # OAuth 2.0 access_token, which you may wish to store
48
+ :expires => false
49
+ },
50
+ :extra => {
51
+ :raw_info => {
52
+ :id => 283559,
53
+ :zip_code => "21314",
54
+ :first_name => "Bob",
55
+ :last_name => "Sponge",
56
+ :full_name => "Bob Sponge",
57
+ :short_name => "Bob",
58
+ :display_name => "Bob S.",
59
+ :email => "sponge.bob@example.com",
60
+ :city: {
61
+ :id: 1,
62
+ :name: "Boston"
63
+ },
64
+ :links => {
65
+ :avatar_url => "https://www.taskrabbit.com/images/default_avatars/poster_thumb.png",
66
+ :get => "/api/v1/users/283559"
67
+ },
68
+ :tasks => {
69
+ :links => {
70
+ :get => "/api/v1/users/283559/tasks",
71
+ :last => "/api/v1/users/283559/tasks?page=1",
72
+ :first => "/api/v1/users/283559/tasks?page=1"
73
+ }
74
+ },
75
+ :locations => {
76
+ :links => {
77
+ :get => "/api/v1/users/283559/locations"
78
+ }
79
+ },
80
+ :counts => {
81
+ :posted_tasks => 5,
82
+ :ongoing_tasks => 2,
83
+ :active_tasks => 1
84
+ }
85
+ }
86
+ }
87
+ }
88
+ ```
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,43 @@
1
+ # Sample app for TaskRabbit OAuth2 Strategy
2
+ # Make sure to setup the ENV variables TR_API_KEY and TR_SECRET
3
+ # Run with "bundle exec rackup"
4
+ ENV['TR_API_KEY'] = 'ior8jfh723hfD8fj9eSi383Niojreiu3U832hf90'
5
+ ENV['TR_API_SECRET'] = 'pfjf7dfw392h2D2iofkjpxqdreLKue523tdnbdff'
6
+
7
+ require 'rubygems'
8
+ require 'bundler'
9
+ require 'sinatra'
10
+ require 'omniauth'
11
+ require 'omniauth-taskrabbit'
12
+ require 'openssl'
13
+ require 'debugger'
14
+
15
+ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
16
+
17
+ class App < Sinatra::Base
18
+ get '/' do
19
+ <<-HTML
20
+ <ul>
21
+ <li><a href='/auth/taskrabbit'>Sign in with TaskRabbit</a></li>
22
+ </ul>
23
+ HTML
24
+ end
25
+
26
+ get '/auth/:provider/callback' do
27
+ content_type 'text/plain'
28
+ request.env['omniauth.auth'].to_hash.inspect rescue "No Data"
29
+ end
30
+
31
+ get '/auth/failure' do
32
+ content_type 'text/plain'
33
+ request.env['omniauth.auth'].to_hash.inspect rescue "No Data"
34
+ end
35
+ end
36
+
37
+ use Rack::Session::Cookie, :secret => ENV['RACK_COOKIE_SECRET']
38
+
39
+ use OmniAuth::Builder do
40
+ provider :taskrabbit, ENV['TR_API_KEY'], ENV['TR_API_SECRET']
41
+ end
42
+
43
+ run App.new
@@ -0,0 +1,3 @@
1
+ Rails.application.config.middleware.use OmniAuth::Builder do
2
+ provider :taskrabbit, ENV['TR_API_KEY'], ENV['TR_SECRET']
3
+ end
@@ -0,0 +1 @@
1
+ require 'omniauth/taskrabbit'
@@ -0,0 +1,65 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class TaskRabbit < OmniAuth::Strategies::OAuth2
6
+ option :name, "taskrabbit"
7
+
8
+ option :client_options, {
9
+ :site => "https://www.taskrabbit.com",
10
+ :authorize_url => '/api/authorize',
11
+ :request_token_url => "/api/oauth/request_token",
12
+ :token_url => '/api/oauth/token'
13
+ }
14
+
15
+ option :access_token_options, {
16
+ :header_format => 'OAuth %s',
17
+ :param_name => 'access_token'
18
+ }
19
+
20
+ uid { raw_info['id'] }
21
+
22
+ info do
23
+ prune!({
24
+ 'email' => raw_info['email'],
25
+ 'first_name' => raw_info['first_name'],
26
+ 'last_name' => raw_info['last_name'],
27
+ 'full_name' => raw_info['full_name'],
28
+ 'zip_code' => raw_info['zip_code'],
29
+ 'city' => raw_info['city'],
30
+ })
31
+ end
32
+
33
+ extra do
34
+ prune!({
35
+ 'raw_info' => raw_info
36
+ })
37
+ end
38
+
39
+ def raw_info
40
+ @raw_info ||= access_token.get('/api/v1/account').parsed
41
+ end
42
+
43
+ def build_access_token
44
+ super.tap do |token|
45
+ token.options.merge!(access_token_options)
46
+ end
47
+ end
48
+
49
+ def access_token_options
50
+ options.access_token_options.inject({}) { |h,(k,v)| h[k.to_sym] = v; h }
51
+ end
52
+
53
+ private
54
+
55
+ def prune!(hash)
56
+ hash.delete_if do |_, value|
57
+ prune!(value) if value.is_a?(Hash)
58
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ OmniAuth.config.add_camelization 'taskrabbit', 'TaskRabbit'
@@ -0,0 +1,2 @@
1
+ require 'omniauth/taskrabbit/version'
2
+ require 'omniauth/strategies/taskrabbit'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module TaskRabbit
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'omniauth/taskrabbit/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'omniauth-taskrabbit'
7
+ s.version = OmniAuth::TaskRabbit::VERSION
8
+ s.authors = ['Jean-Richard Lai']
9
+ s.email = ['jrichardlai@gmail.com']
10
+ s.summary = 'Taskrabbit strategy for OmniAuth'
11
+ s.homepage = 'https://github.com/jrichardlai/omniauth-taskrabbit'
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.2'
19
+
20
+ s.add_development_dependency 'rspec', '~> 2'
21
+ s.add_development_dependency 'rake'
22
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-taskrabbit'
3
+ require 'openssl'
4
+ require 'base64'
5
+
6
+ describe OmniAuth::Strategies::TaskRabbit do
7
+ before :each do
8
+ @request = double('Request')
9
+ @request.stub(:params) { {} }
10
+ @request.stub(:cookies) { {} }
11
+ @request.stub(:env) { {} }
12
+
13
+ @client_id = '123'
14
+ @client_secret = '53cr3tz'
15
+ end
16
+
17
+ subject do
18
+ args = [@client_id, @client_secret, @options].compact
19
+ OmniAuth::Strategies::TaskRabbit.new(nil, *args).tap do |strategy|
20
+ strategy.stub(:request) { @request }
21
+ end
22
+ end
23
+
24
+ it_should_behave_like 'an oauth2 strategy'
25
+
26
+ describe '#client' do
27
+ it 'has correct TaskRabbit site' do
28
+ subject.client.site.should eq('https://www.taskrabbit.com')
29
+ end
30
+
31
+ it 'has correct authorize url' do
32
+ subject.client.options[:authorize_url].should eq('/api/authorize')
33
+ end
34
+
35
+ it 'has correct token url' do
36
+ subject.client.options[:token_url].should eq('/api/oauth/token')
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,6 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+ Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
4
+
5
+ RSpec.configure do |config|
6
+ end
@@ -0,0 +1,37 @@
1
+ # NOTE it would be useful if this lived in omniauth-oauth2 eventually
2
+ shared_examples 'an oauth2 strategy' do
3
+ describe '#client' do
4
+ it 'should be initialized with symbolized client_options' do
5
+ @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
6
+ subject.client.options[:authorize_url].should == 'https://example.com'
7
+ end
8
+ end
9
+
10
+ describe '#authorize_params' do
11
+ it 'should include any authorize params passed in the :authorize_params option' do
12
+ @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
13
+ subject.authorize_params['foo'].should eq('bar')
14
+ subject.authorize_params['baz'].should eq('zip')
15
+ end
16
+
17
+ it 'should include top-level options that are marked as :authorize_options' do
18
+ @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
19
+ subject.authorize_params['scope'].should eq('bar')
20
+ subject.authorize_params['foo'].should eq('baz')
21
+ end
22
+ end
23
+
24
+ describe '#token_params' do
25
+ it 'should include any authorize params passed in the :authorize_params option' do
26
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
27
+ subject.token_params['foo'].should eq('bar')
28
+ subject.token_params['baz'].should eq('zip')
29
+ end
30
+
31
+ it 'should include top-level options that are marked as :authorize_options' do
32
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
33
+ subject.token_params['scope'].should eq('bar')
34
+ subject.token_params['foo'].should eq('baz')
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-taskrabbit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jean-Richard Lai
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-29 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.2
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.2
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: '2'
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: '2'
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
+ - jrichardlai@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - README.md
72
+ - Rakefile
73
+ - examples/config.ru
74
+ - examples/omni_auth.rb
75
+ - lib/omniauth-taskrabbit.rb
76
+ - lib/omniauth/strategies/taskrabbit.rb
77
+ - lib/omniauth/taskrabbit.rb
78
+ - lib/omniauth/taskrabbit/version.rb
79
+ - omniauth-taskrabbit.gemspec
80
+ - spec/omniauth/strategies/taskrabbit_spec.rb
81
+ - spec/spec_helper.rb
82
+ - spec/support/shared_examples.rb
83
+ homepage: https://github.com/jrichardlai/omniauth-taskrabbit
84
+ licenses: []
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ segments:
96
+ - 0
97
+ hash: -844660181069885661
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ segments:
105
+ - 0
106
+ hash: -844660181069885661
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 1.8.24
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Taskrabbit strategy for OmniAuth
113
+ test_files:
114
+ - spec/omniauth/strategies/taskrabbit_spec.rb
115
+ - spec/spec_helper.rb
116
+ - spec/support/shared_examples.rb