authkick 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +119 -0
- data/Rakefile +1 -0
- data/authkick.gemspec +23 -0
- data/lib/authkick.rb +48 -0
- data/lib/authkick/version.rb +3 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a7b96602af86fa1c26220bf719218b9fe4637861
|
4
|
+
data.tar.gz: c4fbf675f3b319592a10db3568f4ed1e1717f3a9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9a1a0b1811fd76faa4136e68d2bc14b547ed960b4649db850fe12c176b4621af482cc4d448f442e4c0e0604ee92c423e8af9c04353aa24c8d1c7bae72fcc826a
|
7
|
+
data.tar.gz: 8ecdd06d8d4b11686a6c79a6407ab0b4a96b153411e087799b827e3348d4493e01c506f6656ce92addd78e1ad10eeb4856d2fc60b75a5b8632b8a6d1ea75d7d6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Andrew Kane
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# Authkick
|
2
|
+
|
3
|
+
Lightweight authentication for OmniAuth
|
4
|
+
|
5
|
+
:bangbang: Not ready for production use
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
Authkick provides four methods:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
sign_in(user)
|
13
|
+
sign_out
|
14
|
+
current_user
|
15
|
+
signed_in?
|
16
|
+
```
|
17
|
+
|
18
|
+
By default, users are remembered when returning for convenience.
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
sign_in(user, remember: 1.year) # default
|
22
|
+
sign_in(user, remember: false) # log out when browser is closed
|
23
|
+
```
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
First, select an OmniAuth strategy (or a few).
|
28
|
+
|
29
|
+
Add it to your Gemfile
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
gem "authkick"
|
33
|
+
gem "omniauth-google-apps"
|
34
|
+
```
|
35
|
+
|
36
|
+
and create an initializer.
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
# config/initializers/omniauth.rb
|
40
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
41
|
+
provider :google_apps
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
Add `uid` and `provider` fields - both strings - to your `User` model.
|
46
|
+
|
47
|
+
Next, create a `SessionsController` to manage the sign in and sign out actions.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
# app/controllers/sessions_controller.rb
|
51
|
+
class SessionsController < ApplicationController
|
52
|
+
# prevent CSRF warnings
|
53
|
+
skip_before_filter :verify_authenticity_token, only: [:create]
|
54
|
+
|
55
|
+
def create
|
56
|
+
auth = request.env["omniauth.auth"]
|
57
|
+
user = User.where(provider: auth["provider"], uid: auth["uid"])
|
58
|
+
.first_or_create!(name: auth["info"]["name"])
|
59
|
+
sign_in user
|
60
|
+
redirect_to root_path
|
61
|
+
end
|
62
|
+
|
63
|
+
def destroy
|
64
|
+
sign_out
|
65
|
+
redirect_to root_path
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
And hook up the routes
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
# config/routes.rb
|
75
|
+
post "/auth/:provider/callback" => "sessions#create"
|
76
|
+
get "sign_out", :controller => "sessions", action: "destroy"
|
77
|
+
```
|
78
|
+
|
79
|
+
You now have authentication without the magic.
|
80
|
+
|
81
|
+
To require authentication before an action, add:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
# app/controllers/application_controller.rb
|
85
|
+
def authenticate!
|
86
|
+
redirect_to "/auth/facebook" if !signed_in?
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
And do
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
before_action :authenticate!
|
94
|
+
```
|
95
|
+
|
96
|
+
## Important
|
97
|
+
|
98
|
+
Protect your users from [Firesheep](http://en.wikipedia.org/wiki/Firesheep) - use https. In Rails, use:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
# config/environments/production.rb
|
102
|
+
config.force_ssl = true
|
103
|
+
```
|
104
|
+
|
105
|
+
## Installation
|
106
|
+
|
107
|
+
Add this line to your application's Gemfile:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
gem "authkick"
|
111
|
+
```
|
112
|
+
|
113
|
+
## Contributing
|
114
|
+
|
115
|
+
1. Fork it
|
116
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
117
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
118
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
119
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/authkick.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'authkick/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "authkick"
|
8
|
+
spec.version = Authkick::VERSION
|
9
|
+
spec.authors = ["Andrew Kane"]
|
10
|
+
spec.email = ["acekane1@gmail.com"]
|
11
|
+
spec.description = %q{Lightweight authentication for OmniAuth}
|
12
|
+
spec.summary = %q{Lightweight authentication for OmniAuth}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/authkick.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require "authkick/version"
|
2
|
+
|
3
|
+
module Authkick
|
4
|
+
|
5
|
+
module ControllerMethods
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.helper_method :current_user
|
9
|
+
base.helper_method :signed_in?
|
10
|
+
end
|
11
|
+
|
12
|
+
def current_user
|
13
|
+
@current_user ||= begin
|
14
|
+
user = session[:user_id] ? User.find_by(id: session[:user_id]) : nil
|
15
|
+
if !user and cookies.encrypted[:user_id]
|
16
|
+
user = User.find_by(id: cookies.encrypted[:user_id])
|
17
|
+
if user
|
18
|
+
reset_session
|
19
|
+
session[:user_id] = user.id
|
20
|
+
end
|
21
|
+
end
|
22
|
+
user
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def signed_in?
|
27
|
+
!!current_user
|
28
|
+
end
|
29
|
+
|
30
|
+
def sign_in(user, opts = {})
|
31
|
+
remember = opts.has_key?(:remember) ? opts[:remember] : 1.year
|
32
|
+
reset_session
|
33
|
+
session[:user_id] = user.id
|
34
|
+
@current_user = user
|
35
|
+
cookies.encrypted[:user_id] = {value: "#{user.id}", expires: remember.from_now, httponly: true} if remember
|
36
|
+
end
|
37
|
+
|
38
|
+
def sign_out
|
39
|
+
@current_user = nil
|
40
|
+
reset_session
|
41
|
+
cookies.delete(:user_id)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
ActionController::Base.send(:include, Authkick::ControllerMethods) if defined?(ActionController::Base)
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: authkick
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Kane
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
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: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Lightweight authentication for OmniAuth
|
42
|
+
email:
|
43
|
+
- acekane1@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- authkick.gemspec
|
54
|
+
- lib/authkick.rb
|
55
|
+
- lib/authkick/version.rb
|
56
|
+
homepage: ''
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.0.0
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Lightweight authentication for OmniAuth
|
80
|
+
test_files: []
|