omniauth-makersquare 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 483b0c824d285abc0e14a772004cbc383d5be2bf
4
+ data.tar.gz: 1c8b30692ea9da3d80ee7ccf8e3245eb06f727e9
5
+ SHA512:
6
+ metadata.gz: 805f8d6f614e1fda8943e3fa7100deb96117a0fab39a758cd063efc7b947c13bddf59ee3910094001089101c2d3c585e710a3c5c5d9af1553ea551ef9f59e5d9
7
+ data.tar.gz: a0eedadba0ff8e6a3d851979358885c17fde74c0061d7f72e2da8eed739f2af708bea67b1edbd7e3cea3db798380f5857df02360a48feb6ac14ff95ae0670e40
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ ruby '2.0.0'
3
+
4
+ # Specify your gem's dependencies in pass.gemspec
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Gilbert
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,35 @@
1
+ # Omniauth MakerSquare
2
+
3
+ Log in with MakerSquare!
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'omniauth-makersquare'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install omniauth-makersquare
18
+
19
+ ## Usage
20
+
21
+ Email gilbert@makersquare.com to register your application, then add the following to your application if you're using Rails (in an initializer file such as `config/initializers/makersquare.rb`):
22
+
23
+ ```ruby
24
+ Rails.application.config.middleware.use OmniAuth::Builder do
25
+ provider :makersquare, ENV['MAKERSQUARE_KEY'], ENV['MAKERSQUARE_SECRET']
26
+ end
27
+ ```
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( http://github.com/<my-github-username>/omniauth-makersquare/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,10 @@
1
+ require 'omniauth'
2
+ require 'omniauth/strategies/makersquare'
3
+
4
+ OmniAuth.config.add_camelization('makersquare', 'MakerSquare')
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ autoload :MakerSquare, 'omniauth/strategies/makersquare'
9
+ end
10
+ end
@@ -0,0 +1,146 @@
1
+ # Mostly taken from https://github.com/intridea/omniauth-oauth2
2
+ require 'oauth2'
3
+ require 'omniauth'
4
+ require 'securerandom'
5
+ require 'socket' # for SocketError
6
+ require 'timeout' # for Timeout::Error
7
+ require 'faraday' # for Faraday::Error::TimeoutError and Faraday::Error::ConnectionFailed
8
+ require 'multi_json' # for MultiJson::DecodeError
9
+
10
+ module OmniAuth
11
+ module Strategies
12
+ class MakerSquare
13
+ include OmniAuth::Strategy
14
+
15
+ uid { raw_info["uid"] }
16
+ args [:client_id, :client_secret]
17
+
18
+ option :name, :makersquare
19
+
20
+ option :client_options, {
21
+ :site => ENV['MAKERSQUARE_AUTH_URL'] || "https://auth.makersquare.com",
22
+ :authorize_url => "/oauth/authorize"
23
+ }
24
+
25
+
26
+ option :client_id, nil
27
+ option :client_secret, nil
28
+ option :authorize_params, {}
29
+ option :authorize_options, [:scope]
30
+ option :token_params, {}
31
+ option :token_options, []
32
+ option :auth_token_params, {}
33
+ option :provider_ignores_state, false
34
+
35
+ info do
36
+ {
37
+ :email => raw_info['email'],
38
+ :avatar_url => raw_info['avatar_url']
39
+ # and anything else you want to return to your API consumers
40
+ }
41
+ end
42
+
43
+ attr_accessor :access_token
44
+
45
+ def raw_info
46
+ @raw_info ||= access_token.get('/api/v1/me.json').parsed
47
+ end
48
+
49
+ def client
50
+ ::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(options.client_options))
51
+ end
52
+
53
+ def callback_url
54
+ full_host + script_name + callback_path
55
+ end
56
+
57
+ credentials do
58
+ hash = {'token' => access_token.token}
59
+ hash.merge!('refresh_token' => access_token.refresh_token) if access_token.expires? && access_token.refresh_token
60
+ hash.merge!('expires_at' => access_token.expires_at) if access_token.expires?
61
+ hash.merge!('expires' => access_token.expires?)
62
+ hash
63
+ end
64
+
65
+ def request_phase
66
+ redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params))
67
+ end
68
+
69
+ def authorize_params
70
+ options.authorize_params[:state] = SecureRandom.hex(24)
71
+ params = options.authorize_params.merge(options_for('authorize'))
72
+ if OmniAuth.config.test_mode
73
+ @env ||= {}
74
+ @env['rack.session'] ||= {}
75
+ end
76
+ session['omniauth.state'] = params[:state]
77
+ params
78
+ end
79
+
80
+ def token_params
81
+ options.token_params.merge(options_for('token'))
82
+ end
83
+
84
+ def callback_phase # rubocop:disable CyclomaticComplexity, MethodLength, PerceivedComplexity
85
+ error = request.params['error_reason'] || request.params['error']
86
+ if error
87
+ fail!(error, CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri']))
88
+ elsif !options.provider_ignores_state && (request.params['state'].to_s.empty? || request.params['state'] != session.delete('omniauth.state'))
89
+ fail!(:csrf_detected, CallbackError.new(:csrf_detected, 'CSRF detected'))
90
+ else
91
+ self.access_token = build_access_token
92
+ self.access_token = access_token.refresh! if access_token.expired?
93
+ super
94
+ end
95
+ rescue ::OAuth2::Error, CallbackError => e
96
+ fail!(:invalid_credentials, e)
97
+ rescue ::MultiJson::DecodeError => e
98
+ fail!(:invalid_response, e)
99
+ rescue ::Timeout::Error, ::Errno::ETIMEDOUT, Faraday::Error::TimeoutError => e
100
+ fail!(:timeout, e)
101
+ rescue ::SocketError, Faraday::Error::ConnectionFailed => e
102
+ fail!(:failed_to_connect, e)
103
+ end
104
+
105
+ protected
106
+
107
+ def build_access_token
108
+ verifier = request.params['code']
109
+ client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)), deep_symbolize(options.auth_token_params))
110
+ end
111
+
112
+ def deep_symbolize(options)
113
+ hash = {}
114
+ options.each do |key, value|
115
+ hash[key.to_sym] = value.is_a?(Hash) ? deep_symbolize(value) : value
116
+ end
117
+ hash
118
+ end
119
+
120
+ def options_for(option)
121
+ hash = {}
122
+ options.send(:"#{option}_options").select { |key| options[key] }.each do |key|
123
+ hash[key.to_sym] = options[key]
124
+ end
125
+ hash
126
+ end
127
+
128
+ # An error that is indicated in the OAuth 2.0 callback.
129
+ # This could be a `redirect_uri_mismatch` or other
130
+ class CallbackError < StandardError
131
+ attr_accessor :error, :error_reason, :error_uri
132
+
133
+ def initialize(error, error_reason = nil, error_uri = nil)
134
+ self.error = error
135
+ self.error_reason = error_reason
136
+ self.error_uri = error_uri
137
+ end
138
+
139
+ def message
140
+ [error, error_reason, error_uri].compact.join(' | ')
141
+ end
142
+ end
143
+
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,3 @@
1
+ module MakerPass
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'omniauth'
2
+ require 'omniauth-makersquare/version'
3
+ require 'omniauth/makersquare'
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth-makersquare/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omniauth-makersquare"
8
+ spec.version = MakerPass::VERSION
9
+ spec.authors = ["Gilbert"]
10
+ spec.email = ["gilbertbgarza@gmail.com"]
11
+ spec.summary = %q{Official MakerSquare strategy for OmniAuth}
12
+ spec.description = %q{Official MakerSquare strategy for OmniAuth}
13
+ spec.homepage = "https://github.com/makersquare/omniauth-makersquare"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_dependency 'omniauth', '~> 1.0'
22
+ spec.add_dependency 'omniauth-oauth2', '>= 1.0'
23
+
24
+ spec.required_ruby_version = '~> 2.0'
25
+ spec.add_development_dependency 'bundler', '~> 1.5'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rspec', '~> 3.1'
28
+ end
File without changes
@@ -0,0 +1,25 @@
1
+
2
+ RSpec.configure do |config|
3
+ # rspec-expectations config goes here. You can use an alternate
4
+ # assertion/expectation library such as wrong or the stdlib/minitest
5
+ # assertions if you prefer.
6
+ config.expect_with :rspec do |expectations|
7
+ # This option will default to `true` in RSpec 4. It makes the `description`
8
+ # and `failure_message` of custom matchers include text for helper methods
9
+ # defined using `chain`, e.g.:
10
+ # be_bigger_than(2).and_smaller_than(4).description
11
+ # # => "be bigger than 2 and smaller than 4"
12
+ # ...rather than:
13
+ # # => "be bigger than 2"
14
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
15
+ end
16
+
17
+ # rspec-mocks config goes here. You can use an alternate test double
18
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
19
+ config.mock_with :rspec do |mocks|
20
+ # Prevents you from mocking or stubbing a method that does not exist on
21
+ # a real object. This is generally recommended, and will default to
22
+ # `true` in RSpec 4.
23
+ mocks.verify_partial_doubles = true
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-makersquare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gilbert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '3.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '3.1'
83
+ description: Official MakerSquare strategy for OmniAuth
84
+ email:
85
+ - gilbertbgarza@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/omniauth-makersquare.rb
97
+ - lib/omniauth-makersquare/version.rb
98
+ - lib/omniauth/makersquare.rb
99
+ - lib/omniauth/strategies/makersquare.rb
100
+ - omniauth-makersquare.gemspec
101
+ - spec/oauth_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: https://github.com/makersquare/omniauth-makersquare
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ~>
114
+ - !ruby/object:Gem::Version
115
+ version: '2.0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.2.2
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Official MakerSquare strategy for OmniAuth
127
+ test_files:
128
+ - spec/oauth_spec.rb
129
+ - spec/spec_helper.rb
130
+ has_rdoc: