omniauth-slooob 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/.github/issue_template.md +14 -0
- data/.github/pull_request_template.md +21 -0
- data/.gitignore +22 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +9 -0
- data/CODE_OF_CONDUCT.md +46 -0
- data/Gemfile +7 -0
- data/LICENSE +21 -0
- data/README.md +301 -0
- data/Rakefile +15 -0
- data/examples/omniauth.rb +31 -0
- data/examples/rails_example/.gitignore +27 -0
- data/examples/rails_example/Gemfile +54 -0
- data/examples/rails_example/README.md +24 -0
- data/examples/rails_example/Rakefile +6 -0
- data/examples/rails_example/app/assets/config/manifest.js +3 -0
- data/examples/rails_example/app/assets/images/.keep +0 -0
- data/examples/rails_example/app/assets/javascripts/application.js +15 -0
- data/examples/rails_example/app/assets/javascripts/books.coffee +3 -0
- data/examples/rails_example/app/assets/javascripts/cable.js +13 -0
- data/examples/rails_example/app/assets/javascripts/channels/.keep +0 -0
- data/examples/rails_example/app/assets/javascripts/sessions.coffee +3 -0
- data/examples/rails_example/app/assets/stylesheets/application.css +15 -0
- data/examples/rails_example/app/assets/stylesheets/books.scss +3 -0
- data/examples/rails_example/app/assets/stylesheets/scaffolds.scss +84 -0
- data/examples/rails_example/app/assets/stylesheets/sessions.scss +3 -0
- data/examples/rails_example/app/channels/application_cable/channel.rb +4 -0
- data/examples/rails_example/app/channels/application_cable/connection.rb +4 -0
- data/examples/rails_example/app/controllers/application_controller.rb +10 -0
- data/examples/rails_example/app/controllers/books_controller.rb +74 -0
- data/examples/rails_example/app/controllers/concerns/.keep +0 -0
- data/examples/rails_example/app/controllers/sessions_controller.rb +16 -0
- data/examples/rails_example/app/helpers/application_helper.rb +2 -0
- data/examples/rails_example/app/helpers/books_helper.rb +2 -0
- data/examples/rails_example/app/helpers/sessions_helper.rb +2 -0
- data/examples/rails_example/app/jobs/application_job.rb +2 -0
- data/examples/rails_example/app/mailers/application_mailer.rb +4 -0
- data/examples/rails_example/app/models/application_record.rb +3 -0
- data/examples/rails_example/app/models/book.rb +2 -0
- data/examples/rails_example/app/models/concerns/.keep +0 -0
- data/examples/rails_example/app/models/user.rb +12 -0
- data/examples/rails_example/app/views/books/_book.json.jbuilder +2 -0
- data/examples/rails_example/app/views/books/_form.html.erb +17 -0
- data/examples/rails_example/app/views/books/edit.html.erb +6 -0
- data/examples/rails_example/app/views/books/index.html.erb +25 -0
- data/examples/rails_example/app/views/books/index.json.jbuilder +1 -0
- data/examples/rails_example/app/views/books/new.html.erb +5 -0
- data/examples/rails_example/app/views/books/show.html.erb +4 -0
- data/examples/rails_example/app/views/books/show.json.jbuilder +1 -0
- data/examples/rails_example/app/views/layouts/application.html.erb +19 -0
- data/examples/rails_example/app/views/layouts/mailer.html.erb +13 -0
- data/examples/rails_example/app/views/layouts/mailer.text.erb +1 -0
- data/examples/rails_example/bin/bundle +3 -0
- data/examples/rails_example/bin/rails +4 -0
- data/examples/rails_example/bin/rake +4 -0
- data/examples/rails_example/bin/setup +38 -0
- data/examples/rails_example/bin/update +29 -0
- data/examples/rails_example/bin/yarn +11 -0
- data/examples/rails_example/config.ru +5 -0
- data/examples/rails_example/config/application.rb +18 -0
- data/examples/rails_example/config/boot.rb +3 -0
- data/examples/rails_example/config/cable.yml +10 -0
- data/examples/rails_example/config/database.yml +25 -0
- data/examples/rails_example/config/environment.rb +5 -0
- data/examples/rails_example/config/environments/development.rb +54 -0
- data/examples/rails_example/config/environments/production.rb +91 -0
- data/examples/rails_example/config/environments/test.rb +42 -0
- data/examples/rails_example/config/initializers/application_controller_renderer.rb +6 -0
- data/examples/rails_example/config/initializers/assets.rb +14 -0
- data/examples/rails_example/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/rails_example/config/initializers/config.rb +36 -0
- data/examples/rails_example/config/initializers/cookies_serializer.rb +5 -0
- data/examples/rails_example/config/initializers/filter_parameter_logging.rb +4 -0
- data/examples/rails_example/config/initializers/inflections.rb +16 -0
- data/examples/rails_example/config/initializers/mime_types.rb +4 -0
- data/examples/rails_example/config/initializers/omniauth.rb +3 -0
- data/examples/rails_example/config/initializers/wrap_parameters.rb +14 -0
- data/examples/rails_example/config/locales/en.yml +33 -0
- data/examples/rails_example/config/puma.rb +56 -0
- data/examples/rails_example/config/routes.rb +10 -0
- data/examples/rails_example/config/secrets.yml +32 -0
- data/examples/rails_example/config/settings.yml +1 -0
- data/examples/rails_example/config/settings/development.yml +3 -0
- data/examples/rails_example/config/settings/production.yml +3 -0
- data/examples/rails_example/config/settings/test.yml +3 -0
- data/examples/rails_example/db/migrate/20170827120704_create_books.rb +8 -0
- data/examples/rails_example/db/migrate/20170827122351_create_users.rb +11 -0
- data/examples/rails_example/db/schema.rb +28 -0
- data/examples/rails_example/db/seeds.rb +7 -0
- data/examples/rails_example/lib/assets/.keep +0 -0
- data/examples/rails_example/lib/tasks/.keep +0 -0
- data/examples/rails_example/log/.keep +0 -0
- data/examples/rails_example/package.json +5 -0
- data/examples/rails_example/public/404.html +67 -0
- data/examples/rails_example/public/422.html +67 -0
- data/examples/rails_example/public/500.html +66 -0
- data/examples/rails_example/public/apple-touch-icon-precomposed.png +0 -0
- data/examples/rails_example/public/apple-touch-icon.png +0 -0
- data/examples/rails_example/public/favicon.ico +0 -0
- data/examples/rails_example/public/robots.txt +1 -0
- data/examples/rails_example/test/application_system_test_case.rb +5 -0
- data/examples/rails_example/test/controllers/.keep +0 -0
- data/examples/rails_example/test/controllers/books_controller_test.rb +48 -0
- data/examples/rails_example/test/controllers/sessions_controller_test.rb +9 -0
- data/examples/rails_example/test/fixtures/.keep +0 -0
- data/examples/rails_example/test/fixtures/books.yml +11 -0
- data/examples/rails_example/test/fixtures/files/.keep +0 -0
- data/examples/rails_example/test/fixtures/users.yml +9 -0
- data/examples/rails_example/test/helpers/.keep +0 -0
- data/examples/rails_example/test/integration/.keep +0 -0
- data/examples/rails_example/test/mailers/.keep +0 -0
- data/examples/rails_example/test/models/.keep +0 -0
- data/examples/rails_example/test/models/book_test.rb +7 -0
- data/examples/rails_example/test/models/user_test.rb +7 -0
- data/examples/rails_example/test/system/.keep +0 -0
- data/examples/rails_example/test/system/books_test.rb +9 -0
- data/examples/rails_example/test/test_helper.rb +9 -0
- data/examples/rails_example/vendor/.keep +0 -0
- data/lib/omniauth-slooob.rb +1 -0
- data/lib/omniauth/slooob.rb +1 -0
- data/lib/omniauth/slooob/version.rb +7 -0
- data/lib/omniauth/strategies/slooob.rb +95 -0
- data/omniauth-slooob.gemspec +28 -0
- data/test/test.rb +239 -0
- metadata +265 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<style>
|
|
7
|
+
.rails-default-error-page {
|
|
8
|
+
background-color: #EFEFEF;
|
|
9
|
+
color: #2E2F30;
|
|
10
|
+
text-align: center;
|
|
11
|
+
font-family: arial, sans-serif;
|
|
12
|
+
margin: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.rails-default-error-page div.dialog {
|
|
16
|
+
width: 95%;
|
|
17
|
+
max-width: 33em;
|
|
18
|
+
margin: 4em auto 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.rails-default-error-page div.dialog > div {
|
|
22
|
+
border: 1px solid #CCC;
|
|
23
|
+
border-right-color: #999;
|
|
24
|
+
border-left-color: #999;
|
|
25
|
+
border-bottom-color: #BBB;
|
|
26
|
+
border-top: #B00100 solid 4px;
|
|
27
|
+
border-top-left-radius: 9px;
|
|
28
|
+
border-top-right-radius: 9px;
|
|
29
|
+
background-color: white;
|
|
30
|
+
padding: 7px 12% 0;
|
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.rails-default-error-page h1 {
|
|
35
|
+
font-size: 100%;
|
|
36
|
+
color: #730E15;
|
|
37
|
+
line-height: 1.5em;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.rails-default-error-page div.dialog > p {
|
|
41
|
+
margin: 0 0 1em;
|
|
42
|
+
padding: 1em;
|
|
43
|
+
background-color: #F7F7F7;
|
|
44
|
+
border: 1px solid #CCC;
|
|
45
|
+
border-right-color: #999;
|
|
46
|
+
border-left-color: #999;
|
|
47
|
+
border-bottom-color: #999;
|
|
48
|
+
border-bottom-left-radius: 4px;
|
|
49
|
+
border-bottom-right-radius: 4px;
|
|
50
|
+
border-top-color: #DADADA;
|
|
51
|
+
color: #666;
|
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
|
53
|
+
}
|
|
54
|
+
</style>
|
|
55
|
+
</head>
|
|
56
|
+
|
|
57
|
+
<body class="rails-default-error-page">
|
|
58
|
+
<!-- This file lives in public/422.html -->
|
|
59
|
+
<div class="dialog">
|
|
60
|
+
<div>
|
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
|
63
|
+
</div>
|
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
|
65
|
+
</div>
|
|
66
|
+
</body>
|
|
67
|
+
</html>
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<style>
|
|
7
|
+
.rails-default-error-page {
|
|
8
|
+
background-color: #EFEFEF;
|
|
9
|
+
color: #2E2F30;
|
|
10
|
+
text-align: center;
|
|
11
|
+
font-family: arial, sans-serif;
|
|
12
|
+
margin: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.rails-default-error-page div.dialog {
|
|
16
|
+
width: 95%;
|
|
17
|
+
max-width: 33em;
|
|
18
|
+
margin: 4em auto 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.rails-default-error-page div.dialog > div {
|
|
22
|
+
border: 1px solid #CCC;
|
|
23
|
+
border-right-color: #999;
|
|
24
|
+
border-left-color: #999;
|
|
25
|
+
border-bottom-color: #BBB;
|
|
26
|
+
border-top: #B00100 solid 4px;
|
|
27
|
+
border-top-left-radius: 9px;
|
|
28
|
+
border-top-right-radius: 9px;
|
|
29
|
+
background-color: white;
|
|
30
|
+
padding: 7px 12% 0;
|
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.rails-default-error-page h1 {
|
|
35
|
+
font-size: 100%;
|
|
36
|
+
color: #730E15;
|
|
37
|
+
line-height: 1.5em;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.rails-default-error-page div.dialog > p {
|
|
41
|
+
margin: 0 0 1em;
|
|
42
|
+
padding: 1em;
|
|
43
|
+
background-color: #F7F7F7;
|
|
44
|
+
border: 1px solid #CCC;
|
|
45
|
+
border-right-color: #999;
|
|
46
|
+
border-left-color: #999;
|
|
47
|
+
border-bottom-color: #999;
|
|
48
|
+
border-bottom-left-radius: 4px;
|
|
49
|
+
border-bottom-right-radius: 4px;
|
|
50
|
+
border-top-color: #DADADA;
|
|
51
|
+
color: #666;
|
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
|
53
|
+
}
|
|
54
|
+
</style>
|
|
55
|
+
</head>
|
|
56
|
+
|
|
57
|
+
<body class="rails-default-error-page">
|
|
58
|
+
<!-- This file lives in public/500.html -->
|
|
59
|
+
<div class="dialog">
|
|
60
|
+
<div>
|
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
|
62
|
+
</div>
|
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
|
64
|
+
</div>
|
|
65
|
+
</body>
|
|
66
|
+
</html>
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
|
|
File without changes
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class BooksControllerTest < ActionDispatch::IntegrationTest
|
|
4
|
+
setup do
|
|
5
|
+
@book = books(:one)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
test "should get index" do
|
|
9
|
+
get books_url
|
|
10
|
+
assert_response :success
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test "should get new" do
|
|
14
|
+
get new_book_url
|
|
15
|
+
assert_response :success
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
test "should create book" do
|
|
19
|
+
assert_difference('Book.count') do
|
|
20
|
+
post books_url, params: { book: { } }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
assert_redirected_to book_url(Book.last)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
test "should show book" do
|
|
27
|
+
get book_url(@book)
|
|
28
|
+
assert_response :success
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
test "should get edit" do
|
|
32
|
+
get edit_book_url(@book)
|
|
33
|
+
assert_response :success
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
test "should update book" do
|
|
37
|
+
patch book_url(@book), params: { book: { } }
|
|
38
|
+
assert_redirected_to book_url(@book)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
test "should destroy book" do
|
|
42
|
+
assert_difference('Book.count', -1) do
|
|
43
|
+
delete book_url(@book)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
assert_redirected_to books_url
|
|
47
|
+
end
|
|
48
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
|
2
|
+
|
|
3
|
+
# This model initially had no columns defined. If you add columns to the
|
|
4
|
+
# model remove the '{}' from the fixture names and add the columns immediately
|
|
5
|
+
# below each fixture, per the syntax in the comments below
|
|
6
|
+
#
|
|
7
|
+
one: {}
|
|
8
|
+
# column: value
|
|
9
|
+
#
|
|
10
|
+
two: {}
|
|
11
|
+
# column: value
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require File.expand_path('../../config/environment', __FILE__)
|
|
2
|
+
require 'rails/test_help'
|
|
3
|
+
|
|
4
|
+
class ActiveSupport::TestCase
|
|
5
|
+
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
|
6
|
+
fixtures :all
|
|
7
|
+
|
|
8
|
+
# Add more helper methods to be used by all tests here...
|
|
9
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'omniauth/slooob'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'omniauth/strategies/slooob'
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
require 'multi_json'
|
|
2
|
+
require 'omniauth/strategies/oauth2'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
module OmniAuth
|
|
6
|
+
module Strategies
|
|
7
|
+
class Slooob < OmniAuth::Strategies::OAuth2
|
|
8
|
+
|
|
9
|
+
DEFAULT_SCOPE = 'email public'
|
|
10
|
+
|
|
11
|
+
option :name, :slooob
|
|
12
|
+
option :authorize_options, %i[incremental_authorization image_size scope state]
|
|
13
|
+
|
|
14
|
+
option :client_options, {
|
|
15
|
+
site: 'https://api.slooob.com',
|
|
16
|
+
authorize_url: '/oauth/authorize'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
def authorize_params
|
|
20
|
+
super.tap do |params|
|
|
21
|
+
options[:authorize_options].each do |k|
|
|
22
|
+
params[k] = request.params[k.to_s] unless [nil, ''].include?(request.params[k.to_s])
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
params[:scope] = get_scope params
|
|
26
|
+
|
|
27
|
+
session['omniauth.state'] = params[:state] if params[:state]
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
uid { raw_info[:id] }
|
|
32
|
+
|
|
33
|
+
info do
|
|
34
|
+
prune!(
|
|
35
|
+
email: raw_info[:email],
|
|
36
|
+
username: raw_info[:username],
|
|
37
|
+
name: raw_info[:name],
|
|
38
|
+
first_name: raw_info[:first_name],
|
|
39
|
+
last_name: raw_info[:last_name],
|
|
40
|
+
description: raw_info[:name],
|
|
41
|
+
image: image_url,
|
|
42
|
+
location: raw_info[:location],
|
|
43
|
+
confirmed: raw_info[:email_confirmed],
|
|
44
|
+
urls: {
|
|
45
|
+
website: raw_info[:website],
|
|
46
|
+
slooob: raw_info[:profile]
|
|
47
|
+
}
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
extra do
|
|
52
|
+
hash = {}
|
|
53
|
+
hash[:raw_info] = raw_info unless skip_info?
|
|
54
|
+
prune! hash
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def raw_info
|
|
58
|
+
@raw_info ||= access_token.get('/identity/v1/resource.json').parsed
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# https://github.com/intridea/omniauth-oauth2/issues/81
|
|
66
|
+
def callback_url
|
|
67
|
+
options[:redirect_uri] || (full_host + script_name + callback_path)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def prune! hash
|
|
71
|
+
hash.delete_if do |_, v|
|
|
72
|
+
prune!(v) if v.is_a?(Hash)
|
|
73
|
+
v.nil? || (v.respond_to?(:empty?) && v.empty?)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def get_scope params
|
|
78
|
+
raw_scope = params[:scope] || DEFAULT_SCOPE
|
|
79
|
+
scope_list = raw_scope.split(' ').map { |item| item.split(',') }.flatten
|
|
80
|
+
scope_list.map! { |s| s =~ %r{^https?://} }
|
|
81
|
+
scope_list.join(' ')
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def image_url
|
|
85
|
+
return nil unless raw_info['avatar']
|
|
86
|
+
|
|
87
|
+
image_size = options[:image_size] || 'raw'
|
|
88
|
+
image_url = raw_info['avatar'].has_key?(image_size) ? raw_info['avatar'][image_size] : raw_info['avatar']
|
|
89
|
+
|
|
90
|
+
return image_url
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require File.expand_path File.join('..', 'lib', 'omniauth', 'slooob', 'version'), __FILE__
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.name = 'omniauth-slooob'
|
|
6
|
+
gem.version = OmniAuth::Slooob::VERSION
|
|
7
|
+
gem.platform = Gem::Platform::RUBY
|
|
8
|
+
gem.summary = 'Slooob OAuth2 strategy for OmniAuth'
|
|
9
|
+
gem.description = 'Slooob OAuth2 Strategy for OmniAuth. Built on Slooob Identity API v1.'
|
|
10
|
+
gem.authors = 'Slooob'
|
|
11
|
+
gem.email = 'developer@slooob.com'
|
|
12
|
+
gem.homepage = 'https://developer.slooob.com/docs/api/identity/v1'
|
|
13
|
+
gem.license = 'MIT'
|
|
14
|
+
|
|
15
|
+
gem.files = `git ls-files`.split("\n")
|
|
16
|
+
gem.require_paths = ['lib']
|
|
17
|
+
|
|
18
|
+
gem.required_ruby_version = '>= 2.0'
|
|
19
|
+
|
|
20
|
+
gem.add_runtime_dependency 'omniauth', '>= 1.1.1'
|
|
21
|
+
gem.add_runtime_dependency 'omniauth-oauth2', '>= 1.3.1'
|
|
22
|
+
gem.add_runtime_dependency 'multi_json', '~> 1.12'
|
|
23
|
+
|
|
24
|
+
gem.add_development_dependency 'shoulda', '~> 3.5'
|
|
25
|
+
gem.add_development_dependency 'shoulda-let', '~> 0.0'
|
|
26
|
+
gem.add_development_dependency 'tzinfo-data', '~> 1.2017'
|
|
27
|
+
gem.add_development_dependency 'rubocop', '~> 0.49'
|
|
28
|
+
end
|
data/test/test.rb
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# Configure Rails Envinronment
|
|
2
|
+
ENV['RAILS_ENV'] = 'test'
|
|
3
|
+
|
|
4
|
+
# # Test Coverage
|
|
5
|
+
# require 'simplecov'
|
|
6
|
+
# SimpleCov.start
|
|
7
|
+
|
|
8
|
+
require 'shoulda'
|
|
9
|
+
require 'shoulda/let'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Test
|
|
13
|
+
|
|
14
|
+
let(:request) { double('Request', params: {}, cookies: {}, env: {}) }
|
|
15
|
+
let(:app) do
|
|
16
|
+
lambda do
|
|
17
|
+
[200, {}, ['Hello.']]
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
setup do
|
|
22
|
+
OmniAuth::Strategies::Slooob.new(app, 'appid', 'secret', @options || {}).tap do |strategy|
|
|
23
|
+
allow(strategy).to receive(:request) do
|
|
24
|
+
request
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
before do
|
|
30
|
+
OmniAuth.config.test_mode = true
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
after do
|
|
34
|
+
OmniAuth.config.test_mode = false
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context '#client_options' do
|
|
38
|
+
should 'have correct site' do
|
|
39
|
+
assert_equal 'https://api.slooob.com', subject.client.site
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
should 'have correct authorize_url' do
|
|
43
|
+
assert_equal '/oauth/authorize', subject.client.options[:authorize_url]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
should 'have correct token_url' do
|
|
47
|
+
assert_equal '/oauth/token', subject.client.options[:token_url]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context 'overrides' do
|
|
51
|
+
context 'as strings' do
|
|
52
|
+
should 'allow overriding the site' do
|
|
53
|
+
@options = { client_options: { site: 'https://example.com' } }
|
|
54
|
+
assert_equal 'https://example.com', subject.client.site
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
should 'allow overriding the authorize_url' do
|
|
58
|
+
@options = { client_options: { authorize_url: 'https://example.com' } }
|
|
59
|
+
assert_equal 'https://example.com', subject.client.options[:authorize_url]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
should 'allow overriding the token_url' do
|
|
63
|
+
@options = { client_options: { token_url: 'https://example.com' } }
|
|
64
|
+
assert_equal 'https://example.com', subject.client.options[:token_url]
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context 'as symbols' do
|
|
69
|
+
should 'allow overriding the site' do
|
|
70
|
+
@options = { client_options: { site: 'https://example.com' } }
|
|
71
|
+
assert_equal 'https://example.com', subject.client.site
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
should 'allow overriding the authorize_url' do
|
|
75
|
+
@options = { client_options: { authorize_url: 'https://example.com' } }
|
|
76
|
+
assert_equal 'https://example.com', subject.client.options[:authorize_url]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
should 'allow overriding the token_url' do
|
|
80
|
+
@options = { client_options: { token_url: 'https://example.com' } }
|
|
81
|
+
assert_equal 'https://example.com', subject.client.options[:token_url]
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
context '#authorize_options' do
|
|
88
|
+
%i[email image_size redirect_uri incremental_authorization scope state].each do |k|
|
|
89
|
+
should "support #{k}" do
|
|
90
|
+
@options = { k => 'https://example.com' }
|
|
91
|
+
assert_equal 'https://example.com', subject.authorize_params[k.to_s]
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
context 'redirect_uri' do
|
|
96
|
+
should 'default to nil' do
|
|
97
|
+
@options = {}
|
|
98
|
+
assert_equal nil, subject.authorize_params['redirect_uri']
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
should 'set the redirect_uri parameter if present' do
|
|
102
|
+
@options = { redirect_uri: 'https://example.com' }
|
|
103
|
+
assert_equal 'https://example.com', subject.authorize_params['redirect_uri']
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
context 'email' do
|
|
108
|
+
should 'default to nil' do
|
|
109
|
+
assert_equal nil, subject.authorize_params['email']
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
should 'set the email parameter if present' do
|
|
113
|
+
@options = { email: 'john@example.com' }
|
|
114
|
+
assert_equal 'john@example.com', subject.authorize_params['email']
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
context 'image_size' do
|
|
119
|
+
should 'default to nil' do
|
|
120
|
+
assert_equal nil, subject.authorize_params['image_size']
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
should 'set the image_size parameter if present' do
|
|
124
|
+
@options = { image_size: 'raw' }
|
|
125
|
+
assert_equal 'raw', subject.authorize_params['image_size']
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
context 'incremental_authorization' do
|
|
130
|
+
should 'default to nil' do
|
|
131
|
+
assert_equal nil, subject.authorize_params['incremental_authorization']
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
should 'set the incremental_authorization parameter if present' do
|
|
135
|
+
@options = { incremental_authorization: true }
|
|
136
|
+
assert_equal true, subject.authorize_params['incremental_authorization']
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
context 'scope' do
|
|
141
|
+
should 'join scopes' do
|
|
142
|
+
@options = { scope: 'public,email' }
|
|
143
|
+
assert_equal 'public email', subject.authorize_params['scope']
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
should 'deal with whitespace when joining scopes' do
|
|
147
|
+
@options = { scope: 'public, email' }
|
|
148
|
+
assert_equal 'public email', subject.authorize_params['scope']
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
should 'set default scope to `email public`' do
|
|
152
|
+
assert_equal 'public email', subject.authorize_params['scope']
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
should 'support space delimited scopes' do
|
|
156
|
+
@options = { scope: 'public email' }
|
|
157
|
+
assert_equal 'public email', subject.authorize_params['scope']
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
context 'state' do
|
|
162
|
+
should 'set the state parameter' do
|
|
163
|
+
@options = { state: 'some_state' }
|
|
164
|
+
assert_equal 'some_state', subject.authorize_params['state']
|
|
165
|
+
assert_equal 'some_state', subject.authorize_params[:state]
|
|
166
|
+
assert_equal 'some_state', subject.session['omniauth.state']
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
context 'overrides' do
|
|
171
|
+
should 'include top-level options that are marked as :authorize_options' do
|
|
172
|
+
@options = { authorize_options: %i[scope], scope: 'messaging' }
|
|
173
|
+
assert_equal 'messaging', subject.authorize_params['scope']
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
context 'request overrides' do
|
|
177
|
+
%i[incremental_authorization scope state].each do |k|
|
|
178
|
+
context "authorize option #{k}" do
|
|
179
|
+
let(:request) { double('Request', params: { k.to_s => 'http://example.com' }, cookies: {}, env: {}) }
|
|
180
|
+
|
|
181
|
+
should "set the #{k} authorize option dynamically in the request" do
|
|
182
|
+
@options = { k: '' }
|
|
183
|
+
assert_equal 'http://example.com', subject.authorize_params[k.to_s]
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
context 'custom authorize_options' do
|
|
189
|
+
let(:request) { double('Request', params: { 'foo' => 'bar' }, cookies: {}, env: {}) }
|
|
190
|
+
|
|
191
|
+
should 'support request overrides from custom authorize_options' do
|
|
192
|
+
@options = { authorize_options: [:foo], foo: '' }
|
|
193
|
+
assert_equal 'bar', subject.authorize_params['foo']
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
context '#authorize_params' do
|
|
201
|
+
should 'include any authorize params passed in the :authorize_params option' do
|
|
202
|
+
@options = { authorize_params: { scope: 'something', foo: 'bar', baz: 'zip' }, incremental_authorization: true, bad: 'not_included' }
|
|
203
|
+
assert_equal 'something', subject.authorize_params['scope']
|
|
204
|
+
assert_equal 'bar', subject.authorize_params['foo']
|
|
205
|
+
assert_equal 'zip', subject.authorize_params['baz']
|
|
206
|
+
assert_equal true, subject.authorize_params['incremental_authorization']
|
|
207
|
+
assert_equal nil, subject.authorize_params['bad']
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
context '#token_params' do
|
|
212
|
+
should 'include any token params passed in the :token_params option' do
|
|
213
|
+
@options = { token_params: { foo: 'bar', baz: 'zip' } }
|
|
214
|
+
assert_equal 'bar', subject.token_params['foo']
|
|
215
|
+
assert_equal 'zip', subject.token_params['baz']
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
context '#token_options' do
|
|
220
|
+
should 'include top-level options that are marked as :token_options' do
|
|
221
|
+
@options = { token_options: %i[scope foo], scope: 'bar', foo: 'baz', bad: 'not_included' }
|
|
222
|
+
assert_equal 'bar', subject.token_params['scope']
|
|
223
|
+
assert_equal 'baz', subject.token_params['foo']
|
|
224
|
+
assert_equal nil, subject.token_params['bad']
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
context '#callback_path' do
|
|
229
|
+
should 'have the correct default callback path' do
|
|
230
|
+
assert_equal '/auth/slooob/callback', subject.callback_path
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
should 'set the callback_path parameter if present' do
|
|
234
|
+
@options = { callback_path: '/auth/foo/callback' }
|
|
235
|
+
assert_equal '/auth/foo/callback', subject.callback_path
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
end
|