omniauth-mapsme 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +19 -0
- data/Rakefile +2 -0
- data/lib/omniauth-mapsme.rb +3 -0
- data/lib/omniauth-mapsme/version.rb +9 -0
- data/lib/omniauth/strategies/mapsme-base.rb +13 -0
- data/lib/omniauth/strategies/mapsme-token.rb +127 -0
- data/lib/omniauth/strategies/mapsme.rb +56 -0
- data/omniauth-mapsme.gemspec +23 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f3e26d372a2aaa5ceff75831f10caa8d81ffb08a
|
4
|
+
data.tar.gz: 028ddd93793576a9774dff5616cba7be75e0e203
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 26d075bc5be7c15a51b05e294f796c3a48a0932d995505e782afc741e211e0d504393aa0e25afdb18c433af4b1aac5321283c3c79d7a446611f7b636c52347fe
|
7
|
+
data.tar.gz: 3de46ee21923c1211238a4b1236c3f28e77a56943b21d44e9a740076517dabe0ce57195dfd191536a9527a8c0ebc7194089a4bad856331e2fb34e7296628ada0
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 MAPS.ME
|
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
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Omniauth MAPS.ME
|
2
|
+
|
3
|
+
This is a gem to connect to the MAPS.ME passport service via OAuth2. It requires OmniAuth.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
I'm too lazy to write this section, please use the code from [omniauth-osm examples](https://github.com/sozialhelden/omniauth-osm#how-to-use-it),
|
8
|
+
replacing `osm` with `mapsme`.
|
9
|
+
|
10
|
+
## Development
|
11
|
+
|
12
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
13
|
+
|
14
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
15
|
+
|
16
|
+
## License
|
17
|
+
|
18
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module OmniAuth
|
2
|
+
module Strategies
|
3
|
+
module MapsMeBase
|
4
|
+
MAPSME_BASE = 'http://passport.maps.me'
|
5
|
+
|
6
|
+
MAPSME_CLIENT_OPTIONS = {
|
7
|
+
:site => MAPSME_BASE,
|
8
|
+
:authorize_url => "#{MAPSME_BASE}/oauth/authorize",
|
9
|
+
:token_url => "#{MAPSME_BASE}/oauth/token"
|
10
|
+
}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'oauth2'
|
2
|
+
require 'omniauth'
|
3
|
+
require_relative 'mapsme-base'
|
4
|
+
|
5
|
+
module OmniAuth
|
6
|
+
module Strategies
|
7
|
+
class MapsMeToken
|
8
|
+
include OmniAuth::Strategy
|
9
|
+
include OmniAuth::Strategies::MapsMeBase
|
10
|
+
|
11
|
+
option :name, 'mapsme_token'
|
12
|
+
|
13
|
+
args [:client_id, :client_secret]
|
14
|
+
|
15
|
+
option :client_id, nil
|
16
|
+
option :client_secret, nil
|
17
|
+
|
18
|
+
option :client_options, MAPSME_CLIENT_OPTIONS
|
19
|
+
|
20
|
+
option :access_token_options, {
|
21
|
+
:header_format => 'OAuth %s',
|
22
|
+
:param_name => 'access_token'
|
23
|
+
}
|
24
|
+
|
25
|
+
attr_accessor :access_token
|
26
|
+
|
27
|
+
uid { raw_info['uid'].to_s }
|
28
|
+
|
29
|
+
info do
|
30
|
+
prune!({
|
31
|
+
'email' => raw_info['email'],
|
32
|
+
'name' => raw_info['name']
|
33
|
+
})
|
34
|
+
end
|
35
|
+
|
36
|
+
extra do
|
37
|
+
{ :raw_info => raw_info }
|
38
|
+
end
|
39
|
+
|
40
|
+
credentials do
|
41
|
+
hash = {'token' => access_token.token}
|
42
|
+
hash.merge!('refresh_token' => access_token.refresh_token) if access_token.expires? && access_token.refresh_token
|
43
|
+
hash.merge!('expires_at' => access_token.expires_at) if access_token.expires?
|
44
|
+
hash.merge!('expires' => access_token.expires?)
|
45
|
+
hash
|
46
|
+
end
|
47
|
+
|
48
|
+
def authorize_params
|
49
|
+
super.tap do |params|
|
50
|
+
params[:scope] = 'user mail'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def raw_info
|
55
|
+
@raw_info ||= access_token.get('/user').parsed || {}
|
56
|
+
end
|
57
|
+
|
58
|
+
def info_options
|
59
|
+
options[:info_fields] ? {:params => {:fields => options[:info_fields]}} : {}
|
60
|
+
end
|
61
|
+
|
62
|
+
def client
|
63
|
+
::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(options.client_options))
|
64
|
+
end
|
65
|
+
|
66
|
+
def request_phase
|
67
|
+
form = OmniAuth::Form.new(:title => "User Token", :url => callback_path)
|
68
|
+
form.text_field "Access Token", "access_token"
|
69
|
+
form.button "Sign In"
|
70
|
+
form.to_response
|
71
|
+
end
|
72
|
+
|
73
|
+
def callback_phase
|
74
|
+
if !request.params['access_token'] || request.params['access_token'].to_s.empty?
|
75
|
+
raise ArgumentError.new("No access token provided.")
|
76
|
+
end
|
77
|
+
|
78
|
+
self.access_token = build_access_token
|
79
|
+
self.access_token = self.access_token.refresh! if self.access_token.expired?
|
80
|
+
|
81
|
+
# Instead of calling super, duplicate the functionality, but change the provider to 'mapsme'.
|
82
|
+
# So the list of accounts is single for both strategies.
|
83
|
+
hash = auth_hash
|
84
|
+
hash[:provider] = "mapsme"
|
85
|
+
self.env['omniauth.auth'] = hash
|
86
|
+
call_app!
|
87
|
+
|
88
|
+
rescue ::OAuth2::Error => e
|
89
|
+
fail!(:invalid_credentials, e)
|
90
|
+
rescue ::MultiJson::DecodeError => e
|
91
|
+
fail!(:invalid_response, e)
|
92
|
+
rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
|
93
|
+
fail!(:timeout, e)
|
94
|
+
rescue ::SocketError => e
|
95
|
+
fail!(:failed_to_connect, e)
|
96
|
+
end
|
97
|
+
|
98
|
+
protected
|
99
|
+
|
100
|
+
def deep_symbolize(hash)
|
101
|
+
hash.inject({}) do |h, (k,v)|
|
102
|
+
h[k.to_sym] = v.is_a?(Hash) ? deep_symbolize(v) : v
|
103
|
+
h
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def build_access_token
|
108
|
+
# Options supported by `::OAuth2::AccessToken#initialize` and not overridden by `access_token_options`
|
109
|
+
hash = request.params.slice("access_token", "expires_at", "expires_in", "refresh_token")
|
110
|
+
hash.update(options.access_token_options)
|
111
|
+
::OAuth2::AccessToken.from_hash(
|
112
|
+
client,
|
113
|
+
hash
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
def prune!(hash)
|
118
|
+
hash.delete_if do |_, value|
|
119
|
+
prune!(value) if value.is_a?(Hash)
|
120
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
OmniAuth.config.add_camelization 'mapsme', 'MapsMe'
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
require_relative 'mapsme-base'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class MapsMe < OmniAuth::Strategies::OAuth2
|
7
|
+
include OmniAuth::Strategies::MapsMeBase
|
8
|
+
|
9
|
+
option :name, 'mapsme'
|
10
|
+
|
11
|
+
option :client_options, MAPSME_CLIENT_OPTIONS
|
12
|
+
|
13
|
+
uid { raw_info['uid'].to_s }
|
14
|
+
|
15
|
+
info do
|
16
|
+
{
|
17
|
+
'email' => raw_info['email'],
|
18
|
+
'name' => raw_info['name']
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
extra do
|
23
|
+
{ :raw_info => raw_info }
|
24
|
+
end
|
25
|
+
|
26
|
+
def authorize_params
|
27
|
+
super.tap do |params|
|
28
|
+
params[:scope] = 'user mail'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def raw_info
|
33
|
+
@raw_info ||= access_token.get('/user').parsed || {}
|
34
|
+
end
|
35
|
+
|
36
|
+
# Fix omniauth-oauth2 issue https://github.com/intridea/omniauth-oauth2/issues/76
|
37
|
+
|
38
|
+
def build_access_token
|
39
|
+
options.token_params.merge!(:headers => {'Authorization' => basic_auth_header })
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
def basic_auth_header
|
44
|
+
"Basic " + Base64.strict_encode64("#{options[:client_id]}:#{options[:client_secret]}")
|
45
|
+
end
|
46
|
+
|
47
|
+
# Fix omniauth-oauth2 issue https://github.com/intridea/omniauth-oauth2/issues/93
|
48
|
+
|
49
|
+
def callback_url
|
50
|
+
full_host + script_name + callback_path
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
OmniAuth.config.add_camelization 'mapsme', 'MapsMe'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'omniauth-mapsme/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "omniauth-mapsme"
|
8
|
+
spec.version = OmniAuth::MapsMe::VERSION
|
9
|
+
spec.authors = ["Ilya Zverev"]
|
10
|
+
spec.email = ["ilya@zverev.info"]
|
11
|
+
|
12
|
+
spec.summary = %q{MAPS.ME passport strategy for OmniAuth}
|
13
|
+
spec.description = %q{MAPS.ME passport strategy for OmniAuth, complete with regual and access token strategies}
|
14
|
+
spec.homepage = "http://maps.me/"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "omniauth", "~> 1.2"
|
21
|
+
spec.add_dependency "oauth2", "~> 1.0"
|
22
|
+
spec.add_dependency "omniauth-oauth2", "~> 1.4"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-mapsme
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ilya Zverev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-18 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.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: 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: omniauth-oauth2
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.4'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.4'
|
55
|
+
description: MAPS.ME passport strategy for OmniAuth, complete with regual and access
|
56
|
+
token strategies
|
57
|
+
email:
|
58
|
+
- ilya@zverev.info
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/omniauth-mapsme.rb
|
69
|
+
- lib/omniauth-mapsme/version.rb
|
70
|
+
- lib/omniauth/strategies/mapsme-base.rb
|
71
|
+
- lib/omniauth/strategies/mapsme-token.rb
|
72
|
+
- lib/omniauth/strategies/mapsme.rb
|
73
|
+
- omniauth-mapsme.gemspec
|
74
|
+
homepage: http://maps.me/
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.4.8
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: MAPS.ME passport strategy for OmniAuth
|
98
|
+
test_files: []
|