omniauth-harvest-oauth2 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7528f126ce0f8541727064c0be8fd68c2e0fd3cde77d5412d3affcabb66e04cf
4
+ data.tar.gz: 7142def3c7525bba9cccc340fb3aed876aa24647f07dae7f608522f540812fbd
5
+ SHA512:
6
+ metadata.gz: f44822a650a07cd3c23260a8d78f24d407724aaeedd53881489e995f1ae0bec65490d64245bb76aa25e4087a9d0351274126d3d334d7a5fe50ed3858a817884d
7
+ data.tar.gz: 1af9d3f44474a3267f8c1cf47d63525ad626570ab1f59932419cf9c77531b9a6d8ef29741e58a9408cab8b72d08683e8d30388e7fd7229ae3cedab749c341393
@@ -0,0 +1 @@
1
+ pkg/*
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby-18mode # JRuby in 1.8 mode
7
+ - jruby-19mode # JRuby in 1.9 mode
8
+ - rbx-18mode
9
+ - rbx-19mode
10
+ # uncomment this line if your project needs to run something other than `rake`:
11
+ # script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-harvest (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.0)
12
+ multipart-post (~> 1.1)
13
+ hashie (1.2.0)
14
+ httpauth (0.1)
15
+ multi_json (1.3.4)
16
+ multipart-post (1.1.5)
17
+ oauth2 (0.6.1)
18
+ faraday (~> 0.7)
19
+ httpauth (~> 0.1)
20
+ multi_json (~> 1.3)
21
+ omniauth (1.1.0)
22
+ hashie (~> 1.2)
23
+ rack
24
+ omniauth-oauth2 (1.0.2)
25
+ oauth2 (~> 0.6.0)
26
+ omniauth (~> 1.0)
27
+ rack (1.4.1)
28
+ rake (0.9.2.2)
29
+ rspec (2.10.0)
30
+ rspec-core (~> 2.10.0)
31
+ rspec-expectations (~> 2.10.0)
32
+ rspec-mocks (~> 2.10.0)
33
+ rspec-core (2.10.0)
34
+ rspec-expectations (2.10.0)
35
+ diff-lcs (~> 1.1.3)
36
+ rspec-mocks (2.10.1)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ omniauth-harvest!
43
+ rake
44
+ rspec
@@ -0,0 +1,62 @@
1
+ # OmniAuth Harvest
2
+
3
+ [![Build Status](https://secure.travis-ci.org/corewebdesign/omniauth-harvest.png?branch=master)](http://travis-ci.org/corewebdesign/omniauth-harvest)
4
+
5
+ Harvest OAuth2 Strategy for OmniAuth 1.0. Largely inspired by Shopify's OmniAuth strategy: https://github.com/Shopify/omniauth-shopify-oauth2
6
+
7
+ ## Installing
8
+
9
+ Add to your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem 'omniauth-harvest'
13
+ ```
14
+
15
+ Then run `bundle install`.
16
+
17
+ ## Usage
18
+
19
+ Read the OmniAuth 1.0 docs for detailed instructions on using OmniAuth: https://github.com/intridea/omniauth.
20
+
21
+ You will need to set up your application in your Harvest account `https://<companyname>.harvestapp.com/oauth2_clients`. Support for receiving these details from users (for accessing multiple accounts) will be coming soon.
22
+
23
+ To use this in Rails, for example, add the following in `config/initializers/omniauth.rb`:
24
+
25
+ ```ruby
26
+ Rails.application.config.middleware.use OmniAuth::Builder do
27
+ provider :harvest, ENV['HARVEST_IDENTIFIER'], ENV['HARVEST_SECRET']
28
+ end
29
+ ```
30
+
31
+ There is also a simple Sinatra example in ./example/config.ru
32
+
33
+ ## Authentication Hash
34
+
35
+ Here's an example *Authentication Hash* available in `request.env['omniauth.auth']`:
36
+
37
+ ```ruby
38
+ {
39
+ :provider => 'harvest',
40
+ :credentials => {
41
+ :token => 'afasd923kjh0934kf', # OAuth 2.0 access_token; use this for authenticating API requests
42
+ }
43
+ }
44
+ ```
45
+
46
+ ## License
47
+ Copyright (c) 2012 by Core
48
+
49
+ 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:
50
+
51
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
52
+
53
+ 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.
54
+
55
+ ### Based on the Shopify OmniAuth Strategy
56
+ Copyright (c) 2012 by Shopify Inc
57
+
58
+ 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:
59
+
60
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
61
+
62
+ 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.
@@ -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,6 @@
1
+ source :rubygems
2
+
3
+ gem 'rack'
4
+
5
+ gem 'sinatra'
6
+ gem 'omniauth-harvest', :path => '../'
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ omniauth-harvest (0.1.0)
5
+ omniauth-oauth2 (~> 1.0.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ faraday (0.8.0)
11
+ multipart-post (~> 1.1)
12
+ hashie (1.2.0)
13
+ httpauth (0.1)
14
+ multi_json (1.3.4)
15
+ multipart-post (1.1.5)
16
+ oauth2 (0.6.1)
17
+ faraday (~> 0.7)
18
+ httpauth (~> 0.1)
19
+ multi_json (~> 1.3)
20
+ omniauth (1.1.0)
21
+ hashie (~> 1.2)
22
+ rack
23
+ omniauth-oauth2 (1.0.2)
24
+ oauth2 (~> 0.6.0)
25
+ omniauth (~> 1.0)
26
+ rack (1.4.1)
27
+ rack-protection (1.2.0)
28
+ rack
29
+ sinatra (1.3.2)
30
+ rack (~> 1.3, >= 1.3.6)
31
+ rack-protection (~> 1.2)
32
+ tilt (~> 1.3, >= 1.3.3)
33
+ tilt (1.3.3)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ omniauth-harvest!
40
+ rack
41
+ sinatra
@@ -0,0 +1,41 @@
1
+ require 'bundler/setup'
2
+ require 'sinatra/base'
3
+ require 'omniauth-harvest'
4
+
5
+ class App < Sinatra::Base
6
+ get '/auth/:provider/callback' do
7
+ <<-HTML
8
+ <html>
9
+ <head>
10
+ <title>Harvest Oauth2</title>
11
+ </head>
12
+ <body>
13
+ <h3>Authorized</h3>
14
+ <p>Token: #{request.env['omniauth.auth']['credentials']['token']}</p>
15
+ </body>
16
+ </html>
17
+ HTML
18
+ end
19
+
20
+ get '/auth/failure' do
21
+ <<-HTML
22
+ <html>
23
+ <head>
24
+ <title>Harvest Oauth2</title>
25
+ </head>
26
+ <body>
27
+ <h3>Failed Authorization</h3>
28
+ <p>Message: #{params[:message]}</p>
29
+ </body>
30
+ </html>
31
+ HTML
32
+ end
33
+ end
34
+
35
+ use Rack::Session::Cookie
36
+
37
+ use OmniAuth::Builder do
38
+ provider :harvest, ENV['HARVEST_IDENTIFIER'], ENV['HARVEST_SECRET']
39
+ end
40
+
41
+ run App.new
@@ -0,0 +1 @@
1
+ require 'omniauth/harvest'
@@ -0,0 +1,2 @@
1
+ require 'omniauth/harvest/version'
2
+ require 'omniauth/strategies/harvest'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Harvest
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,36 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Harvest < OmniAuth::Strategies::OAuth2
6
+ option :client_options, {
7
+ :site => 'https://id.getharvest.com',
8
+ :authorize_url => '/oauth2/authorize',
9
+ :token_url => 'api/v2/oauth2/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
+ end
18
+ end
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
+ :grant_type => 'authorization_code'
31
+ }
32
+ client.get_token(token_params)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'omniauth/harvest/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'omniauth-harvest-oauth2'
7
+ s.version = OmniAuth::Harvest::VERSION
8
+ s.authors = ['Matheus Santana', 'Robert May']
9
+ s.email = ['matheus@guava.software', 'robotmay@gmail.com']
10
+ s.summary = 'Harvest strategy for OmniAuth'
11
+ s.homepage = 'https://github.com/guava/omniauth-harvest-oauth2'
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.3.1'
19
+
20
+ s.add_development_dependency 'rspec'
21
+ s.add_development_dependency 'rake'
22
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-harvest'
3
+ require 'base64'
4
+
5
+ describe OmniAuth::Strategies::Harvest 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::Harvest.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('/oauth2/authorize')
26
+ end
27
+
28
+ it 'has correct token url' do
29
+ subject.client.options[:token_url].should eq('/oauth2/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) { '123' }
49
+ subject.credentials['token'].should eq('123')
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
+ end
60
+ 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,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,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-harvest-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matheus Santana
8
+ - Robert May
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2020-01-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth-oauth2
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 1.3.1
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 1.3.1
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description:
57
+ email:
58
+ - matheus@guava.software
59
+ - robotmay@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - README.md
69
+ - Rakefile
70
+ - example/Gemfile
71
+ - example/Gemfile.lock
72
+ - example/config.ru
73
+ - lib/omniauth-harvest.rb
74
+ - lib/omniauth/harvest.rb
75
+ - lib/omniauth/harvest/version.rb
76
+ - lib/omniauth/strategies/harvest.rb
77
+ - omniauth-harvest-oauth2.gemspec
78
+ - spec/omniauth/strategies/harvest_spec.rb
79
+ - spec/spec_helper.rb
80
+ - spec/support/shared_examples.rb
81
+ homepage: https://github.com/guava/omniauth-harvest-oauth2
82
+ licenses: []
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubygems_version: 3.0.3
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Harvest strategy for OmniAuth
103
+ test_files: []