pansophy_authenticator 0.1.0
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 +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.rubocop.yml +11 -0
- data/.ruby-version +1 -0
- data/.travis.yml +11 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +107 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/pansophy_authenticator/application_keys.rb +45 -0
- data/lib/pansophy_authenticator/configuration/configurator.rb +26 -0
- data/lib/pansophy_authenticator/configuration/from_env.rb +37 -0
- data/lib/pansophy_authenticator/configuration/from_file.rb +70 -0
- data/lib/pansophy_authenticator/configuration/instance.rb +17 -0
- data/lib/pansophy_authenticator/configuration.rb +9 -0
- data/lib/pansophy_authenticator/local/application_keys.rb +44 -0
- data/lib/pansophy_authenticator/local.rb +6 -0
- data/lib/pansophy_authenticator/matcher.rb +21 -0
- data/lib/pansophy_authenticator/remote/application_keys.rb +23 -0
- data/lib/pansophy_authenticator/remote.rb +6 -0
- data/lib/pansophy_authenticator/version.rb +4 -0
- data/lib/pansophy_authenticator.rb +37 -0
- data/pansophy_authenticator.gemspec +42 -0
- metadata +241 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 5389e1b9e496f50d0e02ff349030429e5a05afc2
|
|
4
|
+
data.tar.gz: 51e58d9bd27a7b1870723408686ec61c0f248e4e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ba533aef72cc47c5c1cb4aae7d76e158f3d0a6eff8ece870ebed26b62a563fb5b3b6ffdc244ab4ab80e855898f21b515d546cd1ad28bdf3bdb16b7dd689c489e
|
|
7
|
+
data.tar.gz: 2616febd95f06d566a2a652f89eeed0644e2c8323167f6811ef39716423a779a58471067888be394fa9eccd5a30f5cd7e785ba262dc01c04f3312e8cf2961774
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.3.0
|
data/.travis.yml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
language: ruby
|
|
2
|
+
rvm:
|
|
3
|
+
- 2.1
|
|
4
|
+
- 2.2
|
|
5
|
+
- 2.3.0 # The version of RVM installed on Travis doesn't yet recognise 2.3 as an alias of 2.3.0
|
|
6
|
+
before_install: gem install bundler -v 1.11.2
|
|
7
|
+
notifications:
|
|
8
|
+
email:
|
|
9
|
+
- support@travellink.com.au
|
|
10
|
+
flowdock:
|
|
11
|
+
secure: X54gP0PjRDh289791y3jqYryuiWX6RNTNvxpzMVU0l3sw4JwxgjlfGG+VCYtje06D9rd3KJeostko1dqpP6RFiZCcOgd/zjsexP0JokD1e42hM2FTFCu7cMAn+VeWSN42NWTFp+8YIpcKbITiywkIREzHjXXW6jthh6aFEoMUD7u4qUy71iL2gGLlOwIL8IfUAljn1bDAr5w5yFSQvhywldG8QDvHavlH5YEXqNnMypxQT8EGtKtHA1xO6k3JyzVYeZJxmy+ZkmsgOcEAAWSecXpNtMDQIM6V789rML3S86CtyoK3ti7ndMdYx37ff112pmANr8TjFYRBD7Zjn1xfFFd90G8mFcOiYBMKTz1rds8j2UtxcirBxR9T8Hf4xn9LurCyqhKIIml0XAE3pRs3fa4HVzNOZElf8sMPDhWCFBW/BqKlt/e/HIsBBMxZWg6i+mWMJWptkiKWTTxBQYNtoX5pscCW1xxlIM55LUJrWM88vOCaMiM3UYaDIGo35c9cXQZRa86tdjDQhWbyPExpW8L87XGByro7KrN/pQqjPHEL7GVlwGlrRSzS5f8fdLdydAWOwgy0q3D9Rsydy4WPsuVBUM6MmTAD7w41UeyF0aa/Rt8IvG8hCnr2NLS62VHx3rjnLpL4Jrz2XRUgQM/zUmWD2hb8M8iVevUMeLZTms=
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Contributor Code of Conduct
|
|
2
|
+
|
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
|
7
|
+
|
|
8
|
+
We are committed to making participation in this project a harassment-free
|
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
|
12
|
+
|
|
13
|
+
Examples of unacceptable behavior by participants include:
|
|
14
|
+
|
|
15
|
+
* The use of sexualized language or imagery
|
|
16
|
+
* Personal attacks
|
|
17
|
+
* Trolling or insulting/derogatory comments
|
|
18
|
+
* Public or private harassment
|
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
|
20
|
+
addresses, without explicit permission
|
|
21
|
+
* Other unethical or unprofessional conduct
|
|
22
|
+
|
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
27
|
+
threatening, offensive, or harmful.
|
|
28
|
+
|
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
|
32
|
+
Conduct may be permanently removed from the project team.
|
|
33
|
+
|
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
|
35
|
+
when an individual is representing the project or its community.
|
|
36
|
+
|
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
38
|
+
reported by contacting a project maintainer at berardialessandro@gmail.com. All
|
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
|
42
|
+
incident.
|
|
43
|
+
|
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
45
|
+
version 1.3.0, available at
|
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
|
47
|
+
|
|
48
|
+
[homepage]: http://contributor-covenant.org
|
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 SeaLink
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# PansophyAuthenticator
|
|
2
|
+
|
|
3
|
+
[](http://badge.fury.io/rb/pansophy_authenticator)
|
|
4
|
+
[](https://travis-ci.org/sealink/pansophy_authenticator)
|
|
5
|
+
[](https://coveralls.io/github/sealink/pansophy_authenticator?branch=master)
|
|
6
|
+
[](https://gemnasium.com/sealink/pansophy_authenticator)
|
|
7
|
+
[](https://codeclimate.com/github/sealink/pansophy_authenticator)
|
|
8
|
+
|
|
9
|
+
Centralised application authentication via S3
|
|
10
|
+
|
|
11
|
+
By configuring a set of applications authentication keys in a file stored in an S3 bucket,
|
|
12
|
+
applications can authenticate with each other by submitting their authentication key,
|
|
13
|
+
which the receiver can match against the key stored in S3.
|
|
14
|
+
S3 becomes then a central authentication authority.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
Add this line to your application's Gemfile:
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
gem 'pansophy_authenticator'
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
And then execute:
|
|
25
|
+
|
|
26
|
+
$ bundle
|
|
27
|
+
|
|
28
|
+
Or install it yourself as:
|
|
29
|
+
|
|
30
|
+
$ gem install pansophy_authenticator
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
### Configuration
|
|
35
|
+
|
|
36
|
+
PansophyAuthenticator has three levels of configuration:
|
|
37
|
+
|
|
38
|
+
* Via environment variables
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
PANSOPHY_AUTHENTICATOR_LOCAL=false
|
|
42
|
+
PANSOPHY_AUTHENTICATOR_BUCKET_NAME=my_bucket
|
|
43
|
+
PANSOPHY_AUTHENTICATOR_FILE_PATH=config/app_keys.yml
|
|
44
|
+
PANSOPHY_AUTHENTICATOR_APPLICATION=my_app
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
* Via a configuration file
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
PansophyAuthenticator.configure do |configuration|
|
|
51
|
+
basedir = Pathname.new(__FILE__).expand_path.dirname.parent
|
|
52
|
+
configuration.configuration_path = basedir.join('config').join('authenticator.yml')
|
|
53
|
+
end
|
|
54
|
+
```
|
|
55
|
+
Note: If the file name is omitted, it will default to ``pansophy_authenticator.yml``
|
|
56
|
+
|
|
57
|
+
``authenticator.yml`` :
|
|
58
|
+
```yaml
|
|
59
|
+
---
|
|
60
|
+
bucket_name: 'my_bucket'
|
|
61
|
+
file_path: 'config/app_keys.yml'
|
|
62
|
+
application: 'my_app'
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
* Via the configurator
|
|
66
|
+
|
|
67
|
+
```ruby
|
|
68
|
+
PansophyAuthenticator.configure do |configuration|
|
|
69
|
+
configuration.local = false
|
|
70
|
+
configuration.bucket_name = 'my_bucket'
|
|
71
|
+
configuration.file_path = 'config/app_keys.yml'
|
|
72
|
+
configuration.application = 'my_app'
|
|
73
|
+
end
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Each level has precedence on the next, i.e. environment variables will have precedence over file based configuration, which, in turn, will have precedence over the configurator
|
|
77
|
+
|
|
78
|
+
The configuration options are:
|
|
79
|
+
|
|
80
|
+
* *local* true if the location of the application keys file is on the local host
|
|
81
|
+
* *bucket_name* the name of the bucket in S3 where the application keys file is kept
|
|
82
|
+
* *file_path* the remote or local path to the application keys file
|
|
83
|
+
* *application* the identifier of the current application in the application keys file
|
|
84
|
+
|
|
85
|
+
When working in remote mode (``local = false``), AWS access environment variables must be set, e.g.:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
|
|
89
|
+
AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
|
|
90
|
+
AWS_REGION=ap-southeast-2
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Development
|
|
94
|
+
|
|
95
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
96
|
+
|
|
97
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
98
|
+
|
|
99
|
+
## Contributing
|
|
100
|
+
|
|
101
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pansophy_authenticator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
107
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
require 'pansophy_authenticator'
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require 'irb'
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'singleton'
|
|
2
|
+
|
|
3
|
+
module PansophyAuthenticator
|
|
4
|
+
class ApplicationKeys
|
|
5
|
+
include Singleton
|
|
6
|
+
|
|
7
|
+
%i(own key valid? validate!).each do |method|
|
|
8
|
+
define_singleton_method(method) { |*args| instance.send(method, *args) }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def own
|
|
12
|
+
key(configuration.application)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def key(application)
|
|
16
|
+
matcher(application).key
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def valid?(application, key)
|
|
20
|
+
matcher(application).valid?(key)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def validate!(application, key)
|
|
24
|
+
matcher(application).validate!(key)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def matcher(application)
|
|
30
|
+
Matcher.new(retriever.instance.keys, application)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def retriever
|
|
34
|
+
if PansophyAuthenticator.remote?
|
|
35
|
+
Remote::ApplicationKeys
|
|
36
|
+
else
|
|
37
|
+
Local::ApplicationKeys
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def configuration
|
|
42
|
+
PansophyAuthenticator.configuration
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module PansophyAuthenticator
|
|
2
|
+
module Configuration
|
|
3
|
+
class Configurator
|
|
4
|
+
attr_accessor :local, :bucket_name, :file_path, :configuration_path, :application
|
|
5
|
+
|
|
6
|
+
def configuration
|
|
7
|
+
from_env
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
def base_config
|
|
13
|
+
return self if @configuration_path.nil?
|
|
14
|
+
from_file
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def from_file
|
|
18
|
+
FromFile.new(self).configuration
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def from_env
|
|
22
|
+
FromEnv.new(base_config).configuration
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module PansophyAuthenticator
|
|
2
|
+
module Configuration
|
|
3
|
+
class FromEnv
|
|
4
|
+
def initialize(base_configuration)
|
|
5
|
+
@base_configuration = base_configuration
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def configuration
|
|
9
|
+
Instance.new(
|
|
10
|
+
local: local,
|
|
11
|
+
bucket_name: bucket_name,
|
|
12
|
+
file_path: file_path,
|
|
13
|
+
application: application
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def local
|
|
20
|
+
local = ENV.fetch('PANSOPHY_AUTHENTICATOR_LOCAL') { @base_configuration.local }
|
|
21
|
+
local.to_s == 'true'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def bucket_name
|
|
25
|
+
ENV.fetch('PANSOPHY_AUTHENTICATOR_BUCKET_NAME') { @base_configuration.bucket_name }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def file_path
|
|
29
|
+
ENV.fetch('PANSOPHY_AUTHENTICATOR_FILE_PATH') { @base_configuration.file_path }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def application
|
|
33
|
+
ENV.fetch('PANSOPHY_AUTHENTICATOR_APPLICATION') { @base_configuration.application }
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'memoizable'
|
|
3
|
+
require 'yamload'
|
|
4
|
+
|
|
5
|
+
module PansophyAuthenticator
|
|
6
|
+
module Configuration
|
|
7
|
+
class FromFile
|
|
8
|
+
include Memoizable
|
|
9
|
+
|
|
10
|
+
DEFAULT_FILENAME = 'pansophy_authenticator'.freeze
|
|
11
|
+
|
|
12
|
+
def initialize(base_configuration)
|
|
13
|
+
@base_configuration = base_configuration
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def configuration
|
|
17
|
+
Instance.new(
|
|
18
|
+
local: local,
|
|
19
|
+
bucket_name: bucket_name,
|
|
20
|
+
file_path: file_path,
|
|
21
|
+
application: application
|
|
22
|
+
)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def local
|
|
28
|
+
content.fetch('local') { @base_configuration.local }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def bucket_name
|
|
32
|
+
content.fetch('bucket_name') { @base_configuration.bucket_name }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def file_path
|
|
36
|
+
content.fetch('file_path') { @base_configuration.file_path }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def application
|
|
40
|
+
content.fetch('application') { @base_configuration.application }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def pathname
|
|
44
|
+
Pathname.new(@base_configuration.configuration_path)
|
|
45
|
+
end
|
|
46
|
+
memoize :pathname
|
|
47
|
+
|
|
48
|
+
def dirname
|
|
49
|
+
return pathname if pathname.directory?
|
|
50
|
+
pathname.dirname
|
|
51
|
+
end
|
|
52
|
+
memoize :dirname
|
|
53
|
+
|
|
54
|
+
def filename
|
|
55
|
+
return Pathname.new(DEFAULT_FILENAME) if pathname.directory?
|
|
56
|
+
pathname.basename('.yml')
|
|
57
|
+
end
|
|
58
|
+
memoize :filename
|
|
59
|
+
|
|
60
|
+
def content
|
|
61
|
+
loader.content
|
|
62
|
+
end
|
|
63
|
+
memoize :content
|
|
64
|
+
|
|
65
|
+
def loader
|
|
66
|
+
Yamload::Loader.new(filename, dirname)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module PansophyAuthenticator
|
|
2
|
+
module Configuration
|
|
3
|
+
end
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
require 'pansophy_authenticator/configuration/configurator'
|
|
7
|
+
require 'pansophy_authenticator/configuration/from_file'
|
|
8
|
+
require 'pansophy_authenticator/configuration/from_env'
|
|
9
|
+
require 'pansophy_authenticator/configuration/instance'
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'singleton'
|
|
2
|
+
require 'memoizable'
|
|
3
|
+
require 'yamload'
|
|
4
|
+
|
|
5
|
+
module PansophyAuthenticator
|
|
6
|
+
module Local
|
|
7
|
+
class ApplicationKeys
|
|
8
|
+
include Singleton
|
|
9
|
+
include Memoizable
|
|
10
|
+
|
|
11
|
+
def keys
|
|
12
|
+
content
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def pathname
|
|
18
|
+
Pathname.new(configuration.file_path)
|
|
19
|
+
end
|
|
20
|
+
memoize :pathname
|
|
21
|
+
|
|
22
|
+
def dirname
|
|
23
|
+
pathname.dirname
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def filename
|
|
27
|
+
pathname.basename('.yml')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def content
|
|
31
|
+
loader.content
|
|
32
|
+
end
|
|
33
|
+
memoize :content
|
|
34
|
+
|
|
35
|
+
def loader
|
|
36
|
+
Yamload::Loader.new(filename, dirname)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def configuration
|
|
40
|
+
PansophyAuthenticator.configuration
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module PansophyAuthenticator
|
|
2
|
+
class Matcher
|
|
3
|
+
def initialize(keys, application)
|
|
4
|
+
@keys = keys
|
|
5
|
+
@application = application
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def validate!(given_key)
|
|
9
|
+
fail Error, "Invalid key for #{@application}" unless valid?(given_key)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def valid?(given_key)
|
|
13
|
+
given_key == key
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def key
|
|
17
|
+
fail Error, "#{@application} is not defined" unless @keys.key?(@application)
|
|
18
|
+
@keys.fetch(@application)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'singleton'
|
|
2
|
+
require 'memoizable'
|
|
3
|
+
require 'pansophy'
|
|
4
|
+
|
|
5
|
+
module PansophyAuthenticator
|
|
6
|
+
module Remote
|
|
7
|
+
class ApplicationKeys
|
|
8
|
+
include Singleton
|
|
9
|
+
include Memoizable
|
|
10
|
+
|
|
11
|
+
def keys
|
|
12
|
+
Pansophy.read(configuration.bucket_name, configuration.file_path)
|
|
13
|
+
end
|
|
14
|
+
memoize :keys
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def configuration
|
|
19
|
+
PansophyAuthenticator.configuration
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'pansophy_authenticator/version'
|
|
2
|
+
|
|
3
|
+
module PansophyAuthenticator
|
|
4
|
+
def self.configure
|
|
5
|
+
configurator = Configuration::Configurator.new
|
|
6
|
+
yield configurator if block_given?
|
|
7
|
+
@configuration = configurator.configuration
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.configuration
|
|
11
|
+
@configuration ||= configure
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.remote?
|
|
15
|
+
configuration.remote?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.own_key
|
|
19
|
+
ApplicationKeys.own
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.authenticate!(application, key)
|
|
23
|
+
ApplicationKeys.validate!(application, key)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
%i(key valid?).each do |method|
|
|
27
|
+
define_singleton_method(method) { |*args| ApplicationKeys.send(method, *args) }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
Error = Class.new(StandardError)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
require 'pansophy_authenticator/configuration'
|
|
34
|
+
require 'pansophy_authenticator/application_keys'
|
|
35
|
+
require 'pansophy_authenticator/matcher'
|
|
36
|
+
require 'pansophy_authenticator/local'
|
|
37
|
+
require 'pansophy_authenticator/remote'
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'pansophy_authenticator/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'pansophy_authenticator'
|
|
8
|
+
spec.version = PansophyAuthenticator::VERSION
|
|
9
|
+
spec.authors = ['Alessandro Berardi']
|
|
10
|
+
spec.email = ['berardialessandro@gmail.com']
|
|
11
|
+
|
|
12
|
+
spec.summary = 'Inter application authentication via central authority'
|
|
13
|
+
spec.description = 'By configuring a set of applications authentication keys in a file'\
|
|
14
|
+
'stored in an S3 bucket, applications can authenticate with each other'\
|
|
15
|
+
'by submitting their authentication key, which the receiver can match'\
|
|
16
|
+
'against the key stored in S3.'\
|
|
17
|
+
'S3 becomes then a central authentication authority.'
|
|
18
|
+
spec.homepage = 'https://github.com/sealink/pansophy_authenticator'
|
|
19
|
+
spec.license = 'MIT'
|
|
20
|
+
|
|
21
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
22
|
+
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
23
|
+
spec.bindir = 'exe'
|
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
25
|
+
spec.require_paths = ['lib']
|
|
26
|
+
|
|
27
|
+
spec.required_ruby_version = '>= 2.1'
|
|
28
|
+
|
|
29
|
+
spec.add_dependency 'memoize', '~> 1.3'
|
|
30
|
+
spec.add_dependency 'anima', '~> 0.3'
|
|
31
|
+
spec.add_dependency 'pansophy', '~> 0.2.6'
|
|
32
|
+
spec.add_dependency 'yamload', '~> 0.2.1'
|
|
33
|
+
|
|
34
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
|
35
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
36
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
37
|
+
spec.add_development_dependency 'simplecov'
|
|
38
|
+
spec.add_development_dependency 'simplecov-rcov'
|
|
39
|
+
spec.add_development_dependency 'coveralls'
|
|
40
|
+
spec.add_development_dependency 'rubocop'
|
|
41
|
+
spec.add_development_dependency 'travis'
|
|
42
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: pansophy_authenticator
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Alessandro Berardi
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-02-01 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: memoize
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.3'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.3'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: anima
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0.3'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0.3'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: pansophy
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 0.2.6
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 0.2.6
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: yamload
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 0.2.1
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 0.2.1
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: bundler
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '1.11'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '1.11'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rake
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '10.0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '10.0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: rspec
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '3.0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '3.0'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: simplecov
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
125
|
+
- !ruby/object:Gem::Dependency
|
|
126
|
+
name: simplecov-rcov
|
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - ">="
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '0'
|
|
132
|
+
type: :development
|
|
133
|
+
prerelease: false
|
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - ">="
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '0'
|
|
139
|
+
- !ruby/object:Gem::Dependency
|
|
140
|
+
name: coveralls
|
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
|
142
|
+
requirements:
|
|
143
|
+
- - ">="
|
|
144
|
+
- !ruby/object:Gem::Version
|
|
145
|
+
version: '0'
|
|
146
|
+
type: :development
|
|
147
|
+
prerelease: false
|
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - ">="
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: '0'
|
|
153
|
+
- !ruby/object:Gem::Dependency
|
|
154
|
+
name: rubocop
|
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - ">="
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: '0'
|
|
160
|
+
type: :development
|
|
161
|
+
prerelease: false
|
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
163
|
+
requirements:
|
|
164
|
+
- - ">="
|
|
165
|
+
- !ruby/object:Gem::Version
|
|
166
|
+
version: '0'
|
|
167
|
+
- !ruby/object:Gem::Dependency
|
|
168
|
+
name: travis
|
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
|
170
|
+
requirements:
|
|
171
|
+
- - ">="
|
|
172
|
+
- !ruby/object:Gem::Version
|
|
173
|
+
version: '0'
|
|
174
|
+
type: :development
|
|
175
|
+
prerelease: false
|
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
177
|
+
requirements:
|
|
178
|
+
- - ">="
|
|
179
|
+
- !ruby/object:Gem::Version
|
|
180
|
+
version: '0'
|
|
181
|
+
description: By configuring a set of applications authentication keys in a filestored
|
|
182
|
+
in an S3 bucket, applications can authenticate with each otherby submitting their
|
|
183
|
+
authentication key, which the receiver can matchagainst the key stored in S3.S3
|
|
184
|
+
becomes then a central authentication authority.
|
|
185
|
+
email:
|
|
186
|
+
- berardialessandro@gmail.com
|
|
187
|
+
executables: []
|
|
188
|
+
extensions: []
|
|
189
|
+
extra_rdoc_files: []
|
|
190
|
+
files:
|
|
191
|
+
- ".gitignore"
|
|
192
|
+
- ".rspec"
|
|
193
|
+
- ".rubocop.yml"
|
|
194
|
+
- ".ruby-version"
|
|
195
|
+
- ".travis.yml"
|
|
196
|
+
- CODE_OF_CONDUCT.md
|
|
197
|
+
- Gemfile
|
|
198
|
+
- LICENSE
|
|
199
|
+
- README.md
|
|
200
|
+
- Rakefile
|
|
201
|
+
- bin/console
|
|
202
|
+
- bin/setup
|
|
203
|
+
- lib/pansophy_authenticator.rb
|
|
204
|
+
- lib/pansophy_authenticator/application_keys.rb
|
|
205
|
+
- lib/pansophy_authenticator/configuration.rb
|
|
206
|
+
- lib/pansophy_authenticator/configuration/configurator.rb
|
|
207
|
+
- lib/pansophy_authenticator/configuration/from_env.rb
|
|
208
|
+
- lib/pansophy_authenticator/configuration/from_file.rb
|
|
209
|
+
- lib/pansophy_authenticator/configuration/instance.rb
|
|
210
|
+
- lib/pansophy_authenticator/local.rb
|
|
211
|
+
- lib/pansophy_authenticator/local/application_keys.rb
|
|
212
|
+
- lib/pansophy_authenticator/matcher.rb
|
|
213
|
+
- lib/pansophy_authenticator/remote.rb
|
|
214
|
+
- lib/pansophy_authenticator/remote/application_keys.rb
|
|
215
|
+
- lib/pansophy_authenticator/version.rb
|
|
216
|
+
- pansophy_authenticator.gemspec
|
|
217
|
+
homepage: https://github.com/sealink/pansophy_authenticator
|
|
218
|
+
licenses:
|
|
219
|
+
- MIT
|
|
220
|
+
metadata: {}
|
|
221
|
+
post_install_message:
|
|
222
|
+
rdoc_options: []
|
|
223
|
+
require_paths:
|
|
224
|
+
- lib
|
|
225
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
226
|
+
requirements:
|
|
227
|
+
- - ">="
|
|
228
|
+
- !ruby/object:Gem::Version
|
|
229
|
+
version: '2.1'
|
|
230
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
231
|
+
requirements:
|
|
232
|
+
- - ">="
|
|
233
|
+
- !ruby/object:Gem::Version
|
|
234
|
+
version: '0'
|
|
235
|
+
requirements: []
|
|
236
|
+
rubyforge_project:
|
|
237
|
+
rubygems_version: 2.5.1
|
|
238
|
+
signing_key:
|
|
239
|
+
specification_version: 4
|
|
240
|
+
summary: Inter application authentication via central authority
|
|
241
|
+
test_files: []
|