tiddle 1.1.0 → 1.6.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +47 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +67 -9
- data/Appraisals +12 -10
- data/CHANGELOG.md +33 -0
- data/Gemfile +0 -2
- data/README.md +0 -6
- data/Rakefile +1 -1
- data/gemfiles/rails5.2.gemfile +3 -2
- data/gemfiles/{rails5.0.gemfile → rails6.0.gemfile} +3 -2
- data/gemfiles/{rails4.2.gemfile → rails6.1.gemfile} +3 -2
- data/lib/tiddle.rb +1 -1
- data/lib/tiddle/strategy.rb +8 -0
- data/lib/tiddle/token_issuer.rb +9 -2
- data/lib/tiddle/version.rb +1 -1
- data/spec/{rails_app → rails_app_active_record}/app/controllers/application_controller.rb +0 -0
- data/spec/{rails_app → rails_app_active_record}/app/controllers/long_secrets_controller.rb +0 -0
- data/spec/{rails_app → rails_app_active_record}/app/controllers/secrets_controller.rb +0 -0
- data/spec/{rails_app → rails_app_active_record}/app/models/admin_user.rb +0 -0
- data/spec/{rails_app → rails_app_active_record}/app/models/authentication_token.rb +0 -0
- data/spec/{rails_app → rails_app_active_record}/app/models/user.rb +0 -0
- data/spec/rails_app_active_record/config/application.rb +15 -0
- data/spec/rails_app_active_record/config/boot.rb +2 -0
- data/spec/{rails_app → rails_app_active_record}/config/environment.rb +1 -1
- data/spec/{rails_app → rails_app_active_record}/config/routes.rb +0 -0
- data/spec/{rails_app → rails_app_active_record}/config/secrets.yml +0 -0
- data/spec/{rails_app → rails_app_active_record}/db/migrate/20150217000000_create_tables.rb +5 -7
- data/spec/rails_app_mongoid/app/controllers/application_controller.rb +5 -0
- data/spec/rails_app_mongoid/app/controllers/long_secrets_controller.rb +7 -0
- data/spec/rails_app_mongoid/app/controllers/secrets_controller.rb +7 -0
- data/spec/rails_app_mongoid/app/models/admin_user.rb +2 -0
- data/spec/rails_app_mongoid/app/models/authentication_token.rb +11 -0
- data/spec/rails_app_mongoid/app/models/user.rb +22 -0
- data/spec/{rails_app → rails_app_mongoid}/config/application.rb +4 -4
- data/spec/rails_app_mongoid/config/boot.rb +2 -0
- data/spec/rails_app_mongoid/config/environment.rb +5 -0
- data/spec/rails_app_mongoid/config/mongoid.yml +6 -0
- data/spec/rails_app_mongoid/config/routes.rb +6 -0
- data/spec/rails_app_mongoid/config/secrets.yml +2 -0
- data/spec/spec_helper.rb +11 -12
- data/spec/strategy_spec.rb +13 -13
- data/spec/support/backend.rb +53 -0
- data/spec/support/fake_request.rb +1 -3
- data/spec/tiddle_spec.rb +1 -1
- data/tiddle.gemspec +6 -7
- metadata +69 -61
- data/.travis.yml +0 -12
- data/gemfiles/rails5.1.gemfile +0 -8
- data/spec/rails_app/config/boot.rb +0 -2
- data/spec/support/warningless_get.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ceda852fb296447c9da00e1f7cafabbfe6eefa599f457bcf1885aa937ba549db
|
4
|
+
data.tar.gz: 4d0133d03bd53b4e75595a26ebb6ca115cb9ab6858f3a557eb38fb70dddf01c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97f53dad24042c517c85445a98e26206995d0242e7d80f42bfd1a49dd6cc40e8f55cfcfbfb9e704aed8992b3872897f8b39b5bb8d4b145e758536bc2ce1d7712
|
7
|
+
data.tar.gz: ebdda46f4045e4aeb26ea535b233b3b75b6c434b7a2062fdc5f2342b0e529189c0f413c9d7d1e94693774efb4d95617b2f2b0082af038f1dd9ddcf8d483e28e4
|
@@ -0,0 +1,47 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [main]
|
6
|
+
pull_request:
|
7
|
+
branches: [main]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
strategy:
|
12
|
+
fail-fast: false
|
13
|
+
matrix:
|
14
|
+
gemfile:
|
15
|
+
- rails5.2
|
16
|
+
- rails6.0
|
17
|
+
- rails6.1
|
18
|
+
ruby:
|
19
|
+
- 2.5
|
20
|
+
- 2.6
|
21
|
+
- 2.7
|
22
|
+
- 3.0
|
23
|
+
backend:
|
24
|
+
- active_record
|
25
|
+
- mongoid
|
26
|
+
exclude:
|
27
|
+
- gemfile: rails5.2
|
28
|
+
ruby: 3.0
|
29
|
+
name: ${{ matrix.gemfile }}, ruby ${{ matrix.ruby }}, ${{ matrix.backend }}
|
30
|
+
runs-on: ubuntu-latest
|
31
|
+
env:
|
32
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
33
|
+
BACKEND: ${{ matrix.backend }}
|
34
|
+
|
35
|
+
steps:
|
36
|
+
- uses: actions/checkout@v2
|
37
|
+
- name: Set up Ruby
|
38
|
+
uses: ruby/setup-ruby@v1
|
39
|
+
with:
|
40
|
+
bundler-cache: true
|
41
|
+
ruby-version: ${{ matrix.ruby }}
|
42
|
+
- name: Start MongoDB
|
43
|
+
uses: supercharge/mongodb-github-action@1.3.0
|
44
|
+
if: ${{ matrix.backend == 'mongoid' }}
|
45
|
+
- name: Run tests
|
46
|
+
run: |
|
47
|
+
bundle exec rake spec
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.5
|
3
3
|
Include:
|
4
|
-
- 'lib'
|
5
|
-
- 'spec'
|
4
|
+
- 'lib/**/*.rb'
|
5
|
+
- 'spec/**/*.rb'
|
6
6
|
Exclude:
|
7
7
|
- 'spec/rails_app/**/*'
|
8
8
|
- 'spec/spec_helper.rb'
|
9
|
+
- 'vendor/bundle/**/*'
|
10
|
+
SuggestExtensions: false
|
9
11
|
Style/StringLiterals:
|
10
12
|
Enabled: false
|
11
13
|
Style/Documentation:
|
@@ -14,17 +16,73 @@ Style/FrozenStringLiteralComment:
|
|
14
16
|
Enabled: false
|
15
17
|
Style/SignalException:
|
16
18
|
Enabled: false
|
17
|
-
|
19
|
+
Layout/LineLength:
|
18
20
|
Max: 100
|
19
21
|
Gemspec/OrderedDependencies:
|
20
22
|
Enabled: false
|
21
|
-
Naming/FileName:
|
22
|
-
Exclude:
|
23
|
-
- 'Rakefile'
|
24
|
-
- 'Gemfile'
|
25
|
-
- 'Appraisals'
|
26
23
|
Metrics/BlockLength:
|
27
24
|
Exclude:
|
28
25
|
- 'spec/**/*'
|
29
26
|
Metrics/MethodLength:
|
30
27
|
Max: 15
|
28
|
+
|
29
|
+
Gemspec/DateAssignment:
|
30
|
+
Enabled: true
|
31
|
+
Layout/SpaceBeforeBrackets:
|
32
|
+
Enabled: true
|
33
|
+
Lint/AmbiguousAssignment:
|
34
|
+
Enabled: true
|
35
|
+
Lint/DeprecatedConstants:
|
36
|
+
Enabled: true
|
37
|
+
Lint/DuplicateBranch:
|
38
|
+
Enabled: true
|
39
|
+
Lint/DuplicateRegexpCharacterClassElement:
|
40
|
+
Enabled: true
|
41
|
+
Lint/EmptyBlock:
|
42
|
+
Enabled: true
|
43
|
+
Lint/EmptyClass:
|
44
|
+
Enabled: true
|
45
|
+
Lint/LambdaWithoutLiteralBlock:
|
46
|
+
Enabled: true
|
47
|
+
Lint/NoReturnInBeginEndBlocks:
|
48
|
+
Enabled: true
|
49
|
+
Lint/NumberedParameterAssignment:
|
50
|
+
Enabled: true
|
51
|
+
Lint/OrAssignmentToConstant:
|
52
|
+
Enabled: true
|
53
|
+
Lint/RedundantDirGlobSort:
|
54
|
+
Enabled: true
|
55
|
+
Lint/SymbolConversion:
|
56
|
+
Enabled: true
|
57
|
+
Lint/ToEnumArguments:
|
58
|
+
Enabled: true
|
59
|
+
Lint/TripleQuotes:
|
60
|
+
Enabled: true
|
61
|
+
Lint/UnexpectedBlockArity:
|
62
|
+
Enabled: true
|
63
|
+
Lint/UnmodifiedReduceAccumulator:
|
64
|
+
Enabled: true
|
65
|
+
Style/ArgumentsForwarding:
|
66
|
+
Enabled: true
|
67
|
+
Style/CollectionCompact:
|
68
|
+
Enabled: true
|
69
|
+
Style/DocumentDynamicEvalDefinition:
|
70
|
+
Enabled: true
|
71
|
+
Style/EndlessMethod:
|
72
|
+
Enabled: true
|
73
|
+
Style/HashConversion:
|
74
|
+
Enabled: true
|
75
|
+
Style/HashExcept:
|
76
|
+
Enabled: true
|
77
|
+
Style/IfWithBooleanLiteralBranches:
|
78
|
+
Enabled: true
|
79
|
+
Style/NegatedIfElseCondition:
|
80
|
+
Enabled: true
|
81
|
+
Style/NilLambda:
|
82
|
+
Enabled: true
|
83
|
+
Style/RedundantArgument:
|
84
|
+
Enabled: true
|
85
|
+
Style/StringChars:
|
86
|
+
Enabled: true
|
87
|
+
Style/SwapValues:
|
88
|
+
Enabled: true
|
data/Appraisals
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
-
appraise "
|
2
|
-
gem "rails", "~>
|
3
|
-
|
4
|
-
|
5
|
-
appraise "rails5.0" do
|
6
|
-
gem "rails", "~> 5.0.0"
|
1
|
+
appraise "rails5.2" do
|
2
|
+
gem "rails", "~> 5.2.1"
|
3
|
+
gem "mongoid", "~> 6"
|
4
|
+
gem "sqlite3", "~> 1.3.13"
|
7
5
|
end
|
8
6
|
|
9
|
-
appraise "
|
10
|
-
gem "rails", "~>
|
7
|
+
appraise "rails6.0" do
|
8
|
+
gem "rails", "~> 6.0.0"
|
9
|
+
gem "mongoid", "~> 7"
|
10
|
+
gem "sqlite3"
|
11
11
|
end
|
12
12
|
|
13
|
-
appraise "
|
14
|
-
gem "rails", "
|
13
|
+
appraise "rails6.1" do
|
14
|
+
gem "rails", "~> 6.1.0"
|
15
|
+
gem "mongoid"
|
16
|
+
gem "sqlite3"
|
15
17
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,36 @@
|
|
1
|
+
### 1.6.0
|
2
|
+
|
3
|
+
Add Rails 6.1 support
|
4
|
+
|
5
|
+
Add Ruby 3.0 support
|
6
|
+
|
7
|
+
Remove Rails 4.2 support
|
8
|
+
|
9
|
+
Remove Ruby 2.4 support
|
10
|
+
|
11
|
+
|
12
|
+
### 1.5.0
|
13
|
+
|
14
|
+
Add Rails 6 support
|
15
|
+
|
16
|
+
Fix warning on Ruby 2.7 (Andy Klimczak)
|
17
|
+
|
18
|
+
Skip CSRF clean up (Marcelo Silveira)
|
19
|
+
|
20
|
+
### 1.4.0
|
21
|
+
|
22
|
+
Support for Devise 4.6.
|
23
|
+
|
24
|
+
Relax dependency on Devise.
|
25
|
+
|
26
|
+
### 1.3.0
|
27
|
+
|
28
|
+
Support for Devise 4.5
|
29
|
+
|
30
|
+
### 1.2.0
|
31
|
+
|
32
|
+
Adds support for MongoDB.
|
33
|
+
|
1
34
|
### 1.1.0
|
2
35
|
|
3
36
|
New feature: optional token expiration after period of inactivity - #37
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,17 +1,11 @@
|
|
1
1
|
# Tiddle
|
2
2
|
|
3
|
-
[](https://travis-ci.org/adamniedzielski/tiddle)
|
4
|
-
[](https://coveralls.io/r/adamniedzielski/tiddle?branch=master)
|
5
3
|
[](https://codeclimate.com/github/adamniedzielski/tiddle)
|
6
4
|
|
7
5
|
Tiddle provides Devise strategy for token authentication in API-only Ruby on Rails applications. Its main feature is **support for multiple tokens per user**.
|
8
6
|
|
9
7
|
Tiddle is lightweight and non-configurable. It does what it has to do and leaves some manual implementation to you.
|
10
8
|
|
11
|
-
## Versions
|
12
|
-
|
13
|
-
Versions 0.7.x+ are meant to support Rails 5.0, but they require Devise 4. If you want to use Devise 3 with Rails 4.2 then take a look at the ```0.6.x``` branch.
|
14
|
-
|
15
9
|
## Installation
|
16
10
|
|
17
11
|
Add this line to your application's Gemfile:
|
data/Rakefile
CHANGED
data/gemfiles/rails5.2.gemfile
CHANGED
data/lib/tiddle.rb
CHANGED
@@ -6,7 +6,7 @@ require "tiddle/token_issuer"
|
|
6
6
|
|
7
7
|
module Tiddle
|
8
8
|
def self.create_and_return_token(resource, request, options = {})
|
9
|
-
TokenIssuer.build.create_and_return_token(resource, request, options)
|
9
|
+
TokenIssuer.build.create_and_return_token(resource, request, **options)
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.expire_token(resource, request)
|
data/lib/tiddle/strategy.rb
CHANGED
@@ -28,6 +28,14 @@ module Devise
|
|
28
28
|
false
|
29
29
|
end
|
30
30
|
|
31
|
+
# Avoid CSRF clean up for token authentication as it might trigger session creation in API
|
32
|
+
# environments even if CSRF prevention is not being used.
|
33
|
+
# Devise provides a `clean_up_csrf_token_on_authentication` option but it's not always viable
|
34
|
+
# in applications with multiple user models and authentication strategies.
|
35
|
+
def clean_up_csrf?
|
36
|
+
false
|
37
|
+
end
|
38
|
+
|
31
39
|
private
|
32
40
|
|
33
41
|
def authentication_keys_from_headers
|
data/lib/tiddle/token_issuer.rb
CHANGED
@@ -31,7 +31,8 @@ module Tiddle
|
|
31
31
|
def find_token(resource, token_from_headers)
|
32
32
|
token_class = authentication_token_class(resource)
|
33
33
|
token_body = Devise.token_generator.digest(token_class, :body, token_from_headers)
|
34
|
-
|
34
|
+
# 'find_by' behaves differently in AR vs Mongoid, so using 'where' instead
|
35
|
+
resource.authentication_tokens.where(body: token_body).first
|
35
36
|
end
|
36
37
|
|
37
38
|
def purge_old_tokens(resource)
|
@@ -46,7 +47,13 @@ module Tiddle
|
|
46
47
|
attr_accessor :maximum_tokens_per_user
|
47
48
|
|
48
49
|
def authentication_token_class(resource)
|
49
|
-
resource.
|
50
|
+
if resource.respond_to?(:association) # ActiveRecord
|
51
|
+
resource.association(:authentication_tokens).klass
|
52
|
+
elsif resource.respond_to?(:relations) # Mongoid
|
53
|
+
resource.relations['authentication_tokens'].klass
|
54
|
+
else
|
55
|
+
raise 'Cannot determine authentication token class, unsupported ORM/ODM?'
|
56
|
+
end
|
50
57
|
end
|
51
58
|
|
52
59
|
def token_attributes(token_body, request, expires_in)
|
data/lib/tiddle/version.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path('boot', __dir__)
|
2
|
+
|
3
|
+
require "active_model/railtie"
|
4
|
+
require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_view/railtie"
|
7
|
+
|
8
|
+
module RailsApp
|
9
|
+
class Application < Rails::Application
|
10
|
+
config.eager_load = true
|
11
|
+
config.root = File.expand_path('..', __dir__)
|
12
|
+
config.consider_all_requests_local = true
|
13
|
+
config.active_record.sqlite3.represent_boolean_as_integer = true if config.active_record.sqlite3
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
File without changes
|
@@ -1,10 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
migration_class = ActiveRecord::Migration
|
5
|
-
end
|
6
|
-
|
7
|
-
class CreateTables < migration_class
|
1
|
+
class CreateTables < ActiveRecord::Migration[4.2]
|
2
|
+
# rubocop:disable Metrics/AbcSize
|
3
|
+
# rubocop:disable Metrics/MethodLength
|
8
4
|
def change
|
9
5
|
create_table(:users) do |t|
|
10
6
|
## Database authenticatable
|
@@ -63,4 +59,6 @@ class CreateTables < migration_class
|
|
63
59
|
t.timestamps null: false
|
64
60
|
end
|
65
61
|
end
|
62
|
+
# rubocop:enable Metrics/AbcSize
|
63
|
+
# rubocop:enable Metrics/MethodLength
|
66
64
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class AuthenticationToken
|
2
|
+
include Mongoid::Document
|
3
|
+
|
4
|
+
belongs_to :user
|
5
|
+
|
6
|
+
field :body, type: String
|
7
|
+
field :last_used_at, type: Time
|
8
|
+
field :ip_address, type: String
|
9
|
+
field :user_agent, type: String
|
10
|
+
field :expires_in, type: Integer, default: 0
|
11
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class User
|
2
|
+
include Mongoid::Document
|
3
|
+
|
4
|
+
devise :database_authenticatable,
|
5
|
+
:registerable,
|
6
|
+
:recoverable,
|
7
|
+
:trackable,
|
8
|
+
#:validatable Triggers callback to will_save_change_to_email?, fails with mongoid
|
9
|
+
:token_authenticatable
|
10
|
+
|
11
|
+
has_many :authentication_tokens
|
12
|
+
|
13
|
+
field :email, type: String, default: ''
|
14
|
+
field :encrypted_password, type: String, default: ''
|
15
|
+
field :reset_password_token, type: String
|
16
|
+
field :reset_password_sent_at, type: Time
|
17
|
+
field :sign_in_count, type: Integer, default: 0
|
18
|
+
field :current_sign_in_at, type: Time
|
19
|
+
field :last_sign_in_at, type: Time
|
20
|
+
field :current_sign_in_ip, type: String
|
21
|
+
field :nick_name, type: String
|
22
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require File.expand_path('
|
1
|
+
require File.expand_path('boot', __dir__)
|
2
2
|
|
3
3
|
require "active_model/railtie"
|
4
|
-
require "
|
4
|
+
require "active_job/railtie"
|
5
5
|
require "action_controller/railtie"
|
6
|
+
require "action_mailer/railtie"
|
6
7
|
require "action_view/railtie"
|
7
8
|
|
8
9
|
module RailsApp
|
9
10
|
class Application < Rails::Application
|
10
11
|
config.eager_load = true
|
11
|
-
config.root =
|
12
|
+
config.root = File.expand_path('..', __dir__)
|
12
13
|
config.consider_all_requests_local = true
|
13
14
|
end
|
14
15
|
end
|
15
|
-
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
require 'simplecov'
|
3
|
-
require 'coveralls'
|
4
3
|
|
5
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
6
|
-
SimpleCov::Formatter::HTMLFormatter,
|
7
|
-
Coveralls::SimpleCov::Formatter
|
8
|
-
])
|
9
4
|
SimpleCov.start do
|
10
5
|
add_filter "/spec/"
|
11
6
|
end
|
@@ -13,15 +8,15 @@ end
|
|
13
8
|
ENV["RAILS_ENV"] = 'test'
|
14
9
|
ENV["DATABASE_URL"] = "sqlite3:db/test.sqlite3"
|
15
10
|
|
16
|
-
require
|
17
|
-
|
11
|
+
Dir[__dir__ + "/support/**/*.rb"].each { |f| require f }
|
12
|
+
|
18
13
|
require 'devise'
|
19
|
-
require 'devise/orm/active_record'
|
20
14
|
require 'tiddle'
|
21
15
|
|
22
|
-
|
16
|
+
backend = Backend.from_name(ENV['BACKEND'])
|
17
|
+
backend.load!
|
23
18
|
|
24
|
-
|
19
|
+
require 'rspec/rails'
|
25
20
|
|
26
21
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
27
22
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
@@ -66,8 +61,12 @@ RSpec.configure do |config|
|
|
66
61
|
end
|
67
62
|
|
68
63
|
config.before(:suite) do
|
69
|
-
|
70
|
-
|
64
|
+
backend.setup_database_cleaner
|
65
|
+
backend.migrate!
|
66
|
+
end
|
67
|
+
|
68
|
+
config.before(:each) do
|
69
|
+
DatabaseCleaner.clean if defined?(DatabaseCleaner)
|
71
70
|
end
|
72
71
|
|
73
72
|
config.use_transactional_fixtures = true
|
data/spec/strategy_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe "Authentication using Tiddle strategy", type: :request do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "allows to access endpoints which require authentication" do
|
9
|
-
|
9
|
+
get(
|
10
10
|
secrets_path,
|
11
11
|
headers: {
|
12
12
|
"X-USER-EMAIL" => "test@example.com",
|
@@ -25,14 +25,14 @@ describe "Authentication using Tiddle strategy", type: :request do
|
|
25
25
|
|
26
26
|
it "updates last_used_at field" do
|
27
27
|
expect do
|
28
|
-
|
28
|
+
get(
|
29
29
|
secrets_path,
|
30
30
|
headers: {
|
31
31
|
"X-USER-EMAIL" => "test@example.com",
|
32
32
|
"X-USER-TOKEN" => @token
|
33
33
|
}
|
34
34
|
)
|
35
|
-
end.to(change { @user.authentication_tokens.last.last_used_at })
|
35
|
+
end.to(change { @user.reload.authentication_tokens.last.last_used_at })
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -43,7 +43,7 @@ describe "Authentication using Tiddle strategy", type: :request do
|
|
43
43
|
|
44
44
|
it "does not update last_used_at field" do
|
45
45
|
expect do
|
46
|
-
|
46
|
+
get(
|
47
47
|
secrets_path,
|
48
48
|
headers: {
|
49
49
|
"X-USER-EMAIL" => "test@example.com",
|
@@ -57,7 +57,7 @@ describe "Authentication using Tiddle strategy", type: :request do
|
|
57
57
|
|
58
58
|
context "when email contains uppercase letters" do
|
59
59
|
it "converts email to lower case and authenticates user" do
|
60
|
-
|
60
|
+
get(
|
61
61
|
secrets_path,
|
62
62
|
headers: {
|
63
63
|
"X-USER-EMAIL" => "TEST@example.com",
|
@@ -76,7 +76,7 @@ describe "Authentication using Tiddle strategy", type: :request do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it "does not allow to access endpoints which require authentication" do
|
79
|
-
|
79
|
+
get(
|
80
80
|
secrets_path,
|
81
81
|
headers: {
|
82
82
|
"X-USER-EMAIL" => "wrong@example.com",
|
@@ -94,7 +94,7 @@ describe "Authentication using Tiddle strategy", type: :request do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
it "does not allow to access endpoints which require authentication" do
|
97
|
-
|
97
|
+
get(
|
98
98
|
secrets_path,
|
99
99
|
headers: {
|
100
100
|
"X-USER-EMAIL" => "test@example.com",
|
@@ -107,7 +107,7 @@ describe "Authentication using Tiddle strategy", type: :request do
|
|
107
107
|
|
108
108
|
context "when no headers are passed" do
|
109
109
|
it "does not allow to access endpoints which require authentication" do
|
110
|
-
|
110
|
+
get secrets_path, headers: {}
|
111
111
|
expect(response.status).to eq 401
|
112
112
|
end
|
113
113
|
end
|
@@ -119,7 +119,7 @@ describe "Authentication using Tiddle strategy", type: :request do
|
|
119
119
|
end
|
120
120
|
|
121
121
|
it "allows to access endpoints which require authentication" do
|
122
|
-
|
122
|
+
get(
|
123
123
|
long_secrets_path,
|
124
124
|
headers: {
|
125
125
|
"X-ADMIN-USER-EMAIL" => "test@example.com",
|
@@ -152,7 +152,7 @@ describe "Authentication using Tiddle strategy", type: :request do
|
|
152
152
|
|
153
153
|
it "allows to access endpoints which require authentication with valid \
|
154
154
|
nick name and token" do
|
155
|
-
|
155
|
+
get(
|
156
156
|
secrets_path,
|
157
157
|
headers: { "X-USER-NICK-NAME" => "test", "X-USER-TOKEN" => @token }
|
158
158
|
)
|
@@ -168,7 +168,7 @@ describe "Authentication using Tiddle strategy", type: :request do
|
|
168
168
|
|
169
169
|
describe "token is not expired" do
|
170
170
|
it "does allow to access endpoints which require authentication" do
|
171
|
-
|
171
|
+
get(
|
172
172
|
secrets_path,
|
173
173
|
headers: {
|
174
174
|
"X-USER-EMAIL" => "test@example.com",
|
@@ -181,12 +181,12 @@ describe "Authentication using Tiddle strategy", type: :request do
|
|
181
181
|
|
182
182
|
describe "token is expired" do
|
183
183
|
before do
|
184
|
-
token = @user.authentication_tokens.
|
184
|
+
token = @user.authentication_tokens.max_by(&:id)
|
185
185
|
token.update_attribute(:last_used_at, 1.month.ago)
|
186
186
|
end
|
187
187
|
|
188
188
|
it "does not allow to access endpoints which require authentication" do
|
189
|
-
|
189
|
+
get(
|
190
190
|
secrets_path,
|
191
191
|
headers: {
|
192
192
|
"X-USER-EMAIL" => "test@example.com",
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Backend
|
2
|
+
def self.from_name(name)
|
3
|
+
puts "Backend: #{name}"
|
4
|
+
case name
|
5
|
+
when 'mongoid'
|
6
|
+
MongoidBackend.new
|
7
|
+
else
|
8
|
+
ActiveRecordBackend.new
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class ActiveRecordBackend
|
13
|
+
def load!
|
14
|
+
require 'devise/orm/active_record'
|
15
|
+
require 'rails_app_active_record/config/environment'
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup_database_cleaner
|
19
|
+
# Not necessary
|
20
|
+
end
|
21
|
+
|
22
|
+
def migrate!
|
23
|
+
# Do initial migration
|
24
|
+
path = File.expand_path("../rails_app_active_record/db/migrate/", File.dirname(__FILE__))
|
25
|
+
|
26
|
+
if Gem::Requirement.new(">= 6.0.0") =~ Rails.gem_version
|
27
|
+
ActiveRecord::MigrationContext.new(
|
28
|
+
path,
|
29
|
+
ActiveRecord::SchemaMigration
|
30
|
+
).migrate
|
31
|
+
else
|
32
|
+
ActiveRecord::MigrationContext.new(path).migrate
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class MongoidBackend
|
38
|
+
def load!
|
39
|
+
require 'mongoid'
|
40
|
+
require 'devise/orm/mongoid'
|
41
|
+
require 'rails_app_mongoid/config/environment'
|
42
|
+
require 'database_cleaner-mongoid'
|
43
|
+
end
|
44
|
+
|
45
|
+
def setup_database_cleaner
|
46
|
+
DatabaseCleaner.allow_remote_database_url = true
|
47
|
+
end
|
48
|
+
|
49
|
+
def migrate!
|
50
|
+
# Not necessary
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/spec/tiddle_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe Tiddle do
|
|
23
23
|
|
24
24
|
it "sets last_used_at field" do
|
25
25
|
Tiddle.create_and_return_token(@user, FakeRequest.new)
|
26
|
-
expect(@user.authentication_tokens.last.last_used_at)
|
26
|
+
expect(@user.authentication_tokens.last.last_used_at.to_time)
|
27
27
|
.to be_within(1).of(Time.current)
|
28
28
|
end
|
29
29
|
|
data/tiddle.gemspec
CHANGED
@@ -16,16 +16,15 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
|
-
spec.required_ruby_version = '>= 2.
|
19
|
+
spec.required_ruby_version = '>= 2.5.0'
|
20
20
|
|
21
|
-
spec.add_dependency "devise", ">= 4.0.0.rc1", "<
|
22
|
-
spec.add_dependency "activerecord", ">=
|
23
|
-
spec.add_development_dependency "
|
24
|
-
spec.add_development_dependency "rake", "~> 12.0"
|
21
|
+
spec.add_dependency "devise", ">= 4.0.0.rc1", "< 5"
|
22
|
+
spec.add_dependency "activerecord", ">= 5.2.0"
|
23
|
+
spec.add_development_dependency "rake"
|
25
24
|
spec.add_development_dependency "rspec-rails"
|
26
25
|
spec.add_development_dependency "appraisal"
|
27
|
-
spec.add_development_dependency "sqlite3"
|
28
|
-
spec.add_development_dependency "coveralls"
|
29
26
|
spec.add_development_dependency "simplecov"
|
30
27
|
spec.add_development_dependency "rubocop"
|
28
|
+
spec.add_development_dependency "database_cleaner-active_record"
|
29
|
+
spec.add_development_dependency "database_cleaner-mongoid"
|
31
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiddle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Niedzielski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: 4.0.0.rc1
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '5'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,49 +29,35 @@ dependencies:
|
|
29
29
|
version: 4.0.0.rc1
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '5'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: activerecord
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
39
|
+
version: 5.2.0
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: bundler
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - "~>"
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '1.7'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - "~>"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '1.7'
|
46
|
+
version: 5.2.0
|
61
47
|
- !ruby/object:Gem::Dependency
|
62
48
|
name: rake
|
63
49
|
requirement: !ruby/object:Gem::Requirement
|
64
50
|
requirements:
|
65
|
-
- - "
|
51
|
+
- - ">="
|
66
52
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
53
|
+
version: '0'
|
68
54
|
type: :development
|
69
55
|
prerelease: false
|
70
56
|
version_requirements: !ruby/object:Gem::Requirement
|
71
57
|
requirements:
|
72
|
-
- - "
|
58
|
+
- - ">="
|
73
59
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
60
|
+
version: '0'
|
75
61
|
- !ruby/object:Gem::Dependency
|
76
62
|
name: rspec-rails
|
77
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,7 +87,7 @@ dependencies:
|
|
101
87
|
- !ruby/object:Gem::Version
|
102
88
|
version: '0'
|
103
89
|
- !ruby/object:Gem::Dependency
|
104
|
-
name:
|
90
|
+
name: simplecov
|
105
91
|
requirement: !ruby/object:Gem::Requirement
|
106
92
|
requirements:
|
107
93
|
- - ">="
|
@@ -115,7 +101,7 @@ dependencies:
|
|
115
101
|
- !ruby/object:Gem::Version
|
116
102
|
version: '0'
|
117
103
|
- !ruby/object:Gem::Dependency
|
118
|
-
name:
|
104
|
+
name: rubocop
|
119
105
|
requirement: !ruby/object:Gem::Requirement
|
120
106
|
requirements:
|
121
107
|
- - ">="
|
@@ -129,7 +115,7 @@ dependencies:
|
|
129
115
|
- !ruby/object:Gem::Version
|
130
116
|
version: '0'
|
131
117
|
- !ruby/object:Gem::Dependency
|
132
|
-
name:
|
118
|
+
name: database_cleaner-active_record
|
133
119
|
requirement: !ruby/object:Gem::Requirement
|
134
120
|
requirements:
|
135
121
|
- - ">="
|
@@ -143,7 +129,7 @@ dependencies:
|
|
143
129
|
- !ruby/object:Gem::Version
|
144
130
|
version: '0'
|
145
131
|
- !ruby/object:Gem::Dependency
|
146
|
-
name:
|
132
|
+
name: database_cleaner-mongoid
|
147
133
|
requirement: !ruby/object:Gem::Requirement
|
148
134
|
requirements:
|
149
135
|
- - ">="
|
@@ -163,10 +149,10 @@ executables: []
|
|
163
149
|
extensions: []
|
164
150
|
extra_rdoc_files: []
|
165
151
|
files:
|
152
|
+
- ".github/workflows/ruby.yml"
|
166
153
|
- ".gitignore"
|
167
154
|
- ".rspec"
|
168
155
|
- ".rubocop.yml"
|
169
|
-
- ".travis.yml"
|
170
156
|
- Appraisals
|
171
157
|
- CHANGELOG.md
|
172
158
|
- CONTRIBUTING.md
|
@@ -175,10 +161,9 @@ files:
|
|
175
161
|
- README.md
|
176
162
|
- Rakefile
|
177
163
|
- config/locales/en.yml
|
178
|
-
- gemfiles/rails4.2.gemfile
|
179
|
-
- gemfiles/rails5.0.gemfile
|
180
|
-
- gemfiles/rails5.1.gemfile
|
181
164
|
- gemfiles/rails5.2.gemfile
|
165
|
+
- gemfiles/rails6.0.gemfile
|
166
|
+
- gemfiles/rails6.1.gemfile
|
182
167
|
- lib/tiddle.rb
|
183
168
|
- lib/tiddle/model.rb
|
184
169
|
- lib/tiddle/model_name.rb
|
@@ -186,22 +171,34 @@ files:
|
|
186
171
|
- lib/tiddle/strategy.rb
|
187
172
|
- lib/tiddle/token_issuer.rb
|
188
173
|
- lib/tiddle/version.rb
|
189
|
-
- spec/
|
190
|
-
- spec/
|
191
|
-
- spec/
|
192
|
-
- spec/
|
193
|
-
- spec/
|
194
|
-
- spec/
|
195
|
-
- spec/
|
196
|
-
- spec/
|
197
|
-
- spec/
|
198
|
-
- spec/
|
199
|
-
- spec/
|
200
|
-
- spec/
|
174
|
+
- spec/rails_app_active_record/app/controllers/application_controller.rb
|
175
|
+
- spec/rails_app_active_record/app/controllers/long_secrets_controller.rb
|
176
|
+
- spec/rails_app_active_record/app/controllers/secrets_controller.rb
|
177
|
+
- spec/rails_app_active_record/app/models/admin_user.rb
|
178
|
+
- spec/rails_app_active_record/app/models/authentication_token.rb
|
179
|
+
- spec/rails_app_active_record/app/models/user.rb
|
180
|
+
- spec/rails_app_active_record/config/application.rb
|
181
|
+
- spec/rails_app_active_record/config/boot.rb
|
182
|
+
- spec/rails_app_active_record/config/environment.rb
|
183
|
+
- spec/rails_app_active_record/config/routes.rb
|
184
|
+
- spec/rails_app_active_record/config/secrets.yml
|
185
|
+
- spec/rails_app_active_record/db/migrate/20150217000000_create_tables.rb
|
186
|
+
- spec/rails_app_mongoid/app/controllers/application_controller.rb
|
187
|
+
- spec/rails_app_mongoid/app/controllers/long_secrets_controller.rb
|
188
|
+
- spec/rails_app_mongoid/app/controllers/secrets_controller.rb
|
189
|
+
- spec/rails_app_mongoid/app/models/admin_user.rb
|
190
|
+
- spec/rails_app_mongoid/app/models/authentication_token.rb
|
191
|
+
- spec/rails_app_mongoid/app/models/user.rb
|
192
|
+
- spec/rails_app_mongoid/config/application.rb
|
193
|
+
- spec/rails_app_mongoid/config/boot.rb
|
194
|
+
- spec/rails_app_mongoid/config/environment.rb
|
195
|
+
- spec/rails_app_mongoid/config/mongoid.yml
|
196
|
+
- spec/rails_app_mongoid/config/routes.rb
|
197
|
+
- spec/rails_app_mongoid/config/secrets.yml
|
201
198
|
- spec/spec_helper.rb
|
202
199
|
- spec/strategy_spec.rb
|
200
|
+
- spec/support/backend.rb
|
203
201
|
- spec/support/fake_request.rb
|
204
|
-
- spec/support/warningless_get.rb
|
205
202
|
- spec/tiddle_spec.rb
|
206
203
|
- tiddle.gemspec
|
207
204
|
homepage: ''
|
@@ -216,33 +213,44 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
216
213
|
requirements:
|
217
214
|
- - ">="
|
218
215
|
- !ruby/object:Gem::Version
|
219
|
-
version: 2.
|
216
|
+
version: 2.5.0
|
220
217
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
221
218
|
requirements:
|
222
219
|
- - ">="
|
223
220
|
- !ruby/object:Gem::Version
|
224
221
|
version: '0'
|
225
222
|
requirements: []
|
226
|
-
|
227
|
-
rubygems_version: 2.7.3
|
223
|
+
rubygems_version: 3.1.2
|
228
224
|
signing_key:
|
229
225
|
specification_version: 4
|
230
226
|
summary: Token authentication for Devise which supports multiple tokens per model
|
231
227
|
test_files:
|
232
|
-
- spec/
|
233
|
-
- spec/
|
234
|
-
- spec/
|
235
|
-
- spec/
|
236
|
-
- spec/
|
237
|
-
- spec/
|
238
|
-
- spec/
|
239
|
-
- spec/
|
240
|
-
- spec/
|
241
|
-
- spec/
|
242
|
-
- spec/
|
243
|
-
- spec/
|
228
|
+
- spec/rails_app_active_record/app/controllers/application_controller.rb
|
229
|
+
- spec/rails_app_active_record/app/controllers/long_secrets_controller.rb
|
230
|
+
- spec/rails_app_active_record/app/controllers/secrets_controller.rb
|
231
|
+
- spec/rails_app_active_record/app/models/admin_user.rb
|
232
|
+
- spec/rails_app_active_record/app/models/authentication_token.rb
|
233
|
+
- spec/rails_app_active_record/app/models/user.rb
|
234
|
+
- spec/rails_app_active_record/config/application.rb
|
235
|
+
- spec/rails_app_active_record/config/boot.rb
|
236
|
+
- spec/rails_app_active_record/config/environment.rb
|
237
|
+
- spec/rails_app_active_record/config/routes.rb
|
238
|
+
- spec/rails_app_active_record/config/secrets.yml
|
239
|
+
- spec/rails_app_active_record/db/migrate/20150217000000_create_tables.rb
|
240
|
+
- spec/rails_app_mongoid/app/controllers/application_controller.rb
|
241
|
+
- spec/rails_app_mongoid/app/controllers/long_secrets_controller.rb
|
242
|
+
- spec/rails_app_mongoid/app/controllers/secrets_controller.rb
|
243
|
+
- spec/rails_app_mongoid/app/models/admin_user.rb
|
244
|
+
- spec/rails_app_mongoid/app/models/authentication_token.rb
|
245
|
+
- spec/rails_app_mongoid/app/models/user.rb
|
246
|
+
- spec/rails_app_mongoid/config/application.rb
|
247
|
+
- spec/rails_app_mongoid/config/boot.rb
|
248
|
+
- spec/rails_app_mongoid/config/environment.rb
|
249
|
+
- spec/rails_app_mongoid/config/mongoid.yml
|
250
|
+
- spec/rails_app_mongoid/config/routes.rb
|
251
|
+
- spec/rails_app_mongoid/config/secrets.yml
|
244
252
|
- spec/spec_helper.rb
|
245
253
|
- spec/strategy_spec.rb
|
254
|
+
- spec/support/backend.rb
|
246
255
|
- spec/support/fake_request.rb
|
247
|
-
- spec/support/warningless_get.rb
|
248
256
|
- spec/tiddle_spec.rb
|
data/.travis.yml
DELETED
data/gemfiles/rails5.1.gemfile
DELETED