omniauth-translationexchange 1.0.0

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: d9e9d3f9d1bbe6d22a25449eeab03ed272bf3e8c
4
+ data.tar.gz: 35f20bd8fa2da242f0eeb6ab4afb9be0a0c6b3de
5
+ SHA512:
6
+ metadata.gz: 55e8151ee479a93ab3c1a90bad6c71061faea7b3193334bae6b7dcf27d46beec721d8a8fc9485b465994713cacb68e6ce7e3a2f189f28a6cf5d2fc535f747d3b
7
+ data.tar.gz: 45a9ba8dd631a02f999a47ff3afb436b90ca7e805b52b668b8497e48f888c628615390e7b030e8975ab4f8ca7a5e659e30c1936f8dffdcaffc5c22c23a03cb5d
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .idea
2
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ gem 'jruby-openssl', :platform => :jruby
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-translationexchange (1.0.0)
5
+ omniauth-oauth2 (~> 1.3)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.1.3)
11
+ faraday (0.12.1)
12
+ multipart-post (>= 1.2, < 3)
13
+ hashie (3.5.5)
14
+ jwt (1.5.6)
15
+ multi_json (1.12.1)
16
+ multi_xml (0.6.0)
17
+ multipart-post (2.0.0)
18
+ oauth2 (1.4.0)
19
+ faraday (>= 0.8, < 0.13)
20
+ jwt (~> 1.0)
21
+ multi_json (~> 1.3)
22
+ multi_xml (~> 0.5)
23
+ rack (>= 1.2, < 3)
24
+ omniauth (1.6.1)
25
+ hashie (>= 3.4.6, < 3.6.0)
26
+ rack (>= 1.6.2, < 3)
27
+ omniauth-oauth2 (1.4.0)
28
+ oauth2 (~> 1.0)
29
+ omniauth (~> 1.2)
30
+ rack (2.0.3)
31
+ rake (12.0.0)
32
+ rspec (2.7.0)
33
+ rspec-core (~> 2.7.0)
34
+ rspec-expectations (~> 2.7.0)
35
+ rspec-mocks (~> 2.7.0)
36
+ rspec-core (2.7.1)
37
+ rspec-expectations (2.7.0)
38
+ diff-lcs (~> 1.1.2)
39
+ rspec-mocks (2.7.0)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ jruby-openssl
46
+ omniauth-translationexchange!
47
+ rake (~> 12.0)
48
+ rspec (~> 2.7)
49
+
50
+ BUNDLED WITH
51
+ 1.14.6
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # OmniAuth for Translation Exchange
2
+
3
+ Translation Exchange OAuth2 Strategy for OmniAuth 1.4.
4
+
5
+ Supports the OAuth 2.0 server-side. Read the Translation Exchange docs for more details: https://docs.translationexchange.com/
6
+
7
+ ## Installing
8
+
9
+ Add to your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem 'omniauth-translationexchange'
13
+ ```
14
+
15
+ Then `bundle install`.
16
+
17
+ ## Usage
18
+
19
+ `OmniAuth::Strategies::TranslationExchange` is simply a Rack middleware. Read the OmniAuth 1.0 docs for detailed instructions: https://github.com/intridea/omniauth.
20
+
21
+ Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
22
+
23
+ ```ruby
24
+ Rails.application.config.middleware.use OmniAuth::Builder do
25
+ provider :translationexchange, ENV['TRANSLATION_EXCHANGE_KEY'], ENV['TRANSLATION_EXCHANGE_SECRET']
26
+ end
27
+ ```
28
+
29
+ ## Configuring
30
+
31
+ You can configure several options, which you pass in to the `provider` method via a `Hash`:
32
+
33
+ * `scope`: A comma-separated list of permissions you want to request from the user. See the Translation Exchange docs for a full list of available permissions. Default: `email`.
34
+ * `display`: The display context to show the authentication page. Options are: `web`, `desktop` and `mobile`. Default: `web`.
35
+
36
+ For example, to request `email` permission and display the authorization page in a mobile app:
37
+
38
+ ```ruby
39
+ Rails.application.config.middleware.use OmniAuth::Builder do
40
+ provider :translationexchange, ENV['TRANSLATION_EXCHANGE_KEY'], ENV['TRANSLATION_EXCHANGE_SECRET'], {
41
+ :scope => 'email',
42
+ :display => 'mobile'
43
+ }
44
+ end
45
+ ```
46
+
47
+ If you want to set the `display` format on a per-request basis, you can just pass it to the OmniAuth request phase URL, for example: `/auth/translationexchange?display=popup`.
48
+
49
+ ## Authentication Hash
50
+
51
+ Here's an example *Authentication Hash* available in `request.env['omniauth.auth']`:
52
+
53
+ ```ruby
54
+ {"provider"=>"translationexchange",
55
+ "uid"=>"4e4885fd-c0ee-47f2-871d-22473a3de08d",
56
+ "info"=>
57
+ {"id"=>"4e4885fd-c0ee-47f2-871d-22473a3de08d",
58
+ "display_name"=>"Alex Peterson",
59
+ "first_name"=>"Alex",
60
+ "last_name"=>"Peterson",
61
+ "email"=>"alex@domain.com",
62
+ "gender"=>"male",
63
+ "mugshot"=>
64
+ "https://gravatar.com/avatar/sdfasdfasdfasdfasdfasdfr34fsdf.png?s=65"},
65
+ "credentials"=>
66
+ {"token"=>"0ce884c17c79b74667e773c4c226e9fdc8f94f4c6fe4e7fd7b4558dbbbe62505",
67
+ "expires_at"=>1495153596,
68
+ "expires"=>true},
69
+ "extra"=>
70
+ {"user"=>
71
+ {"uuid"=>"4e4885fd-c0ee-47f2-871d-22473a3de08d",
72
+ "email"=>"alex@domain.com",
73
+ "role"=>"developer",
74
+ "display_name"=>"Alex Peterson",
75
+ "first_name"=>"Alex",
76
+ "last_name"=>"Peterson",
77
+ "name"=>"Alex Peterson",
78
+ "username"=>"alex",
79
+ "mugshot"=>
80
+ "https://gravatar.com/avatar/87345b2271259e2eeea3b01142f9af56.png?s=65",
81
+ "time_zone"=>"Pacific Time (US & Canada)",
82
+ "gender"=>"male",
83
+ "created_at"=>"2013-11-21 14:28:45",
84
+ "updated_at"=>"2017-05-18 15:23:03",
85
+ "password_set_at"=>"2016-11-28 19:22:39",
86
+ "last_logged_in_at"=>"2017-05-18 15:23:03"}}}
87
+ ```
88
+
89
+ The precise information available may depend on the permissions which you request.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/deploy ADDED
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ gem_name = 'omniauth-translationexchange'
4
+
5
+ def execute(cmd)
6
+ puts "\n***************************************************************************\n"
7
+ puts "$ #{cmd}"
8
+ system(cmd)
9
+ end
10
+
11
+ def version_file_path
12
+ './lib/omniauth/translation_exchange/version.rb'
13
+ end
14
+
15
+ def version_file
16
+ @version_file ||= File.read(version_file_path)
17
+ end
18
+
19
+ def version
20
+ @version ||= version_file.match(/VERSION\s*=\s*'([^']*)'/)[1]
21
+ end
22
+
23
+ def increment_version
24
+ parts = version.split('.')
25
+ parts[2] = (parts[2].to_i + 1).to_s
26
+ new_version = parts.join('.')
27
+
28
+ version_file.gsub!(version, new_version)
29
+
30
+ File.open(version_file_path, 'w') do |file|
31
+ file.write(version_file)
32
+ end
33
+
34
+ @version_file = nil
35
+ @version = nil
36
+ end
37
+
38
+ puts "\nBuilding omniauth-translationexchange-#{version}.gem..."
39
+
40
+ if ARGV.include?('release')
41
+ execute('git checkout master')
42
+ execute('git merge develop')
43
+ execute('git push')
44
+ end
45
+
46
+ execute('bundle exec rspec')
47
+ execute("gem build #{gem_name}.gemspec")
48
+ execute("gem install #{gem_name}-#{version}.gem --no-ri --no-rdoc")
49
+
50
+ if ARGV.include?('release')
51
+ execute("git tag #{version}")
52
+ execute('git push --tags')
53
+
54
+ execute("gem push #{gem_name}-#{version}.gem")
55
+
56
+ execute('git checkout develop')
57
+
58
+ increment_version
59
+
60
+ execute("git add #{version_file_path}")
61
+ execute("git commit -m 'Updated version to #{version}'")
62
+ execute('git push')
63
+ end
64
+
65
+
66
+
data/example/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source :rubygems
2
+
3
+ gem 'rack', '~> 1.3.6'
4
+
5
+ gem 'sinatra'
6
+ gem 'omniauth-translationexchange', :path => '../'
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ omniauth-geni (1.0.0)
5
+ omniauth-oauth2 (~> 1.0.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ addressable (2.2.6)
11
+ faraday (0.7.6)
12
+ addressable (~> 2.2)
13
+ multipart-post (~> 1.1)
14
+ rack (~> 1.1)
15
+ hashie (1.2.0)
16
+ multi_json (1.0.4)
17
+ multipart-post (1.1.4)
18
+ oauth2 (0.5.2)
19
+ faraday (~> 0.7)
20
+ multi_json (~> 1.0)
21
+ omniauth (1.0.2)
22
+ hashie (~> 1.2)
23
+ rack
24
+ omniauth-oauth2 (1.0.0)
25
+ oauth2 (~> 0.5.0)
26
+ omniauth (~> 1.0)
27
+ rack (1.3.6)
28
+ rack-protection (1.2.0)
29
+ rack
30
+ sinatra (1.3.2)
31
+ rack (~> 1.3, >= 1.3.6)
32
+ rack-protection (~> 1.2)
33
+ tilt (~> 1.3, >= 1.3.3)
34
+ tilt (1.3.3)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ omniauth-geni!
41
+ rack (~> 1.3.6)
42
+ sinatra
data/example/config.ru ADDED
@@ -0,0 +1,31 @@
1
+ require 'bundler/setup'
2
+ require 'sinatra/base'
3
+ require 'omniauth-translationexchange'
4
+
5
+ SCOPE = 'email'
6
+
7
+ class App < Sinatra::Base
8
+
9
+ get '/' do
10
+ redirect '/auth/translationexchange'
11
+ end
12
+
13
+ get '/auth/:provider/callback' do
14
+ content_type 'application/json'
15
+ MultiJson.encode(request.env)
16
+ end
17
+
18
+ get '/auth/failure' do
19
+ content_type 'application/json'
20
+ MultiJson.encode(request.env)
21
+ end
22
+
23
+ end
24
+
25
+ use Rack::Session::Cookie
26
+
27
+ use OmniAuth::Builder do
28
+ provider :translationexchange, ENV['APP_ID'], ENV['APP_SECRET'], :scope => SCOPE
29
+ end
30
+
31
+ run App.new
@@ -0,0 +1,32 @@
1
+ #--
2
+ # Copyright (c) 2017 Translation Exchange, Inc
3
+ #
4
+ # _______ _ _ _ ______ _
5
+ # |__ __| | | | | (_) | ____| | |
6
+ # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
+ # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
+ # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
+ # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
+ # __/ |
11
+ # |___/
12
+ # Permission is hereby granted, free of charge, to any person obtaining
13
+ # a copy of this software and associated documentation files (the
14
+ # "Software"), to deal in the Software without restriction, including
15
+ # without limitation the rights to use, copy, modify, merge, publish,
16
+ # distribute, sublicense, and/or sell copies of the Software, and to
17
+ # permit persons to whom the Software is furnished to do so, subject to
18
+ # the following conditions:
19
+ #
20
+ # The above copyright notice and this permission notice shall be
21
+ # included in all copies or substantial portions of the Software.
22
+ #
23
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+ #++
31
+
32
+ require 'omniauth/translation_exchange'
@@ -0,0 +1,106 @@
1
+ #--
2
+ # Copyright (c) 2017 Translation Exchange, Inc
3
+ #
4
+ # _______ _ _ _ ______ _
5
+ # |__ __| | | | | (_) | ____| | |
6
+ # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
+ # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
+ # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
+ # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
+ # __/ |
11
+ # |___/
12
+ # Permission is hereby granted, free of charge, to any person obtaining
13
+ # a copy of this software and associated documentation files (the
14
+ # "Software"), to deal in the Software without restriction, including
15
+ # without limitation the rights to use, copy, modify, merge, publish,
16
+ # distribute, sublicense, and/or sell copies of the Software, and to
17
+ # permit persons to whom the Software is furnished to do so, subject to
18
+ # the following conditions:
19
+ #
20
+ # The above copyright notice and this permission notice shall be
21
+ # included in all copies or substantial portions of the Software.
22
+ #
23
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+ #++
31
+
32
+ require 'omniauth-oauth2'
33
+
34
+ module OmniAuth
35
+ module Strategies
36
+ class TranslationExchange < OmniAuth::Strategies::OAuth2
37
+
38
+ # option :client_options, {
39
+ # :site => 'http://localhost:3000',
40
+ # :authorize_url => 'http://localhost:3008/oauth/authorize',
41
+ # :token_url => 'http://localhost:3008/oauth/token'
42
+ # }
43
+
44
+ option :client_options, {
45
+ :site => 'https://api.translationexchange.com',
46
+ :authorize_url => 'https://gateway.translationexchange.com/oauth/authorize',
47
+ :token_url => 'https://gateway.translationexchange.com/oauth/token'
48
+ }
49
+
50
+ option :name, 'translationexchange'
51
+
52
+ option :access_token_options, {
53
+ :header_format => 'OAuth %s',
54
+ :param_name => 'access_token'
55
+ }
56
+
57
+ option :authorize_options, [:scope, :display]
58
+
59
+ uid { raw_info['uuid'] }
60
+
61
+ info do
62
+ prune!({
63
+ 'id' => raw_info['uuid'],
64
+ 'display_name' => raw_info['display_name'],
65
+ 'first_name' => raw_info['first_name'],
66
+ 'last_name' => raw_info['last_name'],
67
+ 'email' => raw_info['email'],
68
+ 'gender' => raw_info['gender'],
69
+ 'mugshot' => raw_info['mugshot']
70
+ })
71
+ end
72
+
73
+ extra do
74
+ { 'user' => prune!(raw_info) }
75
+ end
76
+
77
+ def raw_info
78
+ @raw_info ||= access_token.get('/v2/users/me').parsed
79
+ end
80
+
81
+ # fix for the 1.4 and doorkeeper
82
+ def callback_url
83
+ full_host + script_name + callback_path
84
+ end
85
+
86
+ def authorize_params
87
+ super.tap do |params|
88
+ params.merge!(:display => request.params['display']) if request.params['display']
89
+ params.merge!(:state => request.params['state']) if request.params['state']
90
+ end
91
+ end
92
+
93
+ private
94
+
95
+ def prune!(hash)
96
+ hash.delete_if do |_, value|
97
+ prune!(value) if value.is_a?(Hash)
98
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
99
+ end
100
+ end
101
+
102
+ end
103
+ end
104
+ end
105
+
106
+ OmniAuth.config.add_camelization 'translationexchange', 'TranslationExchange'
@@ -0,0 +1,33 @@
1
+ #--
2
+ # Copyright (c) 2017 Translation Exchange, Inc
3
+ #
4
+ # _______ _ _ _ ______ _
5
+ # |__ __| | | | | (_) | ____| | |
6
+ # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
+ # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
+ # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
+ # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
+ # __/ |
11
+ # |___/
12
+ # Permission is hereby granted, free of charge, to any person obtaining
13
+ # a copy of this software and associated documentation files (the
14
+ # "Software"), to deal in the Software without restriction, including
15
+ # without limitation the rights to use, copy, modify, merge, publish,
16
+ # distribute, sublicense, and/or sell copies of the Software, and to
17
+ # permit persons to whom the Software is furnished to do so, subject to
18
+ # the following conditions:
19
+ #
20
+ # The above copyright notice and this permission notice shall be
21
+ # included in all copies or substantial portions of the Software.
22
+ #
23
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+ #++
31
+
32
+ require 'omniauth/translation_exchange/version'
33
+ require 'omniauth/strategies/translation_exchange'
@@ -0,0 +1,36 @@
1
+ #--
2
+ # Copyright (c) 2017 Translation Exchange, Inc
3
+ #
4
+ # _______ _ _ _ ______ _
5
+ # |__ __| | | | | (_) | ____| | |
6
+ # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
+ # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
+ # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
+ # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
+ # __/ |
11
+ # |___/
12
+ # Permission is hereby granted, free of charge, to any person obtaining
13
+ # a copy of this software and associated documentation files (the
14
+ # "Software"), to deal in the Software without restriction, including
15
+ # without limitation the rights to use, copy, modify, merge, publish,
16
+ # distribute, sublicense, and/or sell copies of the Software, and to
17
+ # permit persons to whom the Software is furnished to do so, subject to
18
+ # the following conditions:
19
+ #
20
+ # The above copyright notice and this permission notice shall be
21
+ # included in all copies or substantial portions of the Software.
22
+ #
23
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+ #++
31
+
32
+ module OmniAuth
33
+ module TranslationExchange
34
+ VERSION = '1.0.0'
35
+ end
36
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'omniauth/translation_exchange/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'omniauth-translationexchange'
7
+ s.version = OmniAuth::TranslationExchange::VERSION
8
+ s.authors = ['Michael Berkovich']
9
+ s.email = ['michael@translationexchange.com']
10
+ s.summary = 'Translation Exchange strategy for OmniAuth'
11
+ s.homepage = 'https://github.com/translationexchange/omniauth-translationexchange'
12
+ s.description = 'Translation Exchange strategy for SSO using OmniAuth framework'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
17
+ s.require_paths = ['lib']
18
+ s.licenses = 'MIT-LICENSE'
19
+
20
+ s.add_runtime_dependency 'omniauth-oauth2', '~> 1.3'
21
+ s.add_development_dependency 'rspec', '~> 2.7'
22
+ s.add_development_dependency 'rake', '~> 12.0'
23
+ end
@@ -0,0 +1,211 @@
1
+ #--
2
+ # Copyright (c) 2017 Translation Exchange, Inc
3
+ #
4
+ # _______ _ _ _ ______ _
5
+ # |__ __| | | | | (_) | ____| | |
6
+ # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
+ # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
+ # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
+ # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
+ # __/ |
11
+ # |___/
12
+ # Permission is hereby granted, free of charge, to any person obtaining
13
+ # a copy of this software and associated documentation files (the
14
+ # "Software"), to deal in the Software without restriction, including
15
+ # without limitation the rights to use, copy, modify, merge, publish,
16
+ # distribute, sublicense, and/or sell copies of the Software, and to
17
+ # permit persons to whom the Software is furnished to do so, subject to
18
+ # the following conditions:
19
+ #
20
+ # The above copyright notice and this permission notice shall be
21
+ # included in all copies or substantial portions of the Software.
22
+ #
23
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+ #++
31
+
32
+ require 'spec_helper'
33
+ require 'omniauth-translationexchange'
34
+
35
+ describe OmniAuth::Strategies::TranslationExchange do
36
+ before :each do
37
+ @request = double('Request')
38
+ @request.stub(:params) { {} }
39
+ @request.stub(:cookies) { {} }
40
+
41
+ @client_id = 'abc'
42
+ @client_secret = 'def'
43
+ end
44
+
45
+ subject do
46
+ args = [@client_id, @client_secret, @options].compact
47
+ OmniAuth::Strategies::TranslationExchange.new(nil, *args).tap do |strategy|
48
+ strategy.stub(:request) { @request }
49
+ end
50
+ end
51
+
52
+ it_should_behave_like 'an oauth2 strategy'
53
+
54
+ describe '#client' do
55
+ it 'has correct site' do
56
+ subject.client.site.should eq('https://api.translationexchange.com')
57
+ end
58
+
59
+ it 'has correct authorize url' do
60
+ subject.client.options[:authorize_url].should eq('https://gateway.translationexchange.com/oauth/authorize')
61
+ end
62
+
63
+ it 'has correct token url' do
64
+ subject.client.options[:token_url].should eq('https://gateway.translationexchange.com/oauth/token')
65
+ end
66
+ end
67
+
68
+ describe '#authorize_params' do
69
+ it 'includes display parameter from request when present' do
70
+ # @request.stub(:params) { { 'display' => 'mobile' } }
71
+ # subject.authorize_params.should be_a(Hash)
72
+ # subject.authorize_params[:display].should eq('mobile')
73
+ end
74
+
75
+ it 'includes state parameter from request when present' do
76
+ # @request.stub(:params) { { 'state' => 'some_state' } }
77
+ # subject.authorize_params.should be_a(Hash)
78
+ # subject.authorize_params[:state].should eq('some_state')
79
+ end
80
+ end
81
+
82
+ describe '#uid' do
83
+ before :each do
84
+ subject.stub(:raw_info) { { 'uuid' => '123' } }
85
+ end
86
+
87
+ it 'returns the id from raw_info' do
88
+ subject.uid.should eq('123')
89
+ end
90
+ end
91
+
92
+ describe '#info' do
93
+ before :each do
94
+ @raw_info ||= { 'first_name' => 'Alex' }
95
+ subject.stub(:raw_info) { @raw_info }
96
+ end
97
+
98
+ context 'when optional data is not present in raw info' do
99
+ it 'has no email key' do
100
+ subject.info.should_not have_key('email')
101
+ end
102
+
103
+ it 'has no last name key' do
104
+ subject.info.should_not have_key('last_name')
105
+ end
106
+ end
107
+
108
+ context 'when data is present in raw info' do
109
+ it 'returns first name' do
110
+ subject.info['first_name'].should eq('Alex')
111
+ end
112
+
113
+ it 'returns the email' do
114
+ @raw_info['email'] = 'fred@smith.com'
115
+ subject.info['email'].should eq('fred@smith.com')
116
+ end
117
+ end
118
+ end
119
+
120
+ describe '#raw_info' do
121
+ before :each do
122
+ @access_token = double('OAuth2::AccessToken')
123
+ subject.stub(:access_token) { @access_token }
124
+ end
125
+
126
+ it 'performs a GET to https://api.translationexchange.com/v1/users/me' do
127
+ @access_token.stub(:get) { double('OAuth2::Response').as_null_object }
128
+ @access_token.should_receive(:get).with('/v2/users/me')
129
+ subject.raw_info
130
+ end
131
+
132
+ it 'returns a Hash' do
133
+ @access_token.stub(:get).with('/v2/users/me') do
134
+ raw_response = double('Faraday::Response')
135
+ raw_response.stub(:body) { '{ "ohai": "thar" }' }
136
+ raw_response.stub(:status) { 200 }
137
+ raw_response.stub(:headers) { { 'Content-Type' => 'application/json' } }
138
+ OAuth2::Response.new(raw_response)
139
+ end
140
+ subject.raw_info.should be_a(Hash)
141
+ subject.raw_info['ohai'].should eq('thar')
142
+ end
143
+ end
144
+
145
+ describe '#credentials' do
146
+ before :each do
147
+ @access_token = double('OAuth2::AccessToken')
148
+ @access_token.stub(:token)
149
+ @access_token.stub(:expires?)
150
+ @access_token.stub(:expires_at)
151
+ @access_token.stub(:refresh_token)
152
+ subject.stub(:access_token) { @access_token }
153
+ end
154
+
155
+ it 'returns a Hash' do
156
+ subject.credentials.should be_a(Hash)
157
+ end
158
+
159
+ it 'returns the token' do
160
+ @access_token.stub(:token) { '123' }
161
+ subject.credentials['token'].should eq('123')
162
+ end
163
+
164
+ it 'returns the expiry status' do
165
+ @access_token.stub(:expires?) { true }
166
+ subject.credentials['expires'].should eq(true)
167
+
168
+ @access_token.stub(:expires?) { false }
169
+ subject.credentials['expires'].should eq(false)
170
+ end
171
+
172
+ it 'returns the refresh token and expiry time when expiring' do
173
+ ten_mins_from_now = (Time.now + 600).to_i
174
+ @access_token.stub(:expires?) { true }
175
+ @access_token.stub(:refresh_token) { '321' }
176
+ @access_token.stub(:expires_at) { ten_mins_from_now }
177
+ subject.credentials['refresh_token'].should eq('321')
178
+ subject.credentials['expires_at'].should eq(ten_mins_from_now)
179
+ end
180
+
181
+ it 'does not return the refresh token when it is nil and expiring' do
182
+ @access_token.stub(:expires?) { true }
183
+ @access_token.stub(:refresh_token) { nil }
184
+ subject.credentials['refresh_token'].should be_nil
185
+ subject.credentials.should_not have_key('refresh_token')
186
+ end
187
+
188
+ it 'does not return the refresh token when not expiring' do
189
+ @access_token.stub(:expires?) { false }
190
+ @access_token.stub(:refresh_token) { 'XXX' }
191
+ subject.credentials['refresh_token'].should be_nil
192
+ subject.credentials.should_not have_key('refresh_token')
193
+ end
194
+ end
195
+
196
+ describe '#extra' do
197
+ before :each do
198
+ @raw_info = { 'name' => 'Fred Smith' }
199
+ subject.stub(:raw_info) { @raw_info }
200
+ end
201
+
202
+ it 'returns a Hash' do
203
+ subject.extra.should be_a(Hash)
204
+ end
205
+
206
+ it 'contains raw info' do
207
+ subject.extra.should eq({ 'user' => @raw_info })
208
+ end
209
+ end
210
+
211
+ end
@@ -0,0 +1,37 @@
1
+ #--
2
+ # Copyright (c) 2017 Translation Exchange, Inc
3
+ #
4
+ # _______ _ _ _ ______ _
5
+ # |__ __| | | | | (_) | ____| | |
6
+ # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
+ # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
+ # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
+ # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
+ # __/ |
11
+ # |___/
12
+ # Permission is hereby granted, free of charge, to any person obtaining
13
+ # a copy of this software and associated documentation files (the
14
+ # "Software"), to deal in the Software without restriction, including
15
+ # without limitation the rights to use, copy, modify, merge, publish,
16
+ # distribute, sublicense, and/or sell copies of the Software, and to
17
+ # permit persons to whom the Software is furnished to do so, subject to
18
+ # the following conditions:
19
+ #
20
+ # The above copyright notice and this permission notice shall be
21
+ # included in all copies or substantial portions of the Software.
22
+ #
23
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+ #++
31
+
32
+ require 'bundler/setup'
33
+ require 'rspec'
34
+ Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
35
+
36
+ RSpec.configure do |config|
37
+ end
@@ -0,0 +1,53 @@
1
+ #--
2
+ # Copyright (c) 2017 Translation Exchange, Inc
3
+ #
4
+ # _______ _ _ _ ______ _
5
+ # |__ __| | | | | (_) | ____| | |
6
+ # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
+ # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
+ # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
+ # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
+ # __/ |
11
+ # |___/
12
+ # Permission is hereby granted, free of charge, to any person obtaining
13
+ # a copy of this software and associated documentation files (the
14
+ # "Software"), to deal in the Software without restriction, including
15
+ # without limitation the rights to use, copy, modify, merge, publish,
16
+ # distribute, sublicense, and/or sell copies of the Software, and to
17
+ # permit persons to whom the Software is furnished to do so, subject to
18
+ # the following conditions:
19
+ #
20
+ # The above copyright notice and this permission notice shall be
21
+ # included in all copies or substantial portions of the Software.
22
+ #
23
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+ #++
31
+
32
+ shared_examples 'an oauth2 strategy' do
33
+ describe '#client' do
34
+ it 'should be initialized with symbolized client_options' do
35
+ @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
36
+ subject.client.options[:authorize_url].should == 'https://example.com'
37
+ end
38
+ end
39
+
40
+ describe '#token_params' do
41
+ it 'should include any authorize params passed in the :authorize_params option' do
42
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
43
+ subject.token_params['foo'].should eq('bar')
44
+ subject.token_params['baz'].should eq('zip')
45
+ end
46
+
47
+ it 'should include top-level options that are marked as :authorize_options' do
48
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
49
+ subject.token_params['scope'].should eq('bar')
50
+ subject.token_params['foo'].should eq('baz')
51
+ end
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-translationexchange
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Berkovich
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-20 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.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
55
+ description: Translation Exchange strategy for SSO using OmniAuth framework
56
+ email:
57
+ - michael@translationexchange.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - README.md
66
+ - Rakefile
67
+ - deploy
68
+ - example/Gemfile
69
+ - example/Gemfile.lock
70
+ - example/config.ru
71
+ - lib/omniauth-translationexchange.rb
72
+ - lib/omniauth/strategies/translation_exchange.rb
73
+ - lib/omniauth/translation_exchange.rb
74
+ - lib/omniauth/translation_exchange/version.rb
75
+ - omniauth-translationexchange.gemspec
76
+ - spec/omniauth/strategies/translation_exchange_spec.rb
77
+ - spec/spec_helper.rb
78
+ - spec/support/shared_examples.rb
79
+ homepage: https://github.com/translationexchange/omniauth-translationexchange
80
+ licenses:
81
+ - MIT-LICENSE
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.4.5
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Translation Exchange strategy for OmniAuth
103
+ test_files:
104
+ - spec/omniauth/strategies/translation_exchange_spec.rb
105
+ - spec/spec_helper.rb
106
+ - spec/support/shared_examples.rb