mais-access 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitattributes +2 -0
- data/.gitignore +2 -0
- data/Gemfile +4 -0
- data/README.md +11 -0
- data/lib/mais-access.rb +18 -0
- data/lib/mais-access/dispatcher.rb +33 -0
- data/lib/mais-access/user.rb +16 -0
- data/mais-access.gemspec +27 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8fd2f7a2d92c5596bcfdb2d2111be8fe2fc4459fabe3d6e115b7b47e8a074ec1
|
4
|
+
data.tar.gz: 5aaed8b2a843e12cf11c76b049d9cf7647f43e95fe4e7d38e08c876e27f6cf34
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '089bc20e78a520d9998191dfc2613634088d29650af93b624cc40da7eaf302671cd8ae0eb776b250deda471a2f39f4eaecd1545cd6dc8af0167521e4c3fbe09f'
|
7
|
+
data.tar.gz: ef599828d6c87e138e406407ac98cd96fee6c897978db6b875b88fa53849e07e7583c35595c76e56ffad7593b971ba78a2f2b1cf05ec26570184b051e1407f63
|
data/.gitattributes
ADDED
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# MAIS Access
|
2
|
+
|
3
|
+
A simple gem that enforces HTTP Basic Authentication for account holders in the MAIS business management and information system.
|
4
|
+
|
5
|
+
## License
|
6
|
+
|
7
|
+
Copyright � 2019 [Elias Gabriel](https://eliasfgabriel.com/), [sdbase](http://sdbase.com/)
|
8
|
+
|
9
|
+
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
|
10
|
+
|
11
|
+
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
|
data/lib/mais-access.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module MaisAccess
|
2
|
+
class Railtie < ::Rails::Railtie
|
3
|
+
initializer('mais.middleware') do |app|
|
4
|
+
# Hook into ActionController's loading process
|
5
|
+
ActiveSupport.on_load(:action_controller) do
|
6
|
+
require 'mais-access/dispatcher'
|
7
|
+
include MaisAccess::Dispatcher
|
8
|
+
|
9
|
+
# Mark the `mais_user` reader method (defined in Mais::Dispatcher) as a
|
10
|
+
# helper so that it can be accessed from a view
|
11
|
+
helper_method :mais_user
|
12
|
+
|
13
|
+
# Force a MAIS user authentication check on every request
|
14
|
+
before_action :authenticate_mais_user!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module MaisAccess
|
2
|
+
module Dispatcher
|
3
|
+
require 'net/http'
|
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
|
+
# Get the credentials and POST them to `accounts.scenycwork.net/authenticate`
|
17
|
+
response = Net::HTTP.post_form(URI("#{ENV['MAIS_ACCOUNTS_HOSTNAME']}/authenticate"), { "username" => login, "password" => password })
|
18
|
+
# Parse the JSON response
|
19
|
+
body = JSON.parse(response.body)
|
20
|
+
|
21
|
+
# If the user is valid, set the current mais user and passes the filter action
|
22
|
+
if response.code == '200' && body["authenticated"]
|
23
|
+
@mais_user = MaisAccess::User.new(body["user"])
|
24
|
+
return true
|
25
|
+
end
|
26
|
+
rescue => e
|
27
|
+
Rails.logger.info(e)
|
28
|
+
# Something went wrong, so save our butts and don't them in.
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
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
|
9
|
+
|
10
|
+
def initialize(*params)
|
11
|
+
params = params[0]
|
12
|
+
@username = params["username"]
|
13
|
+
@full_name = params["full_name"]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/mais-access.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "mais-access"
|
6
|
+
spec.version = "1.0.6"
|
7
|
+
spec.platform = Gem::Platform::RUBY
|
8
|
+
spec.author = "Elias Gabriel"
|
9
|
+
spec.email = "me@eliasfgabriel.com"
|
10
|
+
spec.summary = "A MAIS(tm) authentication middleware."
|
11
|
+
spec.description = "A simple gem that provides HTTP Basic Authentication for users registered with the MAIS(tm) accounts application."
|
12
|
+
spec.homepage = "https://github.com/sdbase/mais-access"
|
13
|
+
spec.license = "CC-BY-NC-SA-4.0"
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.metadata["source_code_uri"] = spec.homepage
|
16
|
+
spec.extra_rdoc_files = ["README.md"]
|
17
|
+
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0")
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.add_dependency "rails", '>= 4.0.2'
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", '~> 2.0'
|
26
|
+
spec.add_development_dependency "rake", '~> 10.0'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mais-access
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Elias Gabriel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: A simple gem that provides HTTP Basic Authentication for users registered
|
56
|
+
with the MAIS(tm) accounts application.
|
57
|
+
email: me@eliasfgabriel.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files:
|
61
|
+
- README.md
|
62
|
+
files:
|
63
|
+
- ".gitattributes"
|
64
|
+
- ".gitignore"
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- lib/mais-access.rb
|
68
|
+
- lib/mais-access/dispatcher.rb
|
69
|
+
- lib/mais-access/user.rb
|
70
|
+
- mais-access.gemspec
|
71
|
+
homepage: https://github.com/sdbase/mais-access
|
72
|
+
licenses:
|
73
|
+
- CC-BY-NC-SA-4.0
|
74
|
+
metadata:
|
75
|
+
source_code_uri: https://github.com/sdbase/mais-access
|
76
|
+
homepage_uri: https://github.com/sdbase/mais-access
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.7.6.2
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: A MAIS(tm) authentication middleware.
|
97
|
+
test_files: []
|