hobby-sso-emailing_server 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +83 -0
- data/hobby-sso-emailing_server.gemspec +12 -0
- data/lib/hobby/sso/emailing_server.rb +61 -0
- data/lib/hobby/sso/emailing_server/page_for_providing_email.slim +10 -0
- data/lib/hobby/sso/emailing_server/service.rb +31 -0
- data/lib/hobby/sso/emailing_server/services.rb +16 -0
- data/spec/helper.rb +25 -0
- data/spec/integration_spec.rb +18 -0
- data/spec/test_authserver.rb +9 -0
- data/spec/test_service.rb +17 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 92ec5a8024406215d0a5b818a8d29e6eb7c19680c14add2b2854a147ef8a87ad
|
4
|
+
data.tar.gz: f74bd8e0aab591032baa40232f7f8b3b2475bd44cf819be6e09a8ecae8f549ac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b5db883afba1b4de3d1b7c305e538ef4cdfc80ac9c650a246b886e67599624633e99a05362f1fbe0d653568223880e1972719f7a8414d9ebef7f543b3920cbb8
|
7
|
+
data.tar.gz: c0ad0671fe2539a8f8ba8eed3e1b6cc95d3f9016bee67a9517698f1020a08a1a596859d0f8054a760876c34ec025c97dd11b961670bdb850545ccd8a91e55f0a
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hobby-sso-emailing_server (0.0.0)
|
5
|
+
email_address
|
6
|
+
hobby
|
7
|
+
mail
|
8
|
+
slim
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
awesome_print (1.8.0)
|
14
|
+
childprocess (0.9.0)
|
15
|
+
ffi (~> 1.0, >= 1.0.11)
|
16
|
+
coderay (1.1.2)
|
17
|
+
diff-lcs (1.3)
|
18
|
+
email_address (0.1.9)
|
19
|
+
netaddr (~> 2.0)
|
20
|
+
simpleidn
|
21
|
+
ffi (1.9.23)
|
22
|
+
hobby (0.1.2)
|
23
|
+
rack
|
24
|
+
mail (2.7.0)
|
25
|
+
mini_mime (>= 0.1.1)
|
26
|
+
method_source (0.9.0)
|
27
|
+
mini_mime (1.0.0)
|
28
|
+
netaddr (2.0.3)
|
29
|
+
power_assert (1.1.1)
|
30
|
+
pry (0.11.3)
|
31
|
+
coderay (~> 1.1.0)
|
32
|
+
method_source (~> 0.9.0)
|
33
|
+
puma (3.11.3)
|
34
|
+
rack (2.0.4)
|
35
|
+
redis (4.0.1)
|
36
|
+
rspec (3.7.0)
|
37
|
+
rspec-core (~> 3.7.0)
|
38
|
+
rspec-expectations (~> 3.7.0)
|
39
|
+
rspec-mocks (~> 3.7.0)
|
40
|
+
rspec-core (3.7.1)
|
41
|
+
rspec-support (~> 3.7.0)
|
42
|
+
rspec-expectations (3.7.0)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.7.0)
|
45
|
+
rspec-mocks (3.7.0)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.7.0)
|
48
|
+
rspec-power_assert (1.1.0)
|
49
|
+
power_assert (~> 1.1.0)
|
50
|
+
rspec (>= 2.14)
|
51
|
+
rspec-support (3.7.1)
|
52
|
+
rubyzip (1.2.1)
|
53
|
+
selenium-webdriver (3.11.0)
|
54
|
+
childprocess (~> 0.5)
|
55
|
+
rubyzip (~> 1.2)
|
56
|
+
simpleidn (0.1.1)
|
57
|
+
unf (~> 0.1.4)
|
58
|
+
slim (3.0.9)
|
59
|
+
temple (>= 0.7.6, < 0.9)
|
60
|
+
tilt (>= 1.3.3, < 2.1)
|
61
|
+
temple (0.8.0)
|
62
|
+
tilt (2.0.8)
|
63
|
+
unf (0.1.4)
|
64
|
+
unf_ext
|
65
|
+
unf_ext (0.0.7.5)
|
66
|
+
watir (6.10.3)
|
67
|
+
selenium-webdriver (~> 3.4, >= 3.4.1)
|
68
|
+
|
69
|
+
PLATFORMS
|
70
|
+
ruby
|
71
|
+
|
72
|
+
DEPENDENCIES
|
73
|
+
awesome_print
|
74
|
+
hobby-sso-emailing_server!
|
75
|
+
pry
|
76
|
+
puma
|
77
|
+
redis
|
78
|
+
rspec
|
79
|
+
rspec-power_assert
|
80
|
+
watir
|
81
|
+
|
82
|
+
BUNDLED WITH
|
83
|
+
1.16.1
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Gem::Specification.new do |g|
|
2
|
+
g.name = 'hobby-sso-emailing_server'
|
3
|
+
g.files = `git ls-files`.split($/)
|
4
|
+
g.version = '0.0.0'
|
5
|
+
g.summary = 'A hobby-sso server providing authentication links to emails.'
|
6
|
+
g.authors = ['Anatoly Chernow']
|
7
|
+
|
8
|
+
g.add_dependency 'hobby'
|
9
|
+
g.add_dependency 'mail'
|
10
|
+
g.add_dependency 'email_address'
|
11
|
+
g.add_dependency 'slim'
|
12
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'hobby'
|
2
|
+
require 'mail'
|
3
|
+
require 'email_address'
|
4
|
+
require 'slim'
|
5
|
+
|
6
|
+
require_relative 'emailing_server/services'
|
7
|
+
require_relative 'emailing_server/service'
|
8
|
+
|
9
|
+
module Hobby::SSO
|
10
|
+
class EmailingServer
|
11
|
+
include Hobby
|
12
|
+
|
13
|
+
use Rack::ContentType, 'text/html'
|
14
|
+
|
15
|
+
def initialize services: {}, mail: Mail.new,
|
16
|
+
page_for_providing_email: Slim::Template.new("#{__dir__}/emailing_server/page_for_providing_email.slim")
|
17
|
+
@services, @mail = Services.new(services), mail
|
18
|
+
@page_for_providing_email = page_for_providing_email
|
19
|
+
end
|
20
|
+
|
21
|
+
def service
|
22
|
+
@service ||= @services[request.params['service']]
|
23
|
+
end
|
24
|
+
|
25
|
+
def email
|
26
|
+
@email ||= begin
|
27
|
+
email = request.params['email']
|
28
|
+
email if EmailAddress.valid? email
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
get do
|
33
|
+
if service
|
34
|
+
@page_for_providing_email.render self
|
35
|
+
else
|
36
|
+
'Please specify to which service you would like to authenticate.'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
post do
|
41
|
+
if service && email
|
42
|
+
begin
|
43
|
+
send_link service.create_session email
|
44
|
+
"A link for entering to #{@service} has been sent to #{email}."
|
45
|
+
rescue
|
46
|
+
p $!
|
47
|
+
'A link has not been sent cause something went wrong, sorry.'
|
48
|
+
end
|
49
|
+
else
|
50
|
+
'Not appropriate service or email.'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def send_link link
|
55
|
+
@mail.to = email
|
56
|
+
@mail.subject = "A login link to #{service} issued at #{Time.now}"
|
57
|
+
@mail.body = "During a short period of time, you will be able to login to #{service} by following this link:\n\n#{link}"
|
58
|
+
@mail.deliver
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
doctype 5
|
2
|
+
html
|
3
|
+
head
|
4
|
+
title Login via emailed link
|
5
|
+
body
|
6
|
+
form(action=script_name method='post')
|
7
|
+
p Please submit an email you have access to.
|
8
|
+
input(type='email' placeholder='Email' name='email' required)
|
9
|
+
input(type='hidden' value=service)
|
10
|
+
button(type='submit') Submit
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Hobby::SSO
|
2
|
+
class EmailingServer
|
3
|
+
class Service
|
4
|
+
def initialize sessions:, tickets:
|
5
|
+
@sessions, @tickets = sessions, tickets
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_accessor :domain
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
@domain
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_session user_id
|
15
|
+
session, ticket = random, random
|
16
|
+
@sessions.set session, user_id
|
17
|
+
@tickets.set ticket, session
|
18
|
+
link_with_ticket ticket
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def random
|
23
|
+
SecureRandom.urlsafe_base64 64
|
24
|
+
end
|
25
|
+
|
26
|
+
def link_with_ticket ticket
|
27
|
+
"#{domain}/enter?ticket=#{ticket}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'hobby/sso/emailing_server'
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
require 'watir'
|
5
|
+
|
6
|
+
require 'rspec/power_assert'
|
7
|
+
RSpec::PowerAssert.example_assertion_alias :assert
|
8
|
+
RSpec::PowerAssert.example_group_assertion_alias :assert
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.before :suite do
|
12
|
+
$test_app_pid = fork do
|
13
|
+
require_relative 'test_authserver'
|
14
|
+
require 'puma'
|
15
|
+
server = Puma::Server.new TEST_AUTHSERVER
|
16
|
+
server.add_tcp_listener '127.0.0.1', 8080
|
17
|
+
server.run
|
18
|
+
sleep
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
config.after :suite do
|
23
|
+
`kill #{$test_app_pid}`
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
describe do
|
4
|
+
let(:browser) { Watir::Browser.new }
|
5
|
+
|
6
|
+
it do
|
7
|
+
browser.goto 'http://127.0.0.1:8080?service=https://some.domain'
|
8
|
+
form = browser.form
|
9
|
+
form.text_field(name: 'email').set 'chertoly@gmail.com'
|
10
|
+
form.submit
|
11
|
+
|
12
|
+
assert { browser.text.include? 'A link for entering to https://some.domain has been sent to chertoly@gmail.com.' }
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
browser.quit
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class MockRedis
|
2
|
+
def initialize
|
3
|
+
@hash = {}
|
4
|
+
end
|
5
|
+
|
6
|
+
def get key
|
7
|
+
@hash[key]
|
8
|
+
end
|
9
|
+
|
10
|
+
def set key, value
|
11
|
+
@hash[key] = value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
TEST_SERVICE = Hobby::SSO::EmailingServer::Service.new \
|
16
|
+
sessions: MockRedis.new,
|
17
|
+
tickets: MockRedis.new
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hobby-sso-emailing_server
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anatoly Chernow
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hobby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mail
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: email_address
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: slim
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- Gemfile
|
76
|
+
- Gemfile.lock
|
77
|
+
- hobby-sso-emailing_server.gemspec
|
78
|
+
- lib/hobby/sso/emailing_server.rb
|
79
|
+
- lib/hobby/sso/emailing_server/page_for_providing_email.slim
|
80
|
+
- lib/hobby/sso/emailing_server/service.rb
|
81
|
+
- lib/hobby/sso/emailing_server/services.rb
|
82
|
+
- spec/helper.rb
|
83
|
+
- spec/integration_spec.rb
|
84
|
+
- spec/test_authserver.rb
|
85
|
+
- spec/test_service.rb
|
86
|
+
homepage:
|
87
|
+
licenses: []
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.7.6
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: A hobby-sso server providing authentication links to emails.
|
109
|
+
test_files: []
|