devise-access_token_authenticatable 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -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 devise-access_token_authenticatable.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Eric J. Holmes
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,26 @@
1
+ # Access Token Authenticatable
2
+
3
+ A devise module that provides something a little more full featured than token
4
+ authenticatable.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'devise-access_token_authenticatable'
11
+
12
+ ## Assumptions
13
+
14
+ You have an `AccessToken` model that responds to the following methods:
15
+
16
+ * `invalidate!`: Invalidates the token, making it unusable for authentication.
17
+ * `fresh?`: Whether or not the token can be used to authenticate the user.
18
+ * `used!`: Called whenever the token is used.
19
+
20
+ ## Contributing
21
+
22
+ 1. Fork it
23
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
24
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
25
+ 4. Push to the branch (`git push origin my-new-feature`)
26
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'devise/access_token_authenticatable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "devise-access_token_authenticatable"
8
+ spec.version = Devise::AccessTokenAuthenticatable::VERSION
9
+ spec.authors = ["Eric J. Holmes"]
10
+ spec.email = ["eric@ejholmes.net"]
11
+ spec.description = %q{Access tokens for devise}
12
+ spec.summary = %q{Access tokens for devise}
13
+ spec.homepage = "https://github.com/remind101/devise-access_token_authenticatable"
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_dependency "devise"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1 @@
1
+ require 'devise/access_token_authenticatable'
@@ -0,0 +1,9 @@
1
+ require 'devise'
2
+
3
+ require 'devise/access_token_authenticatable/version'
4
+ require 'devise/models/access_token_authenticatable'
5
+ require 'devise/strategies/access_token_authenticatable'
6
+
7
+ Devise.add_module :access_token_authenticatable,
8
+ controller: :sessions, route: { :session => [nil, :new, :destroy] },
9
+ no_input: true, model: true, strategy: true
@@ -0,0 +1,5 @@
1
+ module Devise
2
+ module AccessTokenAuthenticatable
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,39 @@
1
+ require 'devise/strategies/access_token_authenticatable'
2
+
3
+ module Devise
4
+ module Models
5
+ module AccessTokenAuthenticatable
6
+ extend ActiveSupport::Concern
7
+
8
+ def invalidate_authentication_token!
9
+ access_token.invalidate! if access_token
10
+ end
11
+
12
+ # TODO Remove this entirely. A user should be able to have many access
13
+ # tokens, that should expire after a period of time.
14
+ def reset_authentication_token!
15
+ invalidate_authentication_token!
16
+ self.access_token = access_tokens.create!
17
+ save(:validate => false)
18
+ end
19
+
20
+ def authentication_token
21
+ access_token.try(:token)
22
+ end
23
+
24
+ def after_token_authentication(token)
25
+ token.used!
26
+ end
27
+
28
+ module ClassMethods
29
+ def find_for_access_token_authentication(conditions)
30
+ # TODO Use to_adapter here.
31
+ token = AccessToken.where(token: conditions[token_authentication_key]).first
32
+ [token.user, token] if token.try(:fresh?)
33
+ end
34
+
35
+ Devise::Models.config(self, :token_authentication_key)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ require 'devise/strategies/token_authenticatable'
2
+
3
+ module Devise
4
+ module Strategies
5
+ class AccessTokenAuthenticatable < TokenAuthenticatable
6
+ def authenticate!
7
+ resource, token = mapping.to.find_for_access_token_authentication(authentication_hash)
8
+ return fail(:invalid_token) unless resource
9
+
10
+ if validate(resource)
11
+ resource.after_token_authentication(token)
12
+ success!(resource)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ Warden::Strategies.add(:access_token_authenticatable, Devise::Strategies::AccessTokenAuthenticatable)
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise-access_token_authenticatable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eric J. Holmes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: devise
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Access tokens for devise
63
+ email:
64
+ - eric@ejholmes.net
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - devise-access_token_authenticatable.gemspec
75
+ - lib/devise-access_token_authenticatable.rb
76
+ - lib/devise/access_token_authenticatable.rb
77
+ - lib/devise/access_token_authenticatable/version.rb
78
+ - lib/devise/models/access_token_authenticatable.rb
79
+ - lib/devise/strategies/access_token_authenticatable.rb
80
+ homepage: https://github.com/remind101/devise-access_token_authenticatable
81
+ licenses:
82
+ - MIT
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ segments:
94
+ - 0
95
+ hash: 2414664795423883497
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ segments:
103
+ - 0
104
+ hash: 2414664795423883497
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.23
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Access tokens for devise
111
+ test_files: []