omniauth-splitwise 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c5dd3a989e67c5c6bcd9b6786890681f2e7c24da
4
- data.tar.gz: e49d6a8bc3284f0cec23168c164242537fb5a716
2
+ SHA256:
3
+ metadata.gz: 9bc6c1857d364dc5239bab481eef88c31912a70057e7840825bafdced35dba18
4
+ data.tar.gz: cc0416a613b44a05c5dc000b7eaec93c04013ad531d01a3ecb941b973ec16d4a
5
5
  SHA512:
6
- metadata.gz: 7a382edfc303c4421607b55c0f35f2e727132561b7c39de250c5ee4e68e777c91403b3f73f48c316b4f7a40fe9e7a603734bb724a8eeff98ead55f609513b8ab
7
- data.tar.gz: 8ec95fd694ca45b677f833eeea3c134c13aeb52678f671916c0201caa993126b83e9f3868915eec80e46c37f146917f66370f43b3c19f4d1ec1312b3d07d048c
6
+ metadata.gz: e175f3194e9ed25d411feebaab9d377cc08ba32df794b1d3ee5e4e6b32d4feca04fcebd205608e635b5b2807bcfd81b8751a0501f8ff22772352b1fc63826ec8
7
+ data.tar.gz: 88ce09fe1d5c9a6854c4f03069c93da33a426b2087455a542490f09c58ad2344e630101926a87f63968b85c42449df6df88a14dc63aa146deb2d98a68a333f29
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Nathan Griffith
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # OmniAuth Splitwise
2
2
 
3
- An OmniAuth strategy for authenticating to [Splitwise](http://www.splitwise.com). To use it, you'll need to [sign up for a Consumer Key and Secret](https://secure.splitwise.com/oauth_clients).
3
+ An OmniAuth strategy for authenticating to [Splitwise](http://www.splitwise.com).
4
+ To use it, you'll need to [sign up for a Consumer Key and Secret](https://secure.splitwise.com/oauth_clients).
5
+
6
+ As of 2020, this gem uses OAuth 2.0 to interface with Splitwise.
4
7
 
5
8
  ## Installation
6
9
 
@@ -16,13 +19,13 @@ Or install it yourself:
16
19
 
17
20
  $ gem install omniauth-splitwise
18
21
 
19
- ## Usage
22
+ ## App Setup
20
23
 
21
24
  For Rack apps, in your config.ru:
22
25
 
23
26
  ```ruby
24
27
  use OmniAuth::Builder do
25
- provider :splitwise, ENV['SPLITWISE_KEY'], ENV['SPLITWISE_SECRET']
28
+ provider :splitwise, ENV.fetch('SPLITWISE_KEY'), ENV.fetch('SPLITWISE_SECRET')
26
29
  end
27
30
  ```
28
31
 
@@ -30,21 +33,37 @@ For Rails apps, in config/initializers/omniauth.rb:
30
33
 
31
34
  ```ruby
32
35
  Rails.application.config.middleware.use OmniAuth::Builder do
33
- provider :splitwise, ENV['SPLITWISE_KEY'], ENV['SPLITWISE_SECRET']
36
+ provider :splitwise, ENV.fetch('SPLITWISE_KEY'), ENV.fetch('SPLITWISE_SECRET')
34
37
  end
35
38
  ```
36
39
 
37
40
  See also: [Integrating OmniAuth Into Your Application](https://github.com/intridea/omniauth#integrating-omniauth-into-your-application).
38
41
 
39
- ## Example
42
+ ### Usage
40
43
 
41
- In the `example/` directory, run the provided Sinatra application for a demo:
44
+ Once a successful OAuth2 request has been made, several fields are available immediately:
42
45
 
43
- $ cd example/
44
- $ bundle
45
- $ SPLITWISE_KEY=abc123 SPLITWISE_SECRET=def456 rackup
46
+ ```ruby
47
+ auth = request.env['omniauth.auth']
48
+
49
+ auth['provider'] # => 'splitwise'
50
+ auth['uid'] # => Splitwise User ID
51
+ auth['info'] # => A hash containing 'first_name', 'last_name', and 'email'
52
+ auth['extra'] # => The full user hash from /api/v3.0/get_current_user
53
+ ```
54
+
55
+ Additionally, the bearer token may be extracted and reused:
56
+
57
+ ```ruby
58
+ auth = request.env['omniauth.auth']
46
59
 
47
- Then visit [localhost:9292](http://localhost:9292) to try it out.
60
+ token = auth['credentials']['token']
61
+ client = OAuth2::Client.new(ENV["SPLITWISE_KEY"], ENV["SPLITWISE_SECRET"])
62
+ access_token = OAuth2::AccessToken.new(client, splitwise_token)
63
+
64
+ # Start making API requests:
65
+ access_token.get('/api/v3.0/get_current_user').parsed
66
+ ```
48
67
 
49
68
  ## Contributing
50
69
 
@@ -53,13 +72,3 @@ Then visit [localhost:9292](http://localhost:9292) to try it out.
53
72
  3. Commit your changes (`git commit -am 'Added some feature'`)
54
73
  4. Push to the branch (`git push origin my-new-feature`)
55
74
  5. Create new Pull Request
56
-
57
- # License
58
-
59
- Copyright (C) 2014 by Nathan Griffith
60
-
61
- 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:
62
-
63
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
64
-
65
- 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 CHANGED
@@ -1 +1,11 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rubocop/rake_task'
4
+ RuboCop::RakeTask.new
5
+
6
+ require 'rspec/core'
7
+ require 'rspec/core/rake_task'
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ task(:default).clear
11
+ task default: %i(rubocop spec)
@@ -1,2 +1 @@
1
- require "omniauth/splitwise/version"
2
- require 'omniauth/strategies/splitwise'
1
+ require 'omniauth_splitwise' # rubocop:disable Naming/FileName
@@ -1,36 +1,39 @@
1
- require 'omniauth/strategies/oauth'
1
+ require 'omniauth-oauth2'
2
2
 
3
3
  module OmniAuth
4
4
  module Strategies
5
- class Splitwise < OmniAuth::Strategies::OAuth
6
- option :name, "splitwise"
5
+ class Splitwise < OmniAuth::Strategies::OAuth2
6
+ BASE_SITE = 'https://secure.splitwise.com/'.freeze
7
7
 
8
- option :client_options, {
9
- :site => 'https://secure.splitwise.com',
10
- :request_token_path => '/api/v3.0/get_request_token',
11
- :access_token_path => '/api/v3.0/get_access_token',
12
- :authorize_path => '/authorize',
13
- :http_method => :post,
14
- :scheme => :header
15
- }
8
+ option :name, "splitwise"
9
+ option :client_options, site: BASE_SITE
16
10
 
17
11
  uid do
18
- user_data['id']
12
+ raw_info.fetch('id')
19
13
  end
20
14
 
21
15
  info do
22
- user_data
16
+ {
17
+ 'first_name' => raw_info['first_name'],
18
+ 'last_name' => raw_info['last_name'],
19
+ 'email' => raw_info['email'],
20
+ }
21
+ end
22
+
23
+ extra do
24
+ raw_info
23
25
  end
24
26
 
25
- private
27
+ private
26
28
 
27
- def user_data
28
- @info ||= MultiJson.decode(access_token.get('/api/v3.0/get_current_user').body)['user']
29
+ def raw_info
30
+ @raw_info ||= access_token.get('/api/v3.0/get_current_user').parsed['user']
29
31
  end
30
32
 
31
- def callback_phase
32
- session['oauth'][name.to_s]['callback_confirmed'] = true
33
- super
33
+ # We must override callback_url due to this issue:
34
+ # https://github.com/omniauth/omniauth-oauth2/issues/93
35
+ def callback_url
36
+ full_host + script_name + callback_path
34
37
  end
35
38
  end
36
39
  end
@@ -0,0 +1,2 @@
1
+ require 'omniauth_splitwise/version'
2
+ require 'omniauth/strategies/splitwise'
@@ -0,0 +1,3 @@
1
+ module OmniAuthSplitwise
2
+ VERSION = "0.1.0".freeze
3
+ end
@@ -2,36 +2,50 @@ require 'spec_helper'
2
2
 
3
3
  describe "OmniAuth::Strategies::Splitwise" do
4
4
  subject do
5
- OmniAuth::Strategies::Splitwise.new(nil, @options || {})
5
+ OmniAuth::Strategies::Splitwise.new(nil)
6
6
  end
7
7
 
8
8
  context 'client options' do
9
+ it 'has correct provider name' do
10
+ subject.options.name eq('splitwise')
11
+ end
12
+
9
13
  it 'has correct Splitwise site' do
10
- subject.options.client_options.site.should eq('https://secure.splitwise.com')
14
+ subject.options.client_options.site.should eq('https://secure.splitwise.com/')
11
15
  end
12
16
 
13
- it 'has correct request token path' do
14
- subject.options.client_options.request_token_path.should eq('/api/v3.0/get_request_token')
17
+ it 'has correct callback uri' do
18
+ subject.callback_path.should eq('/auth/splitwise/callback')
15
19
  end
16
20
 
17
- it 'has correct access token path' do
18
- subject.options.client_options.access_token_path.should eq('/api/v3.0/get_access_token')
21
+ it 'has correct token path' do
22
+ subject.client.options[:token_url].should eq('/oauth/token')
19
23
  end
20
24
 
21
25
  it 'has correct authorize path' do
22
- subject.options.client_options.authorize_path.should eq('/authorize')
26
+ subject.client.options[:authorize_url].should eq('/oauth/authorize')
23
27
  end
24
28
  end
25
29
 
26
30
  context '#uid' do
27
31
  before :each do
28
- subject.stub(:user_data) { { 'id' => '123', "other_data" => 012345 } }
32
+ subject.stub(
33
+ raw_info: {
34
+ 'id' => '123',
35
+ 'first_name' => 'Marie',
36
+ 'last_name' => 'Curie',
37
+ 'email' => 'mc@example.org',
38
+ 'other_data' => 0o12345,
39
+ },
40
+ )
29
41
  end
30
42
 
31
43
  it 'returns the id from user_data' do
32
44
  subject.uid.should eq('123')
33
- subject.info["id"].should eq("123")
34
- subject.info["other_data"].should eq(012345)
45
+ subject.info['first_name'].should eq('Marie')
46
+ subject.info['last_name'].should eq('Curie')
47
+ subject.info['email'].should eq('mc@example.org')
48
+ subject.extra['other_data'].should eq(0o12345)
35
49
  end
36
50
  end
37
51
  end
metadata CHANGED
@@ -1,57 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-splitwise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Griffith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-02 00:00:00.000000000 Z
11
+ date: 2020-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: omniauth-oauth
14
+ name: omniauth-oauth2
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.0
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: multi_json
28
+ name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
- type: :runtime
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.7.0
47
+ version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-betterment
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
53
60
  - !ruby/object:Gem::Version
54
- version: 2.7.0
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description:
56
70
  email:
57
71
  - nathan@ngriffith.com
@@ -59,23 +73,18 @@ executables: []
59
73
  extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
62
- - .gitignore
63
- - .rspec
64
- - Gemfile
65
- - Gemfile.lock
76
+ - LICENSE
66
77
  - README.md
67
78
  - Rakefile
68
- - example/Gemfile
69
- - example/Gemfile.lock
70
- - example/config.ru
71
79
  - lib/omniauth-splitwise.rb
72
- - lib/omniauth/splitwise/version.rb
73
80
  - lib/omniauth/strategies/splitwise.rb
74
- - omniauth-splitwise.gemspec
81
+ - lib/omniauth_splitwise.rb
82
+ - lib/omniauth_splitwise/version.rb
75
83
  - spec/omniauth/strategies/splitwise_spec.rb
76
84
  - spec/spec_helper.rb
77
- homepage: https://github.com/Smudge/omniauth-splitwise
78
- licenses: []
85
+ homepage: https://github.com/smudge/omniauth-splitwise
86
+ licenses:
87
+ - MIT
79
88
  metadata: {}
80
89
  post_install_message:
81
90
  rdoc_options: []
@@ -83,20 +92,19 @@ require_paths:
83
92
  - lib
84
93
  required_ruby_version: !ruby/object:Gem::Requirement
85
94
  requirements:
86
- - - '>='
95
+ - - ">="
87
96
  - !ruby/object:Gem::Version
88
97
  version: '0'
89
98
  required_rubygems_version: !ruby/object:Gem::Requirement
90
99
  requirements:
91
- - - '>='
100
+ - - ">="
92
101
  - !ruby/object:Gem::Version
93
102
  version: '0'
94
103
  requirements: []
95
- rubyforge_project:
96
- rubygems_version: 2.0.14
104
+ rubygems_version: 3.0.3
97
105
  signing_key:
98
106
  specification_version: 4
99
107
  summary: Splitwise strategy for OmniAuth
100
108
  test_files:
101
- - spec/omniauth/strategies/splitwise_spec.rb
102
109
  - spec/spec_helper.rb
110
+ - spec/omniauth/strategies/splitwise_spec.rb
data/.gitignore DELETED
@@ -1,16 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- InstalledFiles
7
- _yardoc
8
- coverage
9
- doc/
10
- lib/bundler/man
11
- /pkg
12
- rdoc
13
- spec/reports
14
- test/tmp
15
- test/version_tmp
16
- tmp
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in omniauth-splitwise.gemspec
4
- gemspec
@@ -1,36 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- omniauth-splitwise (0.0.1)
5
- multi_json
6
- omniauth-oauth (~> 1.0.0)
7
-
8
- GEM
9
- remote: http://rubygems.org/
10
- specs:
11
- diff-lcs (1.1.3)
12
- hashie (2.0.5)
13
- multi_json (1.8.2)
14
- oauth (0.4.7)
15
- omniauth (1.1.4)
16
- hashie (>= 1.2, < 3)
17
- rack
18
- omniauth-oauth (1.0.1)
19
- oauth
20
- omniauth (~> 1.0)
21
- rack (1.5.2)
22
- rspec (2.7.0)
23
- rspec-core (~> 2.7.0)
24
- rspec-expectations (~> 2.7.0)
25
- rspec-mocks (~> 2.7.0)
26
- rspec-core (2.7.1)
27
- rspec-expectations (2.7.0)
28
- diff-lcs (~> 1.1.2)
29
- rspec-mocks (2.7.0)
30
-
31
- PLATFORMS
32
- ruby
33
-
34
- DEPENDENCIES
35
- omniauth-splitwise!
36
- rspec (~> 2.7.0)
@@ -1,6 +0,0 @@
1
- source :rubygems
2
-
3
- gem 'sinatra'
4
- gem 'multi_json'
5
- gem 'omniauth-splitwise', :path => '../'
6
-
@@ -1,35 +0,0 @@
1
- PATH
2
- remote: ../
3
- specs:
4
- omniauth-splitwise (0.0.1)
5
- multi_json
6
- omniauth-oauth (~> 1.0.0)
7
-
8
- GEM
9
- remote: http://rubygems.org/
10
- specs:
11
- hashie (2.0.5)
12
- multi_json (1.8.2)
13
- oauth (0.4.7)
14
- omniauth (1.1.4)
15
- hashie (>= 1.2, < 3)
16
- rack
17
- omniauth-oauth (1.0.1)
18
- oauth
19
- omniauth (~> 1.0)
20
- rack (1.5.2)
21
- rack-protection (1.5.0)
22
- rack
23
- sinatra (1.4.3)
24
- rack (~> 1.4)
25
- rack-protection (~> 1.4)
26
- tilt (~> 1.3, >= 1.3.4)
27
- tilt (1.4.1)
28
-
29
- PLATFORMS
30
- ruby
31
-
32
- DEPENDENCIES
33
- multi_json
34
- omniauth-splitwise!
35
- sinatra
@@ -1,27 +0,0 @@
1
- require 'bundler/setup'
2
- require 'sinatra/base'
3
- require 'omniauth-splitwise'
4
-
5
- class App < Sinatra::Base
6
- get '/' do
7
- redirect '/auth/splitwise'
8
- end
9
-
10
- get '/auth/:provider/callback' do
11
- content_type 'application/json'
12
- MultiJson.encode(request.env)
13
- end
14
-
15
- get '/auth/failure' do
16
- content_type 'application/json'
17
- MultiJson.encode(request.env)
18
- end
19
- end
20
-
21
- use Rack::Session::Cookie
22
-
23
- use OmniAuth::Builder do
24
- provider :splitwise, ENV['SPLITWISE_KEY'], ENV['SPLITWISE_SECRET']
25
- end
26
-
27
- run App.new
@@ -1,5 +0,0 @@
1
- module OmniAuth
2
- module Splitwise
3
- VERSION = "0.0.1"
4
- end
5
- end
@@ -1,22 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path('../lib', __FILE__)
3
- require 'omniauth/splitwise/version'
4
-
5
- Gem::Specification.new do |s|
6
- s.name = 'omniauth-splitwise'
7
- s.version = OmniAuth::Splitwise::VERSION
8
- s.authors = ['Nathan Griffith']
9
- s.email = ['nathan@ngriffith.com']
10
- s.summary = 'Splitwise strategy for OmniAuth'
11
- s.homepage = 'https://github.com/Smudge/omniauth-splitwise'
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-oauth', '~> 1.0.0'
19
- s.add_runtime_dependency 'multi_json'
20
-
21
- s.add_development_dependency 'rspec', '~> 2.7.0'
22
- end