autho 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 64d8261f16aff8e02776059ca384113560513276
4
+ data.tar.gz: 3c39c7304aac6f0a0c3cb600fdfddf94eecf79ea
5
+ SHA512:
6
+ metadata.gz: 2920a107ef64da00df797c450476a9f6d3c37ee79a5d9723b7fd1f66975bcb9ff383c8eacc50380e53a93d6a07a52f72f04a9146d792f3c680c2e402c92de1fb
7
+ data.tar.gz: a98f617e58fd0d4a27c535b33dd5d61e11169a24134779d38397d59cca4bdb437d1ac97b87a9b9a961d7f2fcb2f9642651e7060205340a35a46b8b9d81d0711b
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in autho.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Henrik Nyh
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ # Autho
2
+
3
+ **NOTE:** Very much a work in progress.
4
+
5
+ A many-stop-shop for authentication.
6
+
7
+ I've looked at various authentication gems and feel they do too much. I don't want a framework where I override some things. I want a helpful library to handle some things and leave me to bring it all together.
8
+
9
+ If you agree, Autho may be for you.
10
+
11
+ Autho is made to work well with Rails but not to be tied to it.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'autho'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install autho
26
+
27
+ ## Usage
28
+
29
+ Todo. See specs.
30
+
31
+ Current parts:
32
+
33
+ * `Autho::Authentication` to find a user from email and password.
34
+ * `Autho::Session` to store, get and remove user from the session.
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'autho/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "autho"
8
+ spec.version = Autho::VERSION
9
+ spec.authors = ["Henrik Nyh"]
10
+ spec.email = ["henrik@nyh.se"]
11
+ spec.summary = %q{A many-stop-shop for authentication.}
12
+ spec.homepage = "http://github.com/henrik/autho"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "attr_extras", ">=1.6.2"
21
+ spec.add_dependency "bcrypt-ruby"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,5 @@
1
+ require "autho/version"
2
+ require "autho/authentication"
3
+
4
+ module Autho
5
+ end
@@ -0,0 +1,24 @@
1
+ require "attr_extras"
2
+ require "bcrypt"
3
+
4
+ module Autho
5
+ class Authentication
6
+ pattr_initialize :finder, :email, :password
7
+
8
+ def user
9
+ user = finder.find_by_email(email)
10
+ user && authenticate(user, password)
11
+ end
12
+
13
+ private
14
+
15
+ def authenticate(user, unencrypted_password)
16
+ # This is BCcrypt being cryptic. It overrides "==" to compare hashes.
17
+ if BCrypt::Password.new(user.password_digest) == unencrypted_password
18
+ user
19
+ else
20
+ nil
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,30 @@
1
+ require "attr_extras"
2
+
3
+ module Autho
4
+ class Session
5
+ pattr_initialize :controller, :session_key, :finder
6
+
7
+ # NOTE: Not memoized yet.
8
+ def user
9
+ if id
10
+ finder.find(id)
11
+ else
12
+ nil
13
+ end
14
+ end
15
+
16
+ def user=(user)
17
+ controller.session[session_key] = user.id
18
+ end
19
+
20
+ def clear
21
+ controller.session[session_key] = nil
22
+ end
23
+
24
+ private
25
+
26
+ def id
27
+ controller.session[session_key]
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Autho
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+ require "autho/authentication"
3
+
4
+ describe Autho::Authentication do
5
+ describe "#user" do
6
+ let(:finder) { double }
7
+ let(:user) { double(password_digest: digest("sesame")) }
8
+
9
+ it "returns the user with matching email and password" do
10
+ expect(finder).to receive(:find_by_email).with("user@example.com").and_return(user)
11
+
12
+ auth = Autho::Authentication.new(finder, "user@example.com", "sesame")
13
+ expect(auth.user).to eq user
14
+ end
15
+
16
+ it "finds nothing if email does not match" do
17
+ expect(finder).to receive(:find_by_email).with("user@example.com").and_return(nil)
18
+
19
+ auth = Autho::Authentication.new(finder, "user@example.com", "sesame")
20
+ expect(auth.user).to be_nil
21
+ end
22
+
23
+ it "finds nothing if password does not match" do
24
+ expect(finder).to receive(:find_by_email).with("user@example.com").and_return(user)
25
+
26
+ auth = Autho::Authentication.new(finder, "user@example.com", "nomagic")
27
+ expect(auth.user).to be_nil
28
+ end
29
+ end
30
+
31
+ def digest(unencrypted_password)
32
+ BCrypt::Password.create(unencrypted_password)
33
+ end
34
+ end
@@ -0,0 +1,6 @@
1
+ require "spec_helper"
2
+ require "autho/session"
3
+
4
+ describe Autho::Session do
5
+ it "needs specs"
6
+ end
File without changes
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: autho
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Henrik Nyh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: attr_extras
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: bcrypt-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - henrik@nyh.se
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - autho.gemspec
96
+ - lib/autho.rb
97
+ - lib/autho/authentication.rb
98
+ - lib/autho/session.rb
99
+ - lib/autho/version.rb
100
+ - spec/authentication_spec.rb
101
+ - spec/session_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: http://github.com/henrik/autho
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.0.3
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: A many-stop-shop for authentication.
127
+ test_files:
128
+ - spec/authentication_spec.rb
129
+ - spec/session_spec.rb
130
+ - spec/spec_helper.rb
131
+ has_rdoc: