mais-access 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mais-access.rb +2 -0
- data/lib/mais-access/dispatcher.rb +57 -40
- data/lib/mais-access/user.rb +10 -10
- data/mais-access.gemspec +4 -3
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc9907ad2cf934f7a61fc086c1b92a75239a76d3f31dd460c27610a33507721f
|
4
|
+
data.tar.gz: 1ec26dfefef621b95ba1234e9f925905bd4231b358372e143e01720bc8215d46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccead31f66c557e86aa9e4d718159e1928d8f8785fb2221d44e9997c010a840fa418b3cac28a3f00915660eae173a284500a328c404028cbafe81e10b773aa45
|
7
|
+
data.tar.gz: 398360da3a38d578c41d0441d36f6f71ea0e6a0ca59b323d4bd97415d66fd17a5594b0683b36c5bf3cfbfb39b73f593d0ed6aedc90c3420c635cffeede4a6298
|
data/lib/mais-access.rb
CHANGED
@@ -1,44 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module MaisAccess
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
4
|
+
module Dispatcher
|
5
|
+
require 'net/https'
|
6
|
+
require 'uri'
|
7
|
+
require 'json'
|
8
|
+
require 'mais-access/user'
|
9
|
+
|
10
|
+
attr_reader :mais_user
|
11
|
+
|
12
|
+
MAIS_CLIENT = ENV['MAIS_CLIENT']
|
13
|
+
APP_TITLE = "access - MAIS - #{MAIS_CLIENT}"
|
14
|
+
|
15
|
+
def authenticate_mais_user!
|
16
|
+
# Prompt the user for HTTP Basic credentials or authenticate if they are
|
17
|
+
# cached in the browser session
|
18
|
+
authenticate_or_request_with_http_basic(APP_TITLE) { |l, p| user?(l, p) }
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def user?(login, password)
|
24
|
+
begin
|
25
|
+
url = URI("#{ENV['MAIS_ACCOUNTS_HOSTNAME']}/authenticate")
|
26
|
+
|
27
|
+
# Setup https connection and specify certificate bundle if enabled
|
28
|
+
if (ENV.fetch("USE_HTTPS") { false })
|
29
|
+
http = Net::HTTP.new(url.host, 443)
|
30
|
+
http.use_ssl = true
|
31
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
32
|
+
http.cert_store = OpenSSL::X509::Store.new
|
33
|
+
http.cert_store.set_default_paths
|
34
|
+
http.cert_store.add_file("/etc/pki/tls/certs/server.crt")
|
35
|
+
else
|
36
|
+
http = Net::HTTP.new(url.host, url.port)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Get the credentials and POST them to `accounts.scenycwork.net/authenticate`
|
40
|
+
request = Net::HTTP::Post.new(url.path, {'Content-Type' => 'application/json'})
|
41
|
+
request.set_form_data({ "username" => login, "password" => password })
|
42
|
+
response = http.request(request)
|
43
|
+
|
44
|
+
# Parse the response body as JSON
|
45
|
+
body = JSON.parse(response.body)
|
46
|
+
|
47
|
+
# If the user is valid, set the current mais user
|
48
|
+
if response.code == '200' && body["authenticated"]
|
49
|
+
@mais_user = MaisAccess::User.new(body["user"])
|
50
|
+
# let them in
|
51
|
+
return true
|
42
52
|
end
|
53
|
+
rescue => e
|
54
|
+
Rails.logger.error(e)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Something went wrong, so save our butts and don't them in.
|
58
|
+
return false
|
43
59
|
end
|
60
|
+
end
|
44
61
|
end
|
data/lib/mais-access/user.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module MaisAccess
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
# An abstract class used to store the currently authenticated MAIS user. An instance of
|
5
|
+
# this class is initialized every time `authenticate_mais_user!` completes successfully.
|
6
|
+
# The current MAIS user can be accessed anytime via the `mais_user` method.
|
7
|
+
class User
|
8
|
+
attr_reader :username, :full_name
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
10
|
+
def initialize(*params)
|
11
|
+
params = params[0]
|
12
|
+
@username = params["username"]
|
13
|
+
@full_name = params["full_name"]
|
15
14
|
end
|
15
|
+
end
|
16
16
|
end
|
data/mais-access.gemspec
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path("lib", __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
|
4
6
|
Gem::Specification.new do |spec|
|
5
7
|
spec.name = "mais-access"
|
6
|
-
spec.version = "1.1.
|
7
|
-
spec.platform = Gem::Platform::RUBY
|
8
|
+
spec.version = "1.1.2"
|
8
9
|
spec.author = "Elias Gabriel"
|
9
10
|
spec.email = "me@eliasfgabriel.com"
|
10
11
|
spec.summary = "A MAIS(tm) authentication middleware."
|
@@ -23,5 +24,5 @@ Gem::Specification.new do |spec|
|
|
23
24
|
spec.add_dependency "rails", '>= 4.0.2'
|
24
25
|
|
25
26
|
spec.add_development_dependency "bundler", '~> 2.0'
|
26
|
-
|
27
|
+
spec.add_development_dependency "rake", '~> 10.0'
|
27
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mais-access
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elias Gabriel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -89,8 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '0'
|
91
91
|
requirements: []
|
92
|
-
|
93
|
-
rubygems_version: 2.7.6.2
|
92
|
+
rubygems_version: 3.1.3
|
94
93
|
signing_key:
|
95
94
|
specification_version: 4
|
96
95
|
summary: A MAIS(tm) authentication middleware.
|