monban-core 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.envrc +5 -0
- data/.git_release_request.rc.sh +7 -0
- data/.gitignore +9 -0
- data/.gitlab-ci.yml +12 -0
- data/.travis.yml +12 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +36 -0
- data/LICENSE +21 -0
- data/README.md +51 -0
- data/Rakefile +10 -0
- data/lib/monban/core/version.rb +5 -0
- data/lib/monban/domain/auth.rb +273 -0
- data/lib/monban/domain/password.rb +51 -0
- data/lib/monban/use_case/account/admin.rb +49 -0
- data/lib/monban/use_case/account/change/email.rb +60 -0
- data/lib/monban/use_case/account/change/login_id.rb +57 -0
- data/lib/monban/use_case/account/change/password.rb +45 -0
- data/lib/monban/use_case/account/change/roles.rb +51 -0
- data/lib/monban/use_case/account/fetch.rb +36 -0
- data/lib/monban/use_case/account/register.rb +50 -0
- data/lib/monban/use_case/account/search.rb +48 -0
- data/lib/monban/use_case/account/unregister.rb +39 -0
- data/lib/monban/use_case/auth/account.rb +43 -0
- data/lib/monban/use_case/auth/change/authy.rb +50 -0
- data/lib/monban/use_case/auth/change/password.rb +49 -0
- data/lib/monban/use_case/auth/token/authy.rb +51 -0
- data/lib/monban/use_case/auth/token/full.rb +51 -0
- data/lib/monban/use_case/auth/token/general.rb +33 -0
- data/lib/monban/use_case/auth/token/renew.rb +70 -0
- data/lib/monban/use_case/auth/token/reset.rb +99 -0
- data/lib/monban/use_case/auth/token.rb +39 -0
- data/lib/monban/use_case/auth/verify/authy.rb +43 -0
- data/lib/monban/use_case/auth/verify/password.rb +65 -0
- data/lib/monban/use_case/auth/verify/reset_token.rb +41 -0
- data/lib/monban/use_case/base.rb +15 -0
- data/monban-core.gemspec +39 -0
- metadata +184 -0
@@ -0,0 +1,99 @@
|
|
1
|
+
require "monban/use_case/base"
|
2
|
+
require "monban/use_case/auth/token"
|
3
|
+
|
4
|
+
require "getto/params"
|
5
|
+
|
6
|
+
module Monban
|
7
|
+
module UseCase
|
8
|
+
module Auth
|
9
|
+
module Token
|
10
|
+
class Reset < Base
|
11
|
+
include Token::Helper
|
12
|
+
|
13
|
+
initialize_with(
|
14
|
+
error: [:server_error!, :invalid_account!],
|
15
|
+
time: [:now],
|
16
|
+
logger: [:log],
|
17
|
+
token: [:create],
|
18
|
+
reset_token: [:create],
|
19
|
+
auth: [:reset],
|
20
|
+
mailer: [:send_mail],
|
21
|
+
|
22
|
+
expire: Integer,
|
23
|
+
|
24
|
+
repository: [
|
25
|
+
:transaction,
|
26
|
+
:account_id_by_email,
|
27
|
+
:public_id_exists?,
|
28
|
+
:insert_public_id,
|
29
|
+
:login_id,
|
30
|
+
:wipe_old_reset_password_token,
|
31
|
+
:reset_password_token_exists?,
|
32
|
+
:insert_reset_password_token,
|
33
|
+
],
|
34
|
+
)
|
35
|
+
|
36
|
+
def send_mail(params)
|
37
|
+
Getto::Params.new.validate(params) do |v|
|
38
|
+
v.hash(
|
39
|
+
email: v.combine([v.string, v.match(%r{@})]){|val| param_error!(email: val) },
|
40
|
+
)
|
41
|
+
end or param_error!(params: params)
|
42
|
+
|
43
|
+
account_id = repository.account_id_by_email(
|
44
|
+
email: params[:email],
|
45
|
+
) or error.invalid_account!
|
46
|
+
|
47
|
+
token = create(
|
48
|
+
account_id: account_id,
|
49
|
+
)
|
50
|
+
|
51
|
+
mailer.send_mail(
|
52
|
+
email: params[:email],
|
53
|
+
token: token,
|
54
|
+
)
|
55
|
+
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def create(account_id:)
|
62
|
+
repository.transaction do
|
63
|
+
repository.wipe_old_reset_password_token(now: time.now)
|
64
|
+
|
65
|
+
reset_token = generate_reset_token!(account_id: account_id)
|
66
|
+
|
67
|
+
auth.reset(
|
68
|
+
public_id: generate_public_id!(account_id: account_id),
|
69
|
+
reset_token: reset_token,
|
70
|
+
expired_at: time.now + expire,
|
71
|
+
)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def generate_reset_token!(account_id:)
|
76
|
+
i = 0
|
77
|
+
while i < 100 do
|
78
|
+
i += 1
|
79
|
+
|
80
|
+
token = reset_token.create
|
81
|
+
unless repository.reset_password_token_exists?(reset_token: token)
|
82
|
+
repository.insert_reset_password_token(
|
83
|
+
account_id: account_id,
|
84
|
+
reset_token: token,
|
85
|
+
created_at: time.now,
|
86
|
+
expired_at: time.now + expire,
|
87
|
+
)
|
88
|
+
return token
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
error.server_error! "failed generate reset_token"
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Monban
|
2
|
+
module UseCase
|
3
|
+
module Auth
|
4
|
+
module Token
|
5
|
+
module Helper
|
6
|
+
private
|
7
|
+
|
8
|
+
def generate_public_id!(account_id:)
|
9
|
+
i = 0
|
10
|
+
while i < 100 do
|
11
|
+
i += 1
|
12
|
+
|
13
|
+
public_id = token.create
|
14
|
+
unless repository.public_id_exists?(public_id: public_id)
|
15
|
+
repository.insert_public_id(
|
16
|
+
account_id: account_id,
|
17
|
+
public_id: public_id,
|
18
|
+
created_at: time.now,
|
19
|
+
expired_at: time.now + expire,
|
20
|
+
)
|
21
|
+
|
22
|
+
logger.log(generate_public_id: {
|
23
|
+
account_id: account_id,
|
24
|
+
public_id: public_id,
|
25
|
+
login_id: repository.login_id(account_id: account_id),
|
26
|
+
})
|
27
|
+
|
28
|
+
return public_id
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
error.server_error! "failed generate public_id"
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "monban/use_case/base"
|
2
|
+
|
3
|
+
require "getto/params"
|
4
|
+
|
5
|
+
module Monban
|
6
|
+
module UseCase
|
7
|
+
module Auth
|
8
|
+
module Verify
|
9
|
+
class Authy < Base
|
10
|
+
|
11
|
+
initialize_with(
|
12
|
+
error: [:invalid_params!, :invalid_account!],
|
13
|
+
authy: [:verify],
|
14
|
+
repository: [
|
15
|
+
:authy_id,
|
16
|
+
],
|
17
|
+
)
|
18
|
+
|
19
|
+
def verify(params)
|
20
|
+
Getto::Params.new.validate(params) do |v|
|
21
|
+
v.hash(
|
22
|
+
account_id: v.integer {|val| param_error!(account_id: val) },
|
23
|
+
authy_token: v.combine([v.string, v.not_empty]){|val| param_error!(authy_token: val) },
|
24
|
+
)
|
25
|
+
end or param_error!(params: params)
|
26
|
+
|
27
|
+
authy_id = repository.authy_id(
|
28
|
+
account_id: params[:account_id],
|
29
|
+
) or error.invalid_account! "account_id: #{params[:account_id]}"
|
30
|
+
|
31
|
+
authy.verify(
|
32
|
+
authy_id: authy_id,
|
33
|
+
authy_token: params[:authy_token],
|
34
|
+
) or error.invalid_account! "authy_token unmatched"
|
35
|
+
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "monban/use_case/base"
|
2
|
+
|
3
|
+
require "getto/params"
|
4
|
+
|
5
|
+
module Monban
|
6
|
+
module UseCase
|
7
|
+
module Auth
|
8
|
+
module Verify
|
9
|
+
class Password < Base
|
10
|
+
include Getto::InitializeWith
|
11
|
+
|
12
|
+
initialize_with(
|
13
|
+
error: [:invalid_params!, :invalid_account!, :invalid_login!],
|
14
|
+
repository: [
|
15
|
+
:account_id_by_login_id,
|
16
|
+
:password_salt,
|
17
|
+
:password_hash_match?,
|
18
|
+
],
|
19
|
+
|
20
|
+
password: [:hash_secret],
|
21
|
+
)
|
22
|
+
|
23
|
+
def verify(params)
|
24
|
+
Getto::Params.new.validate(params) do |v|
|
25
|
+
v.hash(
|
26
|
+
login_id: v.combine([v.string, v.not_empty]){|val| param_error!(login_id: val) },
|
27
|
+
password: v.combine([v.string, v.not_empty]){|val| param_error!(password: val) },
|
28
|
+
)
|
29
|
+
end or param_error!(params: params)
|
30
|
+
|
31
|
+
account_id = repository.account_id_by_login_id(
|
32
|
+
login_id: params[:login_id],
|
33
|
+
) or error.invalid_account! "login_id: #{params[:login_id]}"
|
34
|
+
|
35
|
+
password_match?(
|
36
|
+
account_id: account_id,
|
37
|
+
password: params[:password],
|
38
|
+
) or error.invalid_login! "password not matched"
|
39
|
+
|
40
|
+
account_id
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def password_match?(account_id:, password:)
|
46
|
+
unless salt = repository.password_salt(account_id: account_id)
|
47
|
+
error.invalid_login! "password not registered"
|
48
|
+
end
|
49
|
+
|
50
|
+
password_hash = self.password.hash_secret(
|
51
|
+
password: password,
|
52
|
+
salt: salt,
|
53
|
+
)
|
54
|
+
|
55
|
+
repository.password_hash_match?(
|
56
|
+
account_id: account_id,
|
57
|
+
password_hash: password_hash,
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "monban/use_case/base"
|
2
|
+
|
3
|
+
require "getto/params"
|
4
|
+
|
5
|
+
module Monban
|
6
|
+
module UseCase
|
7
|
+
module Auth
|
8
|
+
module Verify
|
9
|
+
class ResetToken < Base
|
10
|
+
include Getto::InitializeWith
|
11
|
+
|
12
|
+
initialize_with(
|
13
|
+
error: [:invalid_params!, :invalid_account!],
|
14
|
+
time: [:now],
|
15
|
+
repository: [
|
16
|
+
:valid_reset_password_token?,
|
17
|
+
],
|
18
|
+
)
|
19
|
+
|
20
|
+
def verify(params)
|
21
|
+
Getto::Params.new.validate(params) do |v|
|
22
|
+
v.hash(
|
23
|
+
account_id: v.integer {|val| param_error!(account_id: val) },
|
24
|
+
reset_token: v.combine([v.string, v.not_empty]){|val| param_error!(reset_token: val) },
|
25
|
+
)
|
26
|
+
end or param_error!(params: params)
|
27
|
+
|
28
|
+
repository.valid_reset_password_token?(
|
29
|
+
account_id: params[:account_id],
|
30
|
+
reset_token: params[:reset_token],
|
31
|
+
now: time.now
|
32
|
+
) or error.invalid_account! "reset_token failed: #{params}"
|
33
|
+
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/monban-core.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "monban/core/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.required_ruby_version = ">= 2.5.1"
|
7
|
+
|
8
|
+
spec.name = "monban-core"
|
9
|
+
spec.version = Monban::Core::VERSION
|
10
|
+
spec.authors = ["shun@getto.systems"]
|
11
|
+
spec.email = ["shun@getto.systems"]
|
12
|
+
|
13
|
+
spec.summary = %q{Monban - core}
|
14
|
+
spec.description = %q{Monban - The authentication plugin for web api based on jwt}
|
15
|
+
spec.homepage = "https://github.com/getto-systems/rubygems-monban-core"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
|
28
|
+
spec.extra_rdoc_files = ['README.md', 'LICENSE']
|
29
|
+
spec.rdoc_options = %w[--title Monban::Core --main README.md]
|
30
|
+
|
31
|
+
spec.add_runtime_dependency "getto-initialize_with", "~> 1.0"
|
32
|
+
spec.add_runtime_dependency "getto-params", "~> 1.0"
|
33
|
+
spec.add_runtime_dependency "jwt", "~> 2.1"
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
38
|
+
spec.add_development_dependency "simplecov", "~> 0.16"
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: monban-core
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- shun@getto.systems
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: getto-initialize_with
|
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: getto-params
|
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: jwt
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.16'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.16'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.16'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.16'
|
111
|
+
description: Monban - The authentication plugin for web api based on jwt
|
112
|
+
email:
|
113
|
+
- shun@getto.systems
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files:
|
117
|
+
- README.md
|
118
|
+
- LICENSE
|
119
|
+
files:
|
120
|
+
- ".envrc"
|
121
|
+
- ".git_release_request.rc.sh"
|
122
|
+
- ".gitignore"
|
123
|
+
- ".gitlab-ci.yml"
|
124
|
+
- ".travis.yml"
|
125
|
+
- Gemfile
|
126
|
+
- Gemfile.lock
|
127
|
+
- LICENSE
|
128
|
+
- README.md
|
129
|
+
- Rakefile
|
130
|
+
- lib/monban/core/version.rb
|
131
|
+
- lib/monban/domain/auth.rb
|
132
|
+
- lib/monban/domain/password.rb
|
133
|
+
- lib/monban/use_case/account/admin.rb
|
134
|
+
- lib/monban/use_case/account/change/email.rb
|
135
|
+
- lib/monban/use_case/account/change/login_id.rb
|
136
|
+
- lib/monban/use_case/account/change/password.rb
|
137
|
+
- lib/monban/use_case/account/change/roles.rb
|
138
|
+
- lib/monban/use_case/account/fetch.rb
|
139
|
+
- lib/monban/use_case/account/register.rb
|
140
|
+
- lib/monban/use_case/account/search.rb
|
141
|
+
- lib/monban/use_case/account/unregister.rb
|
142
|
+
- lib/monban/use_case/auth/account.rb
|
143
|
+
- lib/monban/use_case/auth/change/authy.rb
|
144
|
+
- lib/monban/use_case/auth/change/password.rb
|
145
|
+
- lib/monban/use_case/auth/token.rb
|
146
|
+
- lib/monban/use_case/auth/token/authy.rb
|
147
|
+
- lib/monban/use_case/auth/token/full.rb
|
148
|
+
- lib/monban/use_case/auth/token/general.rb
|
149
|
+
- lib/monban/use_case/auth/token/renew.rb
|
150
|
+
- lib/monban/use_case/auth/token/reset.rb
|
151
|
+
- lib/monban/use_case/auth/verify/authy.rb
|
152
|
+
- lib/monban/use_case/auth/verify/password.rb
|
153
|
+
- lib/monban/use_case/auth/verify/reset_token.rb
|
154
|
+
- lib/monban/use_case/base.rb
|
155
|
+
- monban-core.gemspec
|
156
|
+
homepage: https://github.com/getto-systems/rubygems-monban-core
|
157
|
+
licenses:
|
158
|
+
- MIT
|
159
|
+
metadata: {}
|
160
|
+
post_install_message:
|
161
|
+
rdoc_options:
|
162
|
+
- "--title"
|
163
|
+
- Monban::Core
|
164
|
+
- "--main"
|
165
|
+
- README.md
|
166
|
+
require_paths:
|
167
|
+
- lib
|
168
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: 2.5.1
|
173
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
requirements: []
|
179
|
+
rubyforge_project:
|
180
|
+
rubygems_version: 2.7.7
|
181
|
+
signing_key:
|
182
|
+
specification_version: 4
|
183
|
+
summary: Monban - core
|
184
|
+
test_files: []
|