toot-auth 0.1.0 → 0.2.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 +4 -4
- data/Rakefile +7 -0
- data/bin/rspec +16 -0
- data/lib/tasks/toot-auth.rake +29 -0
- data/lib/toot-auth.rb +1 -0
- data/lib/toot/auth.rb +32 -0
- data/lib/toot/auth/adds_credentials.rb +14 -0
- data/lib/toot/auth/checks_credentials.rb +19 -0
- data/lib/toot/auth/credentials.rb +9 -0
- data/lib/toot/auth/generates_credentials.rb +16 -0
- data/lib/toot/auth/lists_credentials.rb +14 -0
- data/lib/toot/auth/rails.rb +9 -0
- data/lib/toot/auth/removes_credentials.rb +15 -0
- data/lib/toot/auth/version.rb +1 -1
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e5d7146d88e7de68319542d68ef33f8208ecebf
|
4
|
+
data.tar.gz: 2de6d5a9cb248cf3572f5205f69dc105ff9b7912
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a346ffbec227daf0e8e9bb2fd639dae0436884210389a3146ad044e6ab2d7bc1c73276ec015a47a32d4e70647bc69c0b7ba005b74c8909ea30f7522992ab09c
|
7
|
+
data.tar.gz: da8a85c9490e1c3f675830f75b6738d856232d1f525dc1b1988fe372c53878f8cb719bc5fa4b6c3daff626ab9706c4c8ed4a33fa966d5dd7f894f8d4216a67b1
|
data/Rakefile
CHANGED
data/bin/rspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rspec' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rspec-core', 'rspec')
|
@@ -0,0 +1,29 @@
|
|
1
|
+
namespace :toot do
|
2
|
+
namespace :auth do
|
3
|
+
|
4
|
+
desc "Add the specified username and password to the credential store"
|
5
|
+
task :add, [:username, :password] => :environment do |t, args|
|
6
|
+
creds = Toot::Auth::Credentials.new(args[:username], args[:password])
|
7
|
+
Toot::Auth::AddsCredentials.(credentials: creds)
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Remove the specified username's credentials from the store"
|
11
|
+
task :remove, [:username] => :environment do |t, args|
|
12
|
+
Toot::Auth::RemovesCredentials.(username: args[:username])
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Generate a new username and password prefixing the username with name"
|
16
|
+
task :generate, [:name] => :environment do |t, args|
|
17
|
+
creds = Toot::Auth::GeneratesCredentials.(name: args[:name])
|
18
|
+
Toot::Auth::AddsCredentials.(credentials: creds)
|
19
|
+
puts "Username: #{creds.username}"
|
20
|
+
puts "Password: #{creds.password}"
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "List the usernames added to the credential store"
|
24
|
+
task :list => :environment do |t, args|
|
25
|
+
p Toot::Auth::ListsCredentials.()
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/toot-auth.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'toot/auth'
|
data/lib/toot/auth.rb
CHANGED
@@ -2,7 +2,39 @@ require "toot/auth/version"
|
|
2
2
|
|
3
3
|
require 'toot'
|
4
4
|
|
5
|
+
require 'toot/auth/credentials'
|
6
|
+
|
7
|
+
require 'toot/auth/adds_credentials'
|
8
|
+
require 'toot/auth/checks_credentials'
|
9
|
+
require 'toot/auth/generates_credentials'
|
10
|
+
require 'toot/auth/lists_credentials'
|
11
|
+
require 'toot/auth/removes_credentials'
|
12
|
+
|
13
|
+
|
5
14
|
module Toot
|
15
|
+
class Config
|
16
|
+
attr_accessor :auth_username, :auth_password, :auth_credentials_store_key
|
17
|
+
|
18
|
+
def auth_credentials_store_key
|
19
|
+
@auth_credentials_store_key ||= [channel_prefix, "toot.auth.credentials_store"].join
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
6
23
|
module Auth
|
24
|
+
|
25
|
+
def self.service_wrapper(app, store_key: Toot.config.auth_credentials_store_key)
|
26
|
+
Rack::Auth::Basic.new(app, "Toot Auth") do |username, password|
|
27
|
+
ChecksCredentials.(username: username, password: password, store_key: store_key)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.install_client_auth
|
32
|
+
Toot.config.http_connection.basic_auth(
|
33
|
+
Toot.config.auth_username,
|
34
|
+
Toot.config.auth_password
|
35
|
+
)
|
36
|
+
end
|
7
37
|
end
|
8
38
|
end
|
39
|
+
|
40
|
+
require 'toot/auth/rails' if defined?(Rails)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Toot::Auth
|
2
|
+
class AddsCredentials
|
3
|
+
|
4
|
+
def call(store_key: Toot.config.auth_credentials_store_key, credentials:)
|
5
|
+
Toot.redis do |r|
|
6
|
+
r.hset store_key, credentials.username, credentials.hashed_password
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.call(*args)
|
11
|
+
new.call(*args)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Toot::Auth
|
2
|
+
class ChecksCredentials
|
3
|
+
|
4
|
+
def call(store_key:, username:, password:)
|
5
|
+
return false if username.empty? || password.empty?
|
6
|
+
stored_password(store_key, username) ==
|
7
|
+
Credentials.new(username, password).hashed_password
|
8
|
+
end
|
9
|
+
|
10
|
+
private def stored_password(store_key, username)
|
11
|
+
Toot.redis { |r| r.hget(store_key, username) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.call(*args)
|
15
|
+
new.call(*args)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Toot::Auth
|
2
|
+
class GeneratesCredentials
|
3
|
+
|
4
|
+
GENERATES_USERNAME = -> (prefix) { prefix + SecureRandom.hex }
|
5
|
+
GENERATES_PASSWORD = -> { SecureRandom.hex }
|
6
|
+
|
7
|
+
def call(name: "")
|
8
|
+
Credentials.new GENERATES_USERNAME.(name), GENERATES_PASSWORD.()
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.call(*args)
|
12
|
+
new.call(*args)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
data/lib/toot/auth/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toot-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Petticrew
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: toot
|
@@ -80,8 +80,18 @@ files:
|
|
80
80
|
- README.md
|
81
81
|
- Rakefile
|
82
82
|
- bin/console
|
83
|
+
- bin/rspec
|
83
84
|
- bin/setup
|
85
|
+
- lib/tasks/toot-auth.rake
|
86
|
+
- lib/toot-auth.rb
|
84
87
|
- lib/toot/auth.rb
|
88
|
+
- lib/toot/auth/adds_credentials.rb
|
89
|
+
- lib/toot/auth/checks_credentials.rb
|
90
|
+
- lib/toot/auth/credentials.rb
|
91
|
+
- lib/toot/auth/generates_credentials.rb
|
92
|
+
- lib/toot/auth/lists_credentials.rb
|
93
|
+
- lib/toot/auth/rails.rb
|
94
|
+
- lib/toot/auth/removes_credentials.rb
|
85
95
|
- lib/toot/auth/version.rb
|
86
96
|
- toot-auth.gemspec
|
87
97
|
homepage: https://github.com/watermarkchurch/toot-auth
|