toot-auth 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17d25f305c969c4a41cfb7ca6ae011a719860471
4
- data.tar.gz: b7d92c2e5780c56a2cff67d9b4125cdb75b3209a
3
+ metadata.gz: 5e5d7146d88e7de68319542d68ef33f8208ecebf
4
+ data.tar.gz: 2de6d5a9cb248cf3572f5205f69dc105ff9b7912
5
5
  SHA512:
6
- metadata.gz: f392f9098f9f91f00b3b1a148dc20045ab83d1f860b44e861eb5eb6773fffdcfc539367ce35dc0fe43b6b603b5871cb5493adff7c26de74cb5fdb716299f027b
7
- data.tar.gz: 1ecd1023e2591319b83033c2cc5216768b6d5de257317997d61555e8b3aca5562a42917b4ccf3258b08f9dc2ad3dae1192f08ccb3dc925f656a52ebbd4a92cd1
6
+ metadata.gz: 6a346ffbec227daf0e8e9bb2fd639dae0436884210389a3146ad044e6ab2d7bc1c73276ec015a47a32d4e70647bc69c0b7ba005b74c8909ea30f7522992ab09c
7
+ data.tar.gz: da8a85c9490e1c3f675830f75b6738d856232d1f525dc1b1988fe372c53878f8cb719bc5fa4b6c3daff626ab9706c4c8ed4a33fa966d5dd7f894f8d4216a67b1
data/Rakefile CHANGED
@@ -4,3 +4,10 @@ require "rspec/core/rake_task"
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  task :default => :spec
7
+
8
+ task :environment do
9
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
10
+ require 'toot/auth'
11
+ end
12
+
13
+ load './lib/tasks/toot-auth.rake'
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,9 @@
1
+ module Toot::Auth
2
+ class Credentials < Struct.new(:username, :password)
3
+
4
+ def hashed_password
5
+ OpenSSL::Digest::SHA256.digest(password)
6
+ end
7
+
8
+ end
9
+ 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
@@ -0,0 +1,14 @@
1
+ module Toot::Auth
2
+ class ListsCredentials
3
+
4
+ def call(store_key: Toot.config.auth_credentials_store_key)
5
+ Toot.redis do |r|
6
+ r.hkeys store_key
7
+ end
8
+ end
9
+
10
+ def self.call(*args)
11
+ new.call(*args)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ module Toot::Auth
2
+ class Rails < Rails::Railtie
3
+ rake_tasks do
4
+ Dir.glob(File.expand_path("../../../tasks/*.rake", __FILE__)).each do |rake_file|
5
+ load rake_file
6
+ end
7
+ end
8
+ end if defined?(Rails::Railtie)
9
+ end
@@ -0,0 +1,15 @@
1
+ module Toot::Auth
2
+ class RemovesCredentials
3
+
4
+ def call(store_key: Toot.config.auth_credentials_store_key, username:)
5
+ Toot.redis do |r|
6
+ r.hdel store_key, username
7
+ end
8
+ end
9
+
10
+ def self.call(*args)
11
+ new.call(*args)
12
+ end
13
+
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  module Toot
2
2
  module Auth
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
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.1.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-10-23 00:00:00.000000000 Z
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