cow_auth 0.5.2 → 0.7.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
  SHA256:
3
- metadata.gz: 0b61a286553d8f86105a6f285edea7f2cdb2834be2083dc6c4cb84cbbec44912
4
- data.tar.gz: fe7353598f52d7249a77877772bf41257ffa350c6ea1b78ec3a75b50054dbaf4
3
+ metadata.gz: c0e869b68884793590a26fb92fa2071936551cd02d12c711ad6c26442ed40004
4
+ data.tar.gz: a6460389351e4f70e079b63c8c0f946415579213a14c2ad2a0895e6602c84afa
5
5
  SHA512:
6
- metadata.gz: 2783eea610cc94b85cbbf10b54ae242be3b7828617daf48aa04372ffcffdfcb9cd15ab7a30c7cefc7dace3148d5789d74870424ae0b25f577a344b57f1e9203b
7
- data.tar.gz: 5e6baa8f5838abc4cbd4518dbc2ce73d50f771c6e04daf99a3b5a3d8d95455b359c642c0fcbc2d0e850b882cccf70c5728cb00da9ddf7af48bd0f0ed4976b057
6
+ metadata.gz: 5d8324716f594328482fea1dcf04d7330d4ff20ecf325eb7e51b68e399598975e1294901cfae4b221adc7e679d101368da355d6d56620540da032cdb81b4c1ca
7
+ data.tar.gz: 834d84c38351ea0a066beed3fbff1723542996f81a10d305c6c69295a23c33af38ef86bf17869b7b351e93ecd6f8f9196417b8fd5a480867e2248445ed91c9ec
data/.gitignore CHANGED
@@ -6,4 +6,3 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
- *.gem
@@ -1,5 +1,6 @@
1
- sudo: false
1
+ ---
2
2
  language: ruby
3
+ cache: bundler
3
4
  rvm:
4
- - 2.5.0
5
- before_install: gem install bundler -v 1.16.1.pre1
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
55
55
  ## Enforcement
56
56
 
57
57
  Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at mickey@vt.edu. All
58
+ reported by contacting the project team at mickey@cowden.tech. All
59
59
  complaints will be reviewed and investigated and will result in a response that
60
60
  is deemed necessary and appropriate to the circumstances. The project team is
61
61
  obligated to maintain confidentiality with regard to the reporter of an incident.
@@ -68,7 +68,7 @@ members of the project's leadership.
68
68
  ## Attribution
69
69
 
70
70
  This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
72
 
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
-
5
3
  # Specify your gem's dependencies in cow_auth.gemspec
6
4
  gemspec
5
+
6
+ gem 'rake', '~> 12.0'
7
+ gem 'minitest', '~> 5.0'
@@ -1,72 +1,47 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cow_auth (0.5.2)
5
- actionpack (~> 5.1)
6
- activesupport (~> 5.1)
4
+ cow_auth (0.7.0)
5
+ activerecord (~> 6.0)
7
6
  scrypt (~> 3.0)
8
7
 
9
8
  GEM
10
9
  remote: https://rubygems.org/
11
10
  specs:
12
- actionpack (5.1.4)
13
- actionview (= 5.1.4)
14
- activesupport (= 5.1.4)
15
- rack (~> 2.0)
16
- rack-test (>= 0.6.3)
17
- rails-dom-testing (~> 2.0)
18
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
19
- actionview (5.1.4)
20
- activesupport (= 5.1.4)
21
- builder (~> 3.1)
22
- erubi (~> 1.4)
23
- rails-dom-testing (~> 2.0)
24
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
25
- activesupport (5.1.4)
11
+ activemodel (6.0.3.2)
12
+ activesupport (= 6.0.3.2)
13
+ activerecord (6.0.3.2)
14
+ activemodel (= 6.0.3.2)
15
+ activesupport (= 6.0.3.2)
16
+ activesupport (6.0.3.2)
26
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
27
- i18n (~> 0.7)
18
+ i18n (>= 0.7, < 2)
28
19
  minitest (~> 5.1)
29
20
  tzinfo (~> 1.1)
30
- builder (3.2.3)
31
- concurrent-ruby (1.0.5)
32
- crass (1.0.3)
33
- erubi (1.7.0)
34
- ffi (1.9.18)
21
+ zeitwerk (~> 2.2, >= 2.2.2)
22
+ concurrent-ruby (1.1.6)
23
+ ffi (1.13.1)
35
24
  ffi-compiler (1.0.1)
36
25
  ffi (>= 1.0.0)
37
26
  rake
38
- i18n (0.9.1)
27
+ i18n (1.8.5)
39
28
  concurrent-ruby (~> 1.0)
40
- loofah (2.1.1)
41
- crass (~> 1.0.2)
42
- nokogiri (>= 1.5.9)
43
- mini_portile2 (2.3.0)
44
- minitest (5.11.1)
45
- nokogiri (1.8.1)
46
- mini_portile2 (~> 2.3.0)
47
- rack (2.0.3)
48
- rack-test (0.8.2)
49
- rack (>= 1.0, < 3)
50
- rails-dom-testing (2.0.3)
51
- activesupport (>= 4.2.0)
52
- nokogiri (>= 1.6)
53
- rails-html-sanitizer (1.0.3)
54
- loofah (~> 2.0)
55
- rake (12.3.0)
56
- scrypt (3.0.5)
29
+ minitest (5.14.1)
30
+ rake (12.3.3)
31
+ scrypt (3.0.7)
57
32
  ffi-compiler (>= 1.0, < 2.0)
58
33
  thread_safe (0.3.6)
59
- tzinfo (1.2.4)
34
+ tzinfo (1.2.7)
60
35
  thread_safe (~> 0.1)
36
+ zeitwerk (2.4.0)
61
37
 
62
38
  PLATFORMS
63
39
  ruby
64
40
 
65
41
  DEPENDENCIES
66
- bundler (~> 1.16)
67
42
  cow_auth!
68
- minitest (~> 5.11)
69
- rake (~> 12.3)
43
+ minitest (~> 5.0)
44
+ rake (~> 12.0)
70
45
 
71
46
  BUNDLED WITH
72
- 1.16.1
47
+ 2.1.4
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017 Mickey Cowden
3
+ Copyright (c) 2020 Mickey Cowden
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # CowAuth
2
2
 
3
- The main goal of this gem is to provide token-based authentication for Rails (or Rails-like) web applications.
3
+ The goal of this gem is to provide token-based authentication for Rails (or Rails-like) web applications.
4
4
 
5
5
  ## Installation
6
6
 
@@ -12,7 +12,7 @@ gem 'cow_auth'
12
12
 
13
13
  And then execute:
14
14
 
15
- $ bundle
15
+ $ bundle install
16
16
 
17
17
  Or install it yourself as:
18
18
 
@@ -26,37 +26,37 @@ Configure your user model to add the authentication mechanism.
26
26
 
27
27
  #### Generator (Example)
28
28
 
29
- $ bundle exec rails generate model user uuid:string:uniq email:string:uniq sid:string:uniq encrypted_password:string locale:string first_name:string last_name:string role:integer sign_in_count:integer is_approved:boolean is_deleted:boolean
29
+ $ bundle exec rails generate model user uuid:string:uniq email:string:uniq sid:string:uniq encrypted_password:string locale:string first_name:string last_name:string sign_in_count:integer is_enabled:boolean is_deleted:boolean
30
30
 
31
31
  #### Migration (Example)
32
32
 
33
33
  # Modified migration; includes indexes and other stuff you might not want.
34
- class CreateUsers < ActiveRecord::Migration[5.2]
34
+ class CreateUsers < ActiveRecord::Migration[6.0]
35
35
  def change
36
36
  create_table :users do |t|
37
37
  t.string :uuid, null: false
38
38
  t.string :email, null: false
39
39
  t.string :sid, null: false
40
- t.string :encrypted_password, null: false
41
40
  t.string :locale, null: false
41
+ t.string :encrypted_password, null: false
42
+ t.string :auth_token
42
43
  t.string :first_name
43
44
  t.string :last_name
44
- t.integer :role, default: 0, null: false
45
45
  t.integer :sign_in_count, default: 0, null: false
46
- t.boolean :is_approved, default: false, null: false
46
+ t.boolean :is_enabled, default: false, null: false
47
47
  t.boolean :is_deleted, default: false, null: false
48
+ t.timestamp :expires_at
48
49
  t.timestamps
49
- t.index [:uuid], unique: true
50
- t.index [:email], unique: true
51
- t.index [:sid], unique: true
52
50
  end
51
+ add_index :users, :uuid, unique: true
52
+ add_index :users, :email, unique: true
53
+ add_index :users, :sid, unique: true
53
54
  end
54
55
  end
55
56
 
56
- #### Model Concern
57
+ #### Model Inheritance
57
58
 
58
- class User < ApplicationRecord
59
- include CowAuth::User
59
+ class User < CowAuth::User
60
60
  end
61
61
 
62
62
  #### Create User
@@ -100,12 +100,40 @@ Add the following private method to the ApplicationController (assuming User is
100
100
  end
101
101
  end
102
102
 
103
- #### Sessions Controller Example
103
+ #### Sessions Controller HTML Example
104
+
105
+ The `sign_in_success_path` and `sign_out_success_path` methods need to be defined for redirecting after successful sign-in and sign-out.
106
+
107
+ class SessionsController < ApplicationController
108
+ include CowAuth::SessionAuth::SessionEndpoints
109
+
110
+ skip_before_action :authenticate_user, only: [:new, :create]
111
+
112
+ private
113
+
114
+ def sign_in_success_path
115
+ return root_url
116
+ end
117
+
118
+ def sign_out_success_path
119
+ return sign_in_url
120
+ end
121
+ end
122
+
123
+ #### Sessions Controller JSON Example
124
+
125
+ The `sign_in_success_response_payload` method can optionally be overridden to customize the response payload for a successful sign-in.
104
126
 
105
127
  class Api::V1::SessionsController < ApplicationController
106
128
  include CowAuth::TokenAuth::SessionEndpoints
107
129
 
108
130
  skip_before_action :authenticate_user, only: [:create]
131
+
132
+ protected
133
+
134
+ def sign_in_success_response_payload
135
+ return { uuid: @user.uuid, sid: @user.sid, auth_token: @user.auth_token }
136
+ end
109
137
  end
110
138
 
111
139
  ### Token Authentication
@@ -138,7 +166,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
138
166
 
139
167
  ## Contributing
140
168
 
141
- Bug reports and pull requests are welcome on GitHub at https://github.com/mickey13/cow_auth. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
169
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mickey13/cow-auth. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/mickey13/cow-auth/blob/master/CODE_OF_CONDUCT.md).
142
170
 
143
171
  ## License
144
172
 
@@ -146,4 +174,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
146
174
 
147
175
  ## Code of Conduct
148
176
 
149
- Everyone interacting in the CowAuth projects codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mickey13/cow-auth/blob/master/CODE_OF_CONDUCT.md).
177
+ Everyone interacting in the CowAuth project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mickey13/cow-auth/blob/master/CODE_OF_CONDUCT.md).
@@ -1,32 +1,30 @@
1
-
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'cow_auth/version'
1
+ require_relative 'lib/cow_auth/version'
5
2
 
6
3
  Gem::Specification.new do |spec|
7
4
  spec.name = 'cow_auth'
8
5
  spec.version = CowAuth::VERSION
9
6
  spec.authors = ['Mickey Cowden']
10
- spec.email = ['mickey@vt.edu']
7
+ spec.email = ['mickey@cowden.tech']
11
8
 
12
9
  spec.summary = 'Authentication gem'
13
- spec.description = 'The main goal of this gem is to provide token-based authentication for Rails (or Rails-like) web applications.'
10
+ spec.description = 'The goal of this gem is to provide token-based authentication for Rails (or Rails-like) web applications.'
14
11
  spec.homepage = 'https://github.com/mickey13/cow-auth'
15
12
  spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
14
+
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = spec.homepage
17
+ spec.metadata['changelog_uri'] = spec.homepage
16
18
 
17
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
- f.match(%r{^(test|spec|features)/})
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
23
  end
20
24
  spec.bindir = 'exe'
21
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
26
  spec.require_paths = ['lib']
23
27
 
24
- spec.required_ruby_version = '~> 2.4'
25
-
26
- spec.add_development_dependency 'bundler', '~> 1.16'
27
- spec.add_development_dependency 'rake', '~> 12.3'
28
- spec.add_development_dependency 'minitest', '~> 5.11'
29
- spec.add_runtime_dependency 'actionpack', '~> 5.1'
30
- spec.add_runtime_dependency 'activesupport', '~> 5.1'
28
+ spec.add_runtime_dependency 'activerecord', '~> 6.0'
31
29
  spec.add_runtime_dependency 'scrypt', '~> 3.0'
32
30
  end
@@ -1,6 +1,8 @@
1
1
  require 'cow_auth/version'
2
2
  require 'cow_auth/user'
3
3
  require 'cow_auth/exceptions'
4
+ require 'cow_auth/session_auth/session_endpoints'
5
+ require 'cow_auth/session_auth/authenticate_request'
4
6
  require 'cow_auth/token_auth/session_endpoints'
5
7
  require 'cow_auth/token_auth/authenticate_request'
6
8
 
@@ -1,7 +1,4 @@
1
1
  module CowAuth
2
2
  class NotAuthenticatedError < StandardError
3
3
  end
4
-
5
- class RedisHandleMissingError < StandardError
6
- end
7
4
  end
@@ -0,0 +1,21 @@
1
+ require 'cow_auth/exceptions'
2
+
3
+ module CowAuth
4
+ module SessionAuth
5
+ module AuthenticateRequest
6
+ extend ActiveSupport::Concern
7
+
8
+ private
9
+
10
+ def authenticate_user
11
+ @current_user = authentication_class.find_by(sid: session[:current_user])
12
+ raise CowAuth::NotAuthenticatedError.new('User not authenticated.') if @current_user.blank?
13
+ return true
14
+ end
15
+
16
+ def current_user
17
+ return @current_user
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ require 'cow_auth/exceptions'
2
+
3
+ module CowAuth
4
+ module SessionAuth
5
+ module SessionEndpoints
6
+ extend ActiveSupport::Concern
7
+
8
+ def new
9
+ end
10
+
11
+ def create
12
+ user = authentication_class.find_by(email: params[:email])
13
+ if user.try(:authenticate_with_password, params[:password])
14
+ session[:current_user] = user.sid
15
+ redirect_to sign_in_success_path
16
+ else
17
+ session[:current_user] = nil
18
+ raise CowAuth::NotAuthenticatedError.new('Invalid user credentials.')
19
+ end
20
+ end
21
+
22
+ def destroy
23
+ if @current_user.present?
24
+ session[:current_user] = nil
25
+ redirect_to sign_out_success_path
26
+ else
27
+ raise CowAuth::StandardError.new('Could not sign user out.')
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -4,17 +4,30 @@ module CowAuth
4
4
  module TokenAuth
5
5
  module AuthenticateRequest
6
6
  extend ActiveSupport::Concern
7
- include ActionController::HttpAuthentication::Token::ControllerMethods
8
7
 
9
8
  private
10
9
 
10
+ SID_KEY = 'sid='
11
+ TOKEN_KEY = 'token='
12
+ AUTHORIZATION_REGEX = /^(Token|Bearer)\s*/
13
+ AUTHORIZATION_DELIMITERS = /(?:,|;|\t+)/
14
+
11
15
  def authenticate_user
12
- authenticate_or_request_with_http_token do |token, options|
13
- user = authentication_class.find_by(sid: options[:sid])
14
- @current_user = user.try(:authenticate_with_token, token) ? user : nil
15
- raise CowAuth::NotAuthenticatedError.new('User not authenticated.') if @current_user.blank?
16
- return true
16
+ sid, auth_token = extract_credentials(request.authorization)
17
+ if sid.present? && auth_token.present?
18
+ user = authentication_class.find_by(sid: sid)
19
+ @current_user = user.try(:authenticate_with_token, auth_token) ? user : nil
20
+ return true if @current_user.present?
17
21
  end
22
+ raise CowAuth::NotAuthenticatedError.new('User not authenticated.')
23
+ end
24
+
25
+ def extract_credentials(authorization_header)
26
+ return nil if authorization_header.blank? || !(authorization_header =~ /\A#{AUTHORIZATION_REGEX}/)
27
+ params = authorization_header.sub(AUTHORIZATION_REGEX, '').split(/\s*#{AUTHORIZATION_DELIMITERS}\s*/)
28
+ sid = params[1].sub(SID_KEY, '') if params[1] =~ /\A#{SID_KEY}/
29
+ auth_token = params[0].sub(TOKEN_KEY, '') if params[0] =~ /\A#{TOKEN_KEY}/
30
+ return sid, auth_token
18
31
  end
19
32
 
20
33
  def current_user
@@ -6,22 +6,28 @@ module CowAuth
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  def create
9
- user = authentication_class.find_by(email: params[:email])
10
- if user.try(:authenticate_with_password, params[:password])
11
- user.api_sign_in
12
- render json: { sid: user.sid, auth_token: user.auth_token }, status: :ok
9
+ @user = authentication_class.find_by(email: params[:email])
10
+ if @user.try(:authenticate_with_password, params[:password])
11
+ @user.create_auth_token
12
+ render json: self.sign_in_success_response_payload, status: :ok
13
13
  else
14
14
  raise CowAuth::NotAuthenticatedError.new('Invalid user credentials.')
15
15
  end
16
16
  end
17
17
 
18
18
  def destroy
19
- if @current_user.try(:api_sign_out)
19
+ if @current_user.try(:destroy_auth_token)
20
20
  head :no_content
21
21
  else
22
22
  raise CowAuth::NotAuthenticatedError.new('Could not sign user out.')
23
23
  end
24
24
  end
25
+
26
+ protected
27
+
28
+ def sign_in_success_response_payload
29
+ return { sid: @user.sid, auth_token: @user.auth_token }
30
+ end
25
31
  end
26
32
  end
27
33
  end
@@ -1,20 +1,16 @@
1
+ require 'active_record'
1
2
  require 'scrypt'
2
- require 'cow_auth/exceptions'
3
3
 
4
4
  module CowAuth
5
- module User
6
- extend ActiveSupport::Concern
5
+ class User < ActiveRecord::Base
6
+ after_initialize :generate_sid_if_necessary
7
7
 
8
- included do
9
- after_initialize :generate_sid_if_necessary
10
-
11
- validates :email, presence: true
12
- validates :email, uniqueness: true
13
- validates :encrypted_password, presence: true
14
- validates :sid, presence: true
15
- validates :sid, uniqueness: true
16
- validates :sid, format: { with: /\AC[a-z0-9]{32}\z/ }
17
- end
8
+ validates :email, presence: true
9
+ validates :email, uniqueness: true
10
+ validates :encrypted_password, presence: true
11
+ validates :sid, presence: true
12
+ validates :sid, uniqueness: true
13
+ validates :sid, format: { with: /\AC[a-z0-9]{32}\z/ }
18
14
 
19
15
  def authenticate_with_password(password)
20
16
  return false if self.encrypted_password.blank?
@@ -26,34 +22,31 @@ module CowAuth
26
22
  end
27
23
 
28
24
  def authenticate_with_token(auth_token)
29
- api_key = self.fetch_api_key_from_redis(sid)
30
- if api_key.present? &&
31
- api_key.key?(:auth_token) &&
32
- api_key.key?(:expires_at) &&
33
- api_key[:auth_token] == auth_token &&
34
- api_key[:expires_at] > Time.zone.now
25
+ if self.auth_token.present? &&
26
+ self.expires_at.present? &&
27
+ self.auth_token == auth_token &&
28
+ self.expires_at > Time.zone.now
35
29
  return true
36
30
  end
37
31
  return false
38
32
  end
39
33
 
40
- def api_sign_in
41
- self.redis_handle.set(self.redis_key, {
34
+ def create_auth_token
35
+ self.update(
42
36
  auth_token: self.token_valid? ? self.auth_token : self.generate_auth_token,
43
37
  expires_at: self.generate_token_expires_at
44
- }.to_json)
38
+ )
45
39
  return true
46
40
  end
47
41
 
48
- def api_sign_out
49
- self.redis_handle.del(self.redis_key)
42
+ def destroy_auth_token
43
+ self.update(
44
+ auth_token: nil,
45
+ expires_at: nil
46
+ )
50
47
  return true
51
48
  end
52
49
 
53
- def auth_token
54
- return self.fetch_api_key_from_redis(self.sid).try(:[], :auth_token)
55
- end
56
-
57
50
  def password=(new_password)
58
51
  return false if new_password.blank?
59
52
  salt = SCrypt::Engine.generate_salt
@@ -63,11 +56,6 @@ module CowAuth
63
56
 
64
57
  protected
65
58
 
66
- def fetch_api_key_from_redis(sid)
67
- api_key = self.redis_handle.get(self.redis_key)
68
- return api_key.present? ? JSON.parse(api_key).try(:symbolize_keys) : nil
69
- end
70
-
71
59
  def generate_auth_token
72
60
  return SecureRandom.hex(64)
73
61
  end
@@ -76,21 +64,10 @@ module CowAuth
76
64
  return 1.month.from_now
77
65
  end
78
66
 
79
- def redis_handle
80
- raise CowAuth::RedisHandleMissingError.new('"$redis" handle not found.') unless $redis.present?
81
- return $redis
82
- end
83
-
84
- def redis_key
85
- return "user_#{self.sid.downcase}"
86
- end
87
-
88
67
  def token_valid?
89
- api_key = self.fetch_api_key_from_redis(self.sid)
90
- return api_key.present? &&
91
- api_key.key?(:auth_token) &&
92
- api_key.key?(:expires_at) &&
93
- api_key[:expires_at] > Time.zone.now
68
+ return self.auth_token.present? &&
69
+ self.expires_at.present? &&
70
+ self.expires_at > Time.zone.now
94
71
  end
95
72
 
96
73
  private
@@ -1,3 +1,3 @@
1
1
  module CowAuth
2
- VERSION = '0.5.2'
2
+ VERSION = '0.7.0'
3
3
  end
metadata CHANGED
@@ -1,85 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cow_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mickey Cowden
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-18 00:00:00.000000000 Z
11
+ date: 2020-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.16'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '12.3'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '12.3'
41
- - !ruby/object:Gem::Dependency
42
- name: minitest
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '5.11'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '5.11'
55
- - !ruby/object:Gem::Dependency
56
- name: actionpack
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '5.1'
19
+ version: '6.0'
62
20
  type: :runtime
63
21
  prerelease: false
64
22
  version_requirements: !ruby/object:Gem::Requirement
65
23
  requirements:
66
24
  - - "~>"
67
25
  - !ruby/object:Gem::Version
68
- version: '5.1'
69
- - !ruby/object:Gem::Dependency
70
- name: activesupport
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '5.1'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '5.1'
26
+ version: '6.0'
83
27
  - !ruby/object:Gem::Dependency
84
28
  name: scrypt
85
29
  requirement: !ruby/object:Gem::Requirement
@@ -94,10 +38,10 @@ dependencies:
94
38
  - - "~>"
95
39
  - !ruby/object:Gem::Version
96
40
  version: '3.0'
97
- description: The main goal of this gem is to provide token-based authentication for
98
- Rails (or Rails-like) web applications.
41
+ description: The goal of this gem is to provide token-based authentication for Rails
42
+ (or Rails-like) web applications.
99
43
  email:
100
- - mickey@vt.edu
44
+ - mickey@cowden.tech
101
45
  executables: []
102
46
  extensions: []
103
47
  extra_rdoc_files: []
@@ -115,6 +59,8 @@ files:
115
59
  - cow_auth.gemspec
116
60
  - lib/cow_auth.rb
117
61
  - lib/cow_auth/exceptions.rb
62
+ - lib/cow_auth/session_auth/authenticate_request.rb
63
+ - lib/cow_auth/session_auth/session_endpoints.rb
118
64
  - lib/cow_auth/token_auth/authenticate_request.rb
119
65
  - lib/cow_auth/token_auth/session_endpoints.rb
120
66
  - lib/cow_auth/user.rb
@@ -122,24 +68,26 @@ files:
122
68
  homepage: https://github.com/mickey13/cow-auth
123
69
  licenses:
124
70
  - MIT
125
- metadata: {}
71
+ metadata:
72
+ homepage_uri: https://github.com/mickey13/cow-auth
73
+ source_code_uri: https://github.com/mickey13/cow-auth
74
+ changelog_uri: https://github.com/mickey13/cow-auth
126
75
  post_install_message:
127
76
  rdoc_options: []
128
77
  require_paths:
129
78
  - lib
130
79
  required_ruby_version: !ruby/object:Gem::Requirement
131
80
  requirements:
132
- - - "~>"
81
+ - - ">="
133
82
  - !ruby/object:Gem::Version
134
- version: '2.4'
83
+ version: 2.3.0
135
84
  required_rubygems_version: !ruby/object:Gem::Requirement
136
85
  requirements:
137
86
  - - ">="
138
87
  - !ruby/object:Gem::Version
139
88
  version: '0'
140
89
  requirements: []
141
- rubyforge_project:
142
- rubygems_version: 2.7.4
90
+ rubygems_version: 3.1.4
143
91
  signing_key:
144
92
  specification_version: 4
145
93
  summary: Authentication gem