tiddle 1.3.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +46 -0
- data/.rubocop.yml +67 -9
- data/Appraisals +11 -13
- data/CHANGELOG.md +34 -0
- data/Gemfile +0 -2
- data/README.md +0 -6
- data/Rakefile +1 -1
- data/gemfiles/rails5.2.gemfile +1 -1
- data/gemfiles/{rails4.2.gemfile → rails6.0.gemfile} +3 -3
- data/gemfiles/{rails5.0.gemfile → rails6.1.gemfile} +3 -3
- data/lib/tiddle/strategy.rb +8 -0
- data/lib/tiddle/token_issuer.rb +9 -4
- data/lib/tiddle/version.rb +1 -1
- data/lib/tiddle.rb +1 -1
- data/spec/rails_app_active_record/config/application.rb +2 -2
- data/spec/rails_app_active_record/config/boot.rb +1 -1
- data/spec/rails_app_active_record/config/environment.rb +1 -1
- data/spec/rails_app_active_record/db/migrate/20150217000000_create_tables.rb +2 -7
- data/spec/rails_app_mongoid/app/models/authentication_token.rb +1 -0
- data/spec/rails_app_mongoid/app/models/user.rb +1 -1
- data/spec/rails_app_mongoid/config/application.rb +2 -3
- data/spec/rails_app_mongoid/config/boot.rb +1 -1
- data/spec/rails_app_mongoid/config/environment.rb +1 -1
- data/spec/spec_helper.rb +4 -9
- data/spec/strategy_spec.rb +12 -12
- data/spec/support/backend.rb +8 -5
- data/spec/support/fake_request.rb +1 -3
- data/spec/tiddle_spec.rb +5 -0
- data/tiddle.gemspec +6 -8
- metadata +17 -49
- data/.travis.yml +0 -16
- data/gemfiles/rails5.1.gemfile +0 -9
- 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: d20d30a11350b4ee5ffe3a9c6ba9640afa90c13ddf87dac2c9bf6d4160339627
|
4
|
+
data.tar.gz: fcd8811ba7c94de4accbf4a7920e6903f780707d5af858c7e9a153691ec53351
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: baf2289d634255233c6efe5c2988789a63ca05bdf1c278be92d500e50a5009e6875b29ef15c7e1cbb9bd03f131349bcf11757938f166a329389fa3cc720a7399
|
7
|
+
data.tar.gz: b972e36c75bb0b1c3bc5f21ef9977d5d9f93e595dfaef6905bd59f458079b9b4f7fb6e5068e35fd6b1aaa6e4e63740c62609db68c89bb87a0353bddf1c702721
|
@@ -0,0 +1,46 @@
|
|
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.6
|
20
|
+
- 2.7
|
21
|
+
- 3.0
|
22
|
+
backend:
|
23
|
+
- active_record
|
24
|
+
- mongoid
|
25
|
+
exclude:
|
26
|
+
- gemfile: rails5.2
|
27
|
+
ruby: 3.0
|
28
|
+
name: ${{ matrix.gemfile }}, ruby ${{ matrix.ruby }}, ${{ matrix.backend }}
|
29
|
+
runs-on: ubuntu-latest
|
30
|
+
env:
|
31
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
32
|
+
BACKEND: ${{ matrix.backend }}
|
33
|
+
|
34
|
+
steps:
|
35
|
+
- uses: actions/checkout@v2
|
36
|
+
- name: Set up Ruby
|
37
|
+
uses: ruby/setup-ruby@v1
|
38
|
+
with:
|
39
|
+
bundler-cache: true
|
40
|
+
ruby-version: ${{ matrix.ruby }}
|
41
|
+
- name: Start MongoDB
|
42
|
+
uses: supercharge/mongodb-github-action@1.3.0
|
43
|
+
if: ${{ matrix.backend == 'mongoid' }}
|
44
|
+
- name: Run tests
|
45
|
+
run: |
|
46
|
+
bundle exec rake spec
|
data/.rubocop.yml
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.6
|
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,19 +1,17 @@
|
|
1
|
-
appraise "
|
2
|
-
gem "rails", "~>
|
3
|
-
gem "mongoid", "~> 5"
|
4
|
-
end
|
5
|
-
|
6
|
-
appraise "rails5.0" do
|
7
|
-
gem "rails", "~> 5.0.0"
|
1
|
+
appraise "rails5.2" do
|
2
|
+
gem "rails", "~> 5.2.1"
|
8
3
|
gem "mongoid", "~> 6"
|
4
|
+
gem "sqlite3", "~> 1.3.13"
|
9
5
|
end
|
10
6
|
|
11
|
-
appraise "
|
12
|
-
gem "rails", "~>
|
13
|
-
gem "mongoid", "~>
|
7
|
+
appraise "rails6.0" do
|
8
|
+
gem "rails", "~> 6.0.0"
|
9
|
+
gem "mongoid", "~> 7"
|
10
|
+
gem "sqlite3"
|
14
11
|
end
|
15
12
|
|
16
|
-
appraise "
|
17
|
-
gem "rails", "~>
|
18
|
-
gem "mongoid"
|
13
|
+
appraise "rails6.1" do
|
14
|
+
gem "rails", "~> 6.1.0"
|
15
|
+
gem "mongoid"
|
16
|
+
gem "sqlite3"
|
19
17
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,37 @@
|
|
1
|
+
### 1.7.0
|
2
|
+
|
3
|
+
Add ability to track additional info in tokens (Marcelo Silveira)
|
4
|
+
|
5
|
+
Remove Ruby 2.5 support
|
6
|
+
|
7
|
+
### 1.6.0
|
8
|
+
|
9
|
+
Add Rails 6.1 support
|
10
|
+
|
11
|
+
Add Ruby 3.0 support
|
12
|
+
|
13
|
+
Remove Rails 4.2 support
|
14
|
+
|
15
|
+
Remove Ruby 2.4 support
|
16
|
+
|
17
|
+
### 1.5.0
|
18
|
+
|
19
|
+
Add Rails 6 support
|
20
|
+
|
21
|
+
Fix warning on Ruby 2.7 (Andy Klimczak)
|
22
|
+
|
23
|
+
Skip CSRF clean up (Marcelo Silveira)
|
24
|
+
|
25
|
+
### 1.4.0
|
26
|
+
|
27
|
+
Support for Devise 4.6.
|
28
|
+
|
29
|
+
Relax dependency on Devise.
|
30
|
+
|
31
|
+
### 1.3.0
|
32
|
+
|
33
|
+
Support for Devise 4.5
|
34
|
+
|
1
35
|
### 1.2.0
|
2
36
|
|
3
37
|
Adds support for MongoDB.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,17 +1,11 @@
|
|
1
1
|
# Tiddle
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/adamniedzielski/tiddle.svg?branch=master)](https://travis-ci.org/adamniedzielski/tiddle)
|
4
|
-
[![Coverage Status](https://coveralls.io/repos/adamniedzielski/tiddle/badge.svg?branch=master)](https://coveralls.io/r/adamniedzielski/tiddle?branch=master)
|
5
3
|
[![Code Climate](https://codeclimate.com/github/adamniedzielski/tiddle/badges/gpa.svg)](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/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
@@ -12,12 +12,17 @@ module Tiddle
|
|
12
12
|
self.maximum_tokens_per_user = maximum_tokens_per_user
|
13
13
|
end
|
14
14
|
|
15
|
-
def create_and_return_token(resource, request, expires_in: nil)
|
15
|
+
def create_and_return_token(resource, request, expires_in: nil, metadata: {})
|
16
16
|
token_class = authentication_token_class(resource)
|
17
17
|
token, token_body = Devise.token_generator.generate(token_class, :body)
|
18
18
|
|
19
19
|
resource.authentication_tokens.create!(
|
20
|
-
token_attributes(
|
20
|
+
token_attributes(
|
21
|
+
token_body: token_body,
|
22
|
+
request: request,
|
23
|
+
expires_in: expires_in,
|
24
|
+
metadata: metadata
|
25
|
+
)
|
21
26
|
)
|
22
27
|
|
23
28
|
token
|
@@ -56,13 +61,13 @@ module Tiddle
|
|
56
61
|
end
|
57
62
|
end
|
58
63
|
|
59
|
-
def token_attributes(token_body
|
64
|
+
def token_attributes(token_body:, request:, expires_in:, metadata: {})
|
60
65
|
attributes = {
|
61
66
|
body: token_body,
|
62
67
|
last_used_at: Time.current,
|
63
68
|
ip_address: request.remote_ip,
|
64
69
|
user_agent: request.user_agent
|
65
|
-
}
|
70
|
+
}.merge(metadata)
|
66
71
|
|
67
72
|
if expires_in
|
68
73
|
attributes.merge(expires_in: expires_in)
|
data/lib/tiddle/version.rb
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)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path('
|
1
|
+
require File.expand_path('boot', __dir__)
|
2
2
|
|
3
3
|
require "active_model/railtie"
|
4
4
|
require "active_record/railtie"
|
@@ -8,7 +8,7 @@ require "action_view/railtie"
|
|
8
8
|
module RailsApp
|
9
9
|
class Application < Rails::Application
|
10
10
|
config.eager_load = true
|
11
|
-
config.root = File.expand_path('
|
11
|
+
config.root = File.expand_path('..', __dir__)
|
12
12
|
config.consider_all_requests_local = true
|
13
13
|
config.active_record.sqlite3.represent_boolean_as_integer = true if config.active_record.sqlite3
|
14
14
|
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
ENV['BUNDLE_GEMFILE'] = File.expand_path('
|
1
|
+
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../../Gemfile', __dir__)
|
2
2
|
require 'bundler/setup'
|
@@ -1,10 +1,4 @@
|
|
1
|
-
|
2
|
-
ActiveRecord::Migration[4.2]
|
3
|
-
else
|
4
|
-
ActiveRecord::Migration
|
5
|
-
end
|
6
|
-
|
7
|
-
class CreateTables < migration_class
|
1
|
+
class CreateTables < ActiveRecord::Migration[4.2]
|
8
2
|
# rubocop:disable Metrics/AbcSize
|
9
3
|
# rubocop:disable Metrics/MethodLength
|
10
4
|
def change
|
@@ -61,6 +55,7 @@ class CreateTables < migration_class
|
|
61
55
|
t.integer :expires_in, null: false, default: 0
|
62
56
|
t.string :ip_address
|
63
57
|
t.string :user_agent
|
58
|
+
t.string :metadata_attr1
|
64
59
|
|
65
60
|
t.timestamps null: false
|
66
61
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path('
|
1
|
+
require File.expand_path('boot', __dir__)
|
2
2
|
|
3
3
|
require "active_model/railtie"
|
4
4
|
require "active_job/railtie"
|
@@ -9,8 +9,7 @@ require "action_view/railtie"
|
|
9
9
|
module RailsApp
|
10
10
|
class Application < Rails::Application
|
11
11
|
config.eager_load = true
|
12
|
-
config.root = File.expand_path('
|
12
|
+
config.root = File.expand_path('..', __dir__)
|
13
13
|
config.consider_all_requests_local = true
|
14
|
-
config.active_record.sqlite3.represent_boolean_as_integer = true if config.active_record.sqlite3
|
15
14
|
end
|
16
15
|
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
ENV['BUNDLE_GEMFILE'] = File.expand_path('
|
1
|
+
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../../Gemfile', __dir__)
|
2
2
|
require 'bundler/setup'
|
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,16 +8,16 @@ 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
14
|
require 'tiddle'
|
20
15
|
|
21
|
-
Dir[__dir__ + "/support/**/*.rb"].each { |f| require f }
|
22
|
-
|
23
16
|
backend = Backend.from_name(ENV['BACKEND'])
|
24
17
|
backend.load!
|
25
18
|
|
19
|
+
require 'rspec/rails'
|
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`.
|
28
23
|
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
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,7 +25,7 @@ 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",
|
@@ -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",
|
data/spec/support/backend.rb
CHANGED
@@ -23,10 +23,13 @@ module Backend
|
|
23
23
|
# Do initial migration
|
24
24
|
path = File.expand_path("../rails_app_active_record/db/migrate/", File.dirname(__FILE__))
|
25
25
|
|
26
|
-
if Gem::Requirement.new(">=
|
27
|
-
ActiveRecord::MigrationContext.new(
|
26
|
+
if Gem::Requirement.new(">= 6.0.0") =~ Rails.gem_version
|
27
|
+
ActiveRecord::MigrationContext.new(
|
28
|
+
path,
|
29
|
+
ActiveRecord::SchemaMigration
|
30
|
+
).migrate
|
28
31
|
else
|
29
|
-
ActiveRecord::
|
32
|
+
ActiveRecord::MigrationContext.new(path).migrate
|
30
33
|
end
|
31
34
|
end
|
32
35
|
end
|
@@ -36,11 +39,11 @@ module Backend
|
|
36
39
|
require 'mongoid'
|
37
40
|
require 'devise/orm/mongoid'
|
38
41
|
require 'rails_app_mongoid/config/environment'
|
39
|
-
require 'database_cleaner'
|
42
|
+
require 'database_cleaner-mongoid'
|
40
43
|
end
|
41
44
|
|
42
45
|
def setup_database_cleaner
|
43
|
-
DatabaseCleaner
|
46
|
+
DatabaseCleaner.allow_remote_database_url = true
|
44
47
|
end
|
45
48
|
|
46
49
|
def migrate!
|
data/spec/tiddle_spec.rb
CHANGED
@@ -38,6 +38,11 @@ describe Tiddle do
|
|
38
38
|
FakeRequest.new(user_agent: "Internet Explorer 4.0")
|
39
39
|
expect(@user.authentication_tokens.last.user_agent).to eq "Internet Explorer 4.0"
|
40
40
|
end
|
41
|
+
|
42
|
+
it "saves additional metadata" do
|
43
|
+
Tiddle.create_and_return_token @user, FakeRequest.new, metadata: { metadata_attr1: "abc" }
|
44
|
+
expect(@user.authentication_tokens.last.metadata_attr1).to eq "abc"
|
45
|
+
end
|
41
46
|
end
|
42
47
|
|
43
48
|
describe "find_token" do
|
data/tiddle.gemspec
CHANGED
@@ -16,17 +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.6.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"
|
31
|
-
spec.add_development_dependency "database_cleaner"
|
28
|
+
spec.add_development_dependency "database_cleaner-active_record"
|
29
|
+
spec.add_development_dependency "database_cleaner-mongoid"
|
32
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.7.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-09-09 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,51 +29,23 @@ 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
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - "~>"
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '12.0'
|
68
|
-
type: :development
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - "~>"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '12.0'
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
|
-
name: rspec-rails
|
77
49
|
requirement: !ruby/object:Gem::Requirement
|
78
50
|
requirements:
|
79
51
|
- - ">="
|
@@ -87,7 +59,7 @@ dependencies:
|
|
87
59
|
- !ruby/object:Gem::Version
|
88
60
|
version: '0'
|
89
61
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
62
|
+
name: rspec-rails
|
91
63
|
requirement: !ruby/object:Gem::Requirement
|
92
64
|
requirements:
|
93
65
|
- - ">="
|
@@ -101,7 +73,7 @@ dependencies:
|
|
101
73
|
- !ruby/object:Gem::Version
|
102
74
|
version: '0'
|
103
75
|
- !ruby/object:Gem::Dependency
|
104
|
-
name:
|
76
|
+
name: appraisal
|
105
77
|
requirement: !ruby/object:Gem::Requirement
|
106
78
|
requirements:
|
107
79
|
- - ">="
|
@@ -115,7 +87,7 @@ dependencies:
|
|
115
87
|
- !ruby/object:Gem::Version
|
116
88
|
version: '0'
|
117
89
|
- !ruby/object:Gem::Dependency
|
118
|
-
name:
|
90
|
+
name: simplecov
|
119
91
|
requirement: !ruby/object:Gem::Requirement
|
120
92
|
requirements:
|
121
93
|
- - ">="
|
@@ -129,7 +101,7 @@ dependencies:
|
|
129
101
|
- !ruby/object:Gem::Version
|
130
102
|
version: '0'
|
131
103
|
- !ruby/object:Gem::Dependency
|
132
|
-
name:
|
104
|
+
name: rubocop
|
133
105
|
requirement: !ruby/object:Gem::Requirement
|
134
106
|
requirements:
|
135
107
|
- - ">="
|
@@ -143,7 +115,7 @@ dependencies:
|
|
143
115
|
- !ruby/object:Gem::Version
|
144
116
|
version: '0'
|
145
117
|
- !ruby/object:Gem::Dependency
|
146
|
-
name:
|
118
|
+
name: database_cleaner-active_record
|
147
119
|
requirement: !ruby/object:Gem::Requirement
|
148
120
|
requirements:
|
149
121
|
- - ">="
|
@@ -157,7 +129,7 @@ dependencies:
|
|
157
129
|
- !ruby/object:Gem::Version
|
158
130
|
version: '0'
|
159
131
|
- !ruby/object:Gem::Dependency
|
160
|
-
name: database_cleaner
|
132
|
+
name: database_cleaner-mongoid
|
161
133
|
requirement: !ruby/object:Gem::Requirement
|
162
134
|
requirements:
|
163
135
|
- - ">="
|
@@ -177,10 +149,10 @@ executables: []
|
|
177
149
|
extensions: []
|
178
150
|
extra_rdoc_files: []
|
179
151
|
files:
|
152
|
+
- ".github/workflows/ruby.yml"
|
180
153
|
- ".gitignore"
|
181
154
|
- ".rspec"
|
182
155
|
- ".rubocop.yml"
|
183
|
-
- ".travis.yml"
|
184
156
|
- Appraisals
|
185
157
|
- CHANGELOG.md
|
186
158
|
- CONTRIBUTING.md
|
@@ -189,10 +161,9 @@ files:
|
|
189
161
|
- README.md
|
190
162
|
- Rakefile
|
191
163
|
- config/locales/en.yml
|
192
|
-
- gemfiles/rails4.2.gemfile
|
193
|
-
- gemfiles/rails5.0.gemfile
|
194
|
-
- gemfiles/rails5.1.gemfile
|
195
164
|
- gemfiles/rails5.2.gemfile
|
165
|
+
- gemfiles/rails6.0.gemfile
|
166
|
+
- gemfiles/rails6.1.gemfile
|
196
167
|
- lib/tiddle.rb
|
197
168
|
- lib/tiddle/model.rb
|
198
169
|
- lib/tiddle/model_name.rb
|
@@ -228,7 +199,6 @@ files:
|
|
228
199
|
- spec/strategy_spec.rb
|
229
200
|
- spec/support/backend.rb
|
230
201
|
- spec/support/fake_request.rb
|
231
|
-
- spec/support/warningless_get.rb
|
232
202
|
- spec/tiddle_spec.rb
|
233
203
|
- tiddle.gemspec
|
234
204
|
homepage: ''
|
@@ -243,15 +213,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
243
213
|
requirements:
|
244
214
|
- - ">="
|
245
215
|
- !ruby/object:Gem::Version
|
246
|
-
version: 2.
|
216
|
+
version: 2.6.0
|
247
217
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
248
218
|
requirements:
|
249
219
|
- - ">="
|
250
220
|
- !ruby/object:Gem::Version
|
251
221
|
version: '0'
|
252
222
|
requirements: []
|
253
|
-
|
254
|
-
rubygems_version: 2.7.3
|
223
|
+
rubygems_version: 3.1.2
|
255
224
|
signing_key:
|
256
225
|
specification_version: 4
|
257
226
|
summary: Token authentication for Devise which supports multiple tokens per model
|
@@ -284,5 +253,4 @@ test_files:
|
|
284
253
|
- spec/strategy_spec.rb
|
285
254
|
- spec/support/backend.rb
|
286
255
|
- spec/support/fake_request.rb
|
287
|
-
- spec/support/warningless_get.rb
|
288
256
|
- spec/tiddle_spec.rb
|
data/.travis.yml
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
before_install: gem update --system
|
3
|
-
services:
|
4
|
-
- mongodb
|
5
|
-
rvm:
|
6
|
-
- "2.3.5"
|
7
|
-
- "2.4.2"
|
8
|
-
- "2.5.0"
|
9
|
-
gemfile:
|
10
|
-
- "gemfiles/rails4.2.gemfile"
|
11
|
-
- "gemfiles/rails5.0.gemfile"
|
12
|
-
- "gemfiles/rails5.1.gemfile"
|
13
|
-
- "gemfiles/rails5.2.gemfile"
|
14
|
-
env:
|
15
|
-
- BACKEND=mongoid
|
16
|
-
- BACKEND=active_record
|
data/gemfiles/rails5.1.gemfile
DELETED