omniauth-makerpass 1.0.0
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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +1 -0
- data/lib/omniauth-makepass.rb +3 -0
- data/lib/omniauth-makerpass/version.rb +3 -0
- data/lib/omniauth/makerpass.rb +10 -0
- data/lib/omniauth/strategies/makerpass.rb +148 -0
- data/omniauth-makerpass.gemspec +28 -0
- data/spec/oauth_spec.rb +0 -0
- data/spec/spec_helper.rb +25 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b7b5f636f492fc0390ca32446d9ef80cfadd7225
|
4
|
+
data.tar.gz: 002c868bbb7c84bc58c8333575296127f8953151
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad804e7b5d11cc5060ca8a0d6ce67314963a6d9f92e77f17d0193a85346f2fac54c850c788d3949821ae001d0306fd29427399e617ffdf03c497e3c829b5a68a
|
7
|
+
data.tar.gz: 80aad2683e344bc8b96149168c0b1f600d793d30077289e25872a96ef90ede772f10ca1591450a8a2abf46fa259d487cc87f96ca8374302c0bb7c85ebf4271b2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
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 MakerPass
|
2
|
+
|
3
|
+
Log in with MakerPass!
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'omniauth-makerpass', '1.0.0'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install omniauth-makerpass
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Email gilbert@makerpass.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/makerpass.rb`):
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
25
|
+
provider :makerpass, ENV['MAKERPASS_KEY'], ENV['MAKERPASS_SECRET']
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it ( http://github.com/<my-github-username>/omniauth-makerpass/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,148 @@
|
|
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 MakerPass
|
13
|
+
include OmniAuth::Strategy
|
14
|
+
|
15
|
+
uid { raw_info["uid"] }
|
16
|
+
args [:client_id, :client_secret]
|
17
|
+
|
18
|
+
option :name, :makerpass
|
19
|
+
|
20
|
+
option :client_options, {
|
21
|
+
:site => ENV['MAKERPASS_AUTH_URL'] || "https://auth.makerpass.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
|
+
:name => raw_info['name'],
|
38
|
+
:email => raw_info['email'],
|
39
|
+
:avatar_url => raw_info['avatar_url'],
|
40
|
+
:memberships => raw_info['memberships'],
|
41
|
+
:schools => raw_info['schools']
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
attr_accessor :access_token
|
46
|
+
|
47
|
+
def raw_info
|
48
|
+
@raw_info ||= access_token.get('/api/v1/me.json').parsed
|
49
|
+
end
|
50
|
+
|
51
|
+
def client
|
52
|
+
::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(options.client_options))
|
53
|
+
end
|
54
|
+
|
55
|
+
def callback_url
|
56
|
+
full_host + script_name + callback_path
|
57
|
+
end
|
58
|
+
|
59
|
+
credentials do
|
60
|
+
hash = {'token' => access_token.token}
|
61
|
+
hash.merge!('refresh_token' => access_token.refresh_token) if access_token.expires? && access_token.refresh_token
|
62
|
+
hash.merge!('expires_at' => access_token.expires_at) if access_token.expires?
|
63
|
+
hash.merge!('expires' => access_token.expires?)
|
64
|
+
hash
|
65
|
+
end
|
66
|
+
|
67
|
+
def request_phase
|
68
|
+
redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params))
|
69
|
+
end
|
70
|
+
|
71
|
+
def authorize_params
|
72
|
+
options.authorize_params[:state] = SecureRandom.hex(24)
|
73
|
+
params = options.authorize_params.merge(options_for('authorize'))
|
74
|
+
if OmniAuth.config.test_mode
|
75
|
+
@env ||= {}
|
76
|
+
@env['rack.session'] ||= {}
|
77
|
+
end
|
78
|
+
session['omniauth.state'] = params[:state]
|
79
|
+
params
|
80
|
+
end
|
81
|
+
|
82
|
+
def token_params
|
83
|
+
options.token_params.merge(options_for('token'))
|
84
|
+
end
|
85
|
+
|
86
|
+
def callback_phase # rubocop:disable CyclomaticComplexity, MethodLength, PerceivedComplexity
|
87
|
+
error = request.params['error_reason'] || request.params['error']
|
88
|
+
if error
|
89
|
+
fail!(error, CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri']))
|
90
|
+
elsif !options.provider_ignores_state && (request.params['state'].to_s.empty? || request.params['state'] != session.delete('omniauth.state'))
|
91
|
+
fail!(:csrf_detected, CallbackError.new(:csrf_detected, 'CSRF detected'))
|
92
|
+
else
|
93
|
+
self.access_token = build_access_token
|
94
|
+
self.access_token = access_token.refresh! if access_token.expired?
|
95
|
+
super
|
96
|
+
end
|
97
|
+
rescue ::OAuth2::Error, CallbackError => e
|
98
|
+
fail!(:invalid_credentials, e)
|
99
|
+
rescue ::MultiJson::DecodeError => e
|
100
|
+
fail!(:invalid_response, e)
|
101
|
+
rescue ::Timeout::Error, ::Errno::ETIMEDOUT, Faraday::Error::TimeoutError => e
|
102
|
+
fail!(:timeout, e)
|
103
|
+
rescue ::SocketError, Faraday::Error::ConnectionFailed => e
|
104
|
+
fail!(:failed_to_connect, e)
|
105
|
+
end
|
106
|
+
|
107
|
+
protected
|
108
|
+
|
109
|
+
def build_access_token
|
110
|
+
verifier = request.params['code']
|
111
|
+
client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)), deep_symbolize(options.auth_token_params))
|
112
|
+
end
|
113
|
+
|
114
|
+
def deep_symbolize(options)
|
115
|
+
hash = {}
|
116
|
+
options.each do |key, value|
|
117
|
+
hash[key.to_sym] = value.is_a?(Hash) ? deep_symbolize(value) : value
|
118
|
+
end
|
119
|
+
hash
|
120
|
+
end
|
121
|
+
|
122
|
+
def options_for(option)
|
123
|
+
hash = {}
|
124
|
+
options.send(:"#{option}_options").select { |key| options[key] }.each do |key|
|
125
|
+
hash[key.to_sym] = options[key]
|
126
|
+
end
|
127
|
+
hash
|
128
|
+
end
|
129
|
+
|
130
|
+
# An error that is indicated in the OAuth 2.0 callback.
|
131
|
+
# This could be a `redirect_uri_mismatch` or other
|
132
|
+
class CallbackError < StandardError
|
133
|
+
attr_accessor :error, :error_reason, :error_uri
|
134
|
+
|
135
|
+
def initialize(error, error_reason = nil, error_uri = nil)
|
136
|
+
self.error = error
|
137
|
+
self.error_reason = error_reason
|
138
|
+
self.error_uri = error_uri
|
139
|
+
end
|
140
|
+
|
141
|
+
def message
|
142
|
+
[error, error_reason, error_uri].compact.join(' | ')
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -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-makerpass/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "omniauth-makerpass"
|
8
|
+
spec.version = MakerPass::VERSION
|
9
|
+
spec.authors = ["Gilbert"]
|
10
|
+
spec.email = ["gilbertbgarza@gmail.com"]
|
11
|
+
spec.summary = %q{Official MakerPass strategy for OmniAuth}
|
12
|
+
spec.description = %q{Official MakerPass strategy for OmniAuth}
|
13
|
+
spec.homepage = "https://github.com/makerpass/omniauth-makerpass"
|
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
|
data/spec/oauth_spec.rb
ADDED
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -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,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-makerpass
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gilbert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-25 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 MakerPass 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-makepass.rb
|
97
|
+
- lib/omniauth-makerpass/version.rb
|
98
|
+
- lib/omniauth/makerpass.rb
|
99
|
+
- lib/omniauth/strategies/makerpass.rb
|
100
|
+
- omniauth-makerpass.gemspec
|
101
|
+
- spec/oauth_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
homepage: https://github.com/makerpass/omniauth-makerpass
|
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.0.14
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Official MakerPass strategy for OmniAuth
|
127
|
+
test_files:
|
128
|
+
- spec/oauth_spec.rb
|
129
|
+
- spec/spec_helper.rb
|