mais-access 1.1.1 → 1.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f88002e1195c7f1187c27fa7a244619fa3101a2ab91a650260dfcd9acb9d9912
4
- data.tar.gz: fdc4e863615ef1ff267d989a0bdd2696ffa2bdbd876695cf4a15b484c4949aaf
3
+ metadata.gz: bc9907ad2cf934f7a61fc086c1b92a75239a76d3f31dd460c27610a33507721f
4
+ data.tar.gz: 1ec26dfefef621b95ba1234e9f925905bd4231b358372e143e01720bc8215d46
5
5
  SHA512:
6
- metadata.gz: 59f48ae598a636cfcaa9b82acb728e70977d7dbd384cf85404d3d11179db9ec46b79ce0c479790e4c05e1e13dd12f98f1d3bcd54a4bfa04f53cd662528d69dd9
7
- data.tar.gz: e350a1b236ecefb20a7184d301c94c3be458c5ec4a8e1b81c986a17ef59257467c4fe89e324f1de48a5a699318073a0981800f4f8e6d33c90a1e9a58eb1df53c
6
+ metadata.gz: ccead31f66c557e86aa9e4d718159e1928d8f8785fb2221d44e9997c010a840fa418b3cac28a3f00915660eae173a284500a328c404028cbafe81e10b773aa45
7
+ data.tar.gz: 398360da3a38d578c41d0441d36f6f71ea0e6a0ca59b323d4bd97415d66fd17a5594b0683b36c5bf3cfbfb39b73f593d0ed6aedc90c3420c635cffeede4a6298
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MaisAccess
2
4
  class Railtie < ::Rails::Railtie
3
5
  initializer('mais.middleware') do |app|
@@ -1,44 +1,61 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MaisAccess
2
- module Dispatcher
3
- require 'net/https'
4
- require 'uri'
5
- require 'json'
6
- require 'mais-access/user'
7
-
8
- attr_reader :mais_user
9
-
10
- MAIS_CLIENT = ENV['MAIS_CLIENT']
11
-
12
- def authenticate_mais_user!
13
- # Prompt the user for HTTP Basic credentials, or authenticate if they are cached in the session
14
- authenticate_or_request_with_http_basic("access - MAIS - #{MAIS_CLIENT}") do |login, password|
15
- begin
16
- # Setup https connection and specify certificate bundle
17
- url = URI("#{ENV['MAIS_ACCOUNTS_HOSTNAME']}/authenticate")
18
- http = Net::HTTP.new(url.host, 443)
19
- http.use_ssl = true
20
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
21
- http.cert_store = OpenSSL::X509::Store.new
22
- http.cert_store.set_default_paths
23
- http.cert_store.add_file("/etc/pki/tls/certs/server.crt")
24
-
25
- # Get the credentials and POST them to `accounts.scenycwork.net/authenticate`
26
- request = Net::HTTP::Post.new(url.path, {'Content-Type' => 'application/json'})
27
- request.set_form_data({ "username" => login, "password" => password })
28
- response = http.request(request)
29
-
30
- # Parse the response body as JSON
31
- body = JSON.parse(response.body)
32
-
33
- # If the user is valid, set the current mais user and passes the filter action
34
- if response.code == '200' && body["authenticated"]
35
- @mais_user = MaisAccess::User.new(body["user"])
36
- return true
37
- end
38
- rescue => e
39
- # Something went wrong, so save our butts and don't them in.
40
- end
41
- end
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
@@ -1,16 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MaisAccess
4
- # An abstract class used to store the currently authenticated MAIS user. An instance of
5
- # this class is initialized everytime `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
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
- def initialize(*params)
11
- params = params[0]
12
- @username = params["username"]
13
- @full_name = params["full_name"]
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
@@ -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.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
- spec.add_development_dependency "rake", '~> 10.0'
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.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-02-18 00:00:00.000000000 Z
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
- rubyforge_project:
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.