omniauth-clover 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZmQwOGVkNzhlOTZhOGRkOGQ0NGQzMzIxZTZlNWNiMDVjNGM4ODU0OA==
5
+ data.tar.gz: !binary |-
6
+ Y2QzNWYyMjAyOTJlMWRmN2M5NjA2ODMxYjkwM2FhMmMwMDRjMDYyNg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OWVlYzFjNDg4YTk1Y2M5ZGIxZThjOWZiMGI3NTZmNDQ5YzVhYmJjZDA5ZDBk
10
+ ODRlMmY0MDYyMmQ3NzZkOWM0NDFhYmEzNDUxMTg2NWQ0NzVhZmFhYWU0OGIy
11
+ ZWEyNDVkODZiYzM2MTIyZmQ5ZTU0ZjZhOGU4NjFmMTdlMDQxMDY=
12
+ data.tar.gz: !binary |-
13
+ MTEyOTY3NDNhZDYxYjQwOGJkYjhmMjVjNjM0MzhmY2YzYmRhYTVmOGI4Mjll
14
+ ZjFhYjdjMjIxNWNjYWU1M2E2ZGQ3ZWJmZTdmYjA3NGY3OGUxMWRlNjIwZWI4
15
+ NGYyZDUzNWU5YjNkYTQwMTZlNmJlMWM5MDRlYjYxOTVkOGE2Nzk=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'jruby-openssl', :platform => :jruby
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 David Yun
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Omniauth::Clover
2
+
3
+ Clover OAuth2 Strategy for OmniAuth.
4
+
5
+ Supports the OAuth 2.0 server-side and client-side flows. For more information: https://www.clover.com/docs/oauth
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'omniauth-clover'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install omniauth-clover
21
+
22
+ ## Usage
23
+
24
+ config.omniauth :clover, "APP_ID", "APP_SECRET", :client_options => {:site => SITE}
25
+
26
+ Please visit: https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview for more information.
27
+
28
+ client options:
29
+ ---------------
30
+ - site: Defaults to the production https://www.clover.com. Change SITE to point to the development server for testing.
31
+ - authorize_url: Defaults to '/oauth/authorize'
32
+ - token_url: Defaults to '/oauth/token'
33
+
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1 @@
1
+ require 'omniauth/clover'
@@ -0,0 +1,2 @@
1
+ require "omniauth/clover/version"
2
+ require "omniauth/strategies/clover"
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Clover
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,100 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Clover < OmniAuth::Strategies::OAuth2
6
+
7
+ option :name, 'clover'
8
+
9
+ # This is where you pass the options you would pass when
10
+ # initializing your consumer from the OAuth gem.
11
+
12
+ option :client_options, {
13
+ :site => 'https://www.clover.com',
14
+ :authorize_url => '/oauth/authorize',
15
+ :token_url => '/oauth/token'
16
+ }
17
+
18
+ option :authorize_options, [:redirect_uri, :response_type, :state]
19
+
20
+
21
+ # After successful authentication, client information is returned
22
+ #
23
+ # Response parameters
24
+ # -------------------
25
+ # merchant_id: An ID that uniquely identifies the merchant who has authenticated with your app.
26
+ #
27
+ # employee_id: The employee ID of the current user. You can use this value to identify whether
28
+ # the current user is the owner of the merchant account, an employee, or someone else.
29
+ #
30
+ # client_id: The application ID that the user is authenticated to. If your app supports multiple
31
+ # markets (and you specified the client_ids parameter in the request to /oauth/authorize,
32
+ # then use this value to determine which of your apps the user authenticated against.
33
+ #
34
+ # code: Authorization code.
35
+ #
36
+ #
37
+ # Employee Information
38
+ # --------------------
39
+ # Retrieves information for single employee
40
+ #
41
+ # id (string, optional): Unique identifier
42
+ # name (string): Full name of the employee
43
+ # email (string, optional): Email of the employee (optional)
44
+ # pin (string, optional): Employee PIN (hashed)
45
+ # role (string, optional): ['ADMIN' or 'MANAGER' or 'EMPLOYEE']: Employee System Role
46
+ #
47
+ # roles (array[Reference], optional)
48
+ # customId (string, optional): Custom ID of the employee
49
+ # shifts (array[Reference], optional): This employee's shifts
50
+ # nickname (string, optional): Nickname of the employee (shows up on receipts)
51
+ # unhashedPin (string, optional): Employee PIN
52
+ # payments (array[Reference], optional): This employee's payments
53
+ # inviteSent (boolean, optional): Returns true if this employee was sent an invite to activate their account
54
+ # isOwner (boolean, optional): Returns true if this employee is the owner account for this merchant
55
+ # orders (array[Reference], optional): This employee's orders
56
+ # claimedTime (long, optional): Timestamp of when this employee claimed their account
57
+
58
+ uid {
59
+ raw_info['id']
60
+ }
61
+
62
+ info do
63
+ {
64
+ :name => raw_info['name'],
65
+ :first_name => first_name,
66
+ :last_name => last_name,
67
+ :email => raw_info['email'],
68
+ :role => raw_info['role'],
69
+ :urls => { 'Clover' => raw_info['href'] }
70
+ }
71
+ end
72
+
73
+ extra do
74
+ {
75
+ :merchant_id => request.params['merchant_id'],
76
+ :employee_id => request.params['employee_id'],
77
+ :client_id => request.params['client_id'],
78
+ :code => request.params['code']
79
+ }
80
+ end
81
+
82
+ def raw_info
83
+ merchant_id = request.params['merchant_id']
84
+ empployee_id = request.params['employee_id']
85
+ @raw_info ||= access_token.get("/v3/merchants/#{merchant_id}/employees/#{empployee_id}").parsed
86
+ end
87
+
88
+
89
+ private
90
+
91
+ def first_name
92
+ @raw_info['name'].blank? ? "" : @raw_info['name'].split(' ').first
93
+ end
94
+
95
+ def last_name
96
+ @raw_info['name'].blank? ? "" : @raw_info['name'].split[1..-1].join(' ')
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth/clover/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omniauth-clover"
8
+ spec.version = OmniAuth::Clover::VERSION
9
+ spec.authors = ["David Yun"]
10
+ spec.email = ["davidy@gmail.com"]
11
+ spec.description = %q{Clover OAuth2 Strategy for Omniauth}
12
+ spec.summary = %q{Clover OAuth2 Strategy for Omniauth}
13
+ spec.homepage = "https://github.com/davidy/omniauth-clover.git"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'omniauth-oauth2', '~> 1.1'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-clover'
3
+
4
+ describe OmniAuth::Strategies::Clover do
5
+ let(:request) { double('Request', :params => {}, :cookies => {}, :env => {}) }
6
+ let(:app) {
7
+ lambda do
8
+ [200, {}, ["Hello."]]
9
+ end
10
+ }
11
+
12
+ subject do
13
+ OmniAuth::Strategies::Clover.new(app, 'appid', 'secret', @options || {}).tap do |strategy|
14
+ allow(strategy).to receive(:request) {
15
+ request
16
+ }
17
+ end
18
+ end
19
+
20
+ before do
21
+ OmniAuth.config.test_mode = true
22
+ end
23
+
24
+ after do
25
+ OmniAuth.config.test_mode = false
26
+ end
27
+
28
+ describe '#client_options' do
29
+ it 'has correct site' do
30
+ expect(subject.client.site).to eq('https://www.clover.com')
31
+ end
32
+
33
+ it 'has correct authorize_url' do
34
+ expect(subject.client.options[:authorize_url]).to eq('/oauth/authorize')
35
+ end
36
+
37
+ it 'has correct token_url' do
38
+ expect(subject.client.options[:token_url]).to eq('/oauth/token')
39
+ end
40
+
41
+ describe "overrides" do
42
+ it 'should allow overriding the site' do
43
+ @options = {:client_options => {'site' => 'https://example.com'}}
44
+ expect(subject.client.site).to eq('https://example.com')
45
+ end
46
+
47
+ it 'should allow overriding the authorize_url' do
48
+ @options = {:client_options => {'authorize_url' => 'https://example.com'}}
49
+ expect(subject.client.options[:authorize_url]).to eq('https://example.com')
50
+ end
51
+
52
+ it 'should allow overriding the token_url' do
53
+ @options = {:client_options => {'token_url' => 'https://example.com'}}
54
+ expect(subject.client.options[:token_url]).to eq('https://example.com')
55
+ end
56
+ end
57
+ end
58
+
59
+ describe "#authorize_options" do
60
+ [:redirect_uri, :response_type, :state].each do |k|
61
+ it "should support #{k}" do
62
+ @options = {k => 'http://someval'}
63
+ expect(subject.authorize_params[k.to_s]).to eq('http://someval')
64
+ end
65
+ end
66
+
67
+ describe "redirect_uri" do
68
+ it 'should default to nil' do
69
+ @options = {}
70
+ expect(subject.authorize_params['redirect_uri']).to eq(nil)
71
+ end
72
+
73
+ it 'should set the redirect_uri parameter if present' do
74
+ @options = {:redirect_uri => 'https://example.com'}
75
+ expect(subject.authorize_params['redirect_uri']).to eq('https://example.com')
76
+ end
77
+ end
78
+
79
+ describe 'response_type' do
80
+ it 'should default to "code"' do
81
+ @options = {}
82
+ expect(subject.authorize_params['response_type']).to eq(nil)
83
+ end
84
+
85
+ it 'should set the response_type parameter if present' do
86
+ @options = {:response_type => 'token'}
87
+ expect(subject.authorize_params['response_type']).to eq('token')
88
+ end
89
+ end
90
+
91
+ describe 'state' do
92
+ it 'should set the state parameter' do
93
+ @options = {:state => 'some_state'}
94
+ expect(subject.authorize_params['state']).to eq('some_state')
95
+ expect(subject.session['omniauth.state']).to eq('some_state')
96
+ end
97
+ end
98
+ end
99
+
100
+ end
@@ -0,0 +1,9 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'omniauth-clover' # and any other gems you need
5
+ require 'rspec'
6
+
7
+ RSpec.configure do |config|
8
+ # some (optional) config here
9
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-clover
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David Yun
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth-oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
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'
69
+ description: Clover OAuth2 Strategy for Omniauth
70
+ email:
71
+ - davidy@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/omniauth-clover.rb
82
+ - lib/omniauth/clover.rb
83
+ - lib/omniauth/clover/version.rb
84
+ - lib/omniauth/strategies/clover.rb
85
+ - omniauth-clover.gemspec
86
+ - spec/omniauth/strategies/clover_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: https://github.com/davidy/omniauth-clover.git
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.1
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Clover OAuth2 Strategy for Omniauth
112
+ test_files:
113
+ - spec/omniauth/strategies/clover_spec.rb
114
+ - spec/spec_helper.rb