solidus_jwt 1.1.0 → 1.2.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/.gem_release.yml +2 -2
- data/.rubocop.yml +0 -17
- data/Gemfile +2 -0
- data/README.md +13 -0
- data/app/decorators/{solidus_jwt → controllers/solidus_jwt}/spree/api/base_controller_decorator.rb +3 -1
- data/app/decorators/{solidus_jwt → models/solidus_jwt}/spree/user_decorator.rb +22 -0
- data/app/models/solidus_jwt/base_record.rb +2 -0
- data/app/models/solidus_jwt/token.rb +2 -0
- data/bin/r +9 -0
- data/bin/rails +4 -14
- data/bin/rails-engine +15 -0
- data/bin/rails-sandbox +17 -0
- data/bin/rake +7 -0
- data/bin/sandbox +4 -1
- data/bin/sandbox_rails +9 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20190222220038_create_solidus_jwt_tokens.rb +2 -0
- data/db/migrate/20191212083655_add_foreign_key_to_users_table.rb +2 -0
- data/{app/controllers → lib/controllers/api}/spree/api/oauths_controller.rb +2 -0
- data/lib/generators/solidus_jwt/install/install_generator.rb +2 -0
- data/lib/solidus_jwt.rb +2 -0
- data/lib/solidus_jwt/concerns/decodeable.rb +2 -0
- data/lib/solidus_jwt/concerns/encodeable.rb +2 -0
- data/lib/solidus_jwt/config.rb +2 -0
- data/lib/solidus_jwt/devise_strategies/base.rb +2 -0
- data/lib/solidus_jwt/devise_strategies/password.rb +2 -0
- data/lib/solidus_jwt/devise_strategies/refresh_token.rb +2 -0
- data/lib/solidus_jwt/distributor/devise.rb +2 -0
- data/lib/solidus_jwt/engine.rb +3 -1
- data/lib/solidus_jwt/factories.rb +2 -0
- data/lib/solidus_jwt/preferences.rb +2 -0
- data/lib/solidus_jwt/version.rb +3 -1
- data/solidus_jwt.gemspec +3 -1
- data/spec/lib/solidus_jwt/config_spec.rb +2 -0
- data/spec/lib/solidus_jwt/devise_strategies/password_spec.rb +2 -0
- data/spec/lib/solidus_jwt/devise_strategies/refresh_token_spec.rb +2 -0
- data/spec/lib/solidus_jwt/preferences_spec.rb +2 -0
- data/spec/lib/solidus_jwt_spec.rb +2 -0
- data/spec/models/solidus_jwt/token_spec.rb +2 -0
- data/spec/requests/spree/api/json_web_tokens_spec.rb +4 -2
- data/spec/requests/spree/api/oauths_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/shared_examples/decodeable_examples.rb +2 -0
- data/spec/support/shared_examples/encodeable_examples.rb +2 -0
- metadata +12 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5069a0d35cb2f777cae543265907fdd284e8e42ccb0e86c8bc4775e17beb6a88
|
4
|
+
data.tar.gz: 1019df1fc49a245eb54d5b64e1f52956a405c4f4f1003a043d65d81b871d672a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b042053167cadec496c99b501b12ada4a3090ea7163afa15718a768b9b01ab822ff8a6f139ffd8c93377525d26b0c83917acb19944ad485b161dd5162a14f1bf
|
7
|
+
data.tar.gz: c8266151ccbd5d50042c289e1ccd2993854dc305e364576489d08a38ab0a0b42166a93a1ac454aac438f306cb46785055cca600003c50bbdf1f8eadd288e72fa
|
data/.gem_release.yml
CHANGED
data/.rubocop.yml
CHANGED
@@ -6,26 +6,9 @@ AllCops:
|
|
6
6
|
- sandbox/**/*
|
7
7
|
- spec/dummy/**/*
|
8
8
|
|
9
|
-
Style/FrozenStringLiteralComment:
|
10
|
-
Enabled: false
|
11
|
-
|
12
|
-
Naming/PredicateName:
|
13
|
-
Exclude:
|
14
|
-
- app/decorators/solidus_kits/spree/stock/availability_validator_decorator.rb
|
15
|
-
|
16
9
|
Metrics/LineLength:
|
17
10
|
Enabled: false
|
18
11
|
|
19
|
-
Rails/SkipsModelValidations:
|
20
|
-
Exclude:
|
21
|
-
- 'spec/**/*'
|
22
|
-
|
23
|
-
RSpec/BeforeAfterAll:
|
24
|
-
Enabled: false
|
25
|
-
|
26
|
-
RSpec/ContextWording:
|
27
|
-
Enabled: false
|
28
|
-
|
29
12
|
RSpec/MultipleExpectations:
|
30
13
|
Enabled: false
|
31
14
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -111,6 +111,19 @@ You can now use the `access_token` to authentication with the
|
|
111
111
|
[Solidus API](https://github.com/solidusio/solidus/tree/master/api) in place
|
112
112
|
of the `spree_api_key`.
|
113
113
|
|
114
|
+
#### Matching token to a user
|
115
|
+
|
116
|
+
By default, the token matches a user using the `Spree::User.for_jwt` method. This methods
|
117
|
+
Finds a user by id using the subject claim of the token. If you want to customize how the
|
118
|
+
subject claim is interpreted you can override this method
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
def self.for_jwt(sub)
|
122
|
+
# find_by(id: sub)
|
123
|
+
find_by(my_external_id: sub)
|
124
|
+
end
|
125
|
+
```
|
126
|
+
|
114
127
|
### Obtain a refresh token
|
115
128
|
|
116
129
|
To refresh your access token, instead of re-authenticating you can send
|
data/app/decorators/{solidus_jwt → controllers/solidus_jwt}/spree/api/base_controller_decorator.rb
RENAMED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SolidusJwt
|
2
4
|
module Spree
|
3
5
|
module Api
|
@@ -16,7 +18,7 @@ module SolidusJwt
|
|
16
18
|
return super if json_web_token.blank?
|
17
19
|
|
18
20
|
# rubocop:disable Naming/MemoizedInstanceVariableName
|
19
|
-
@current_api_user ||= ::Spree.user_class.
|
21
|
+
@current_api_user ||= ::Spree.user_class.for_jwt(json_web_token['sub'] || json_web_token['id'])
|
20
22
|
# rubocop:enable Naming/MemoizedInstanceVariableName
|
21
23
|
end
|
22
24
|
|
@@ -1,10 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SolidusJwt
|
2
4
|
module Spree
|
3
5
|
module UserDecorator
|
4
6
|
def self.prepended(base)
|
7
|
+
base.extend ClassMethods
|
5
8
|
base.has_many :auth_tokens, class_name: 'SolidusJwt::Token'
|
6
9
|
end
|
7
10
|
|
11
|
+
module ClassMethods
|
12
|
+
##
|
13
|
+
# Find user based on subject claim in
|
14
|
+
# our json web token
|
15
|
+
# @see https://tools.ietf.org/html/rfc7519#section-4.1.2
|
16
|
+
#
|
17
|
+
# @example get user token
|
18
|
+
# payload = SolidusJwt.decode(token).first
|
19
|
+
# user = Spree::User.for_jwt(payload['sub'])
|
20
|
+
#
|
21
|
+
# @param sub [string] The subject claim of jwt
|
22
|
+
# @return [Spree.user_class, NilClass] If a match is found, returns the user,
|
23
|
+
# otherwise, returns nil
|
24
|
+
#
|
25
|
+
def for_jwt(sub)
|
26
|
+
find_by(id: sub)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
8
30
|
##
|
9
31
|
# Generate a json web token
|
10
32
|
# @see https://github.com/jwt/ruby-jwt
|
data/bin/r
ADDED
data/bin/rails
CHANGED
@@ -1,18 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
Dir.chdir "#{__dir__}/.." do
|
10
|
-
system "#{__dir__}/sandbox" or begin # rubocop:disable Style/AndOr
|
11
|
-
warn 'Automatic creation of the sandbox app failed'
|
12
|
-
exit 1
|
13
|
-
end
|
14
|
-
end
|
4
|
+
if %w[g generate].include? ARGV.first
|
5
|
+
exec "#{__dir__}/rails-engine", *ARGV
|
6
|
+
else
|
7
|
+
exec "#{__dir__}/rails-sandbox", *ARGV
|
15
8
|
end
|
16
|
-
|
17
|
-
Dir.chdir app_root
|
18
|
-
exec 'bin/rails', *ARGV
|
data/bin/rails-engine
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
5
|
+
# installed from the root of your application.
|
6
|
+
|
7
|
+
ENGINE_ROOT = File.expand_path('..', __dir__)
|
8
|
+
ENGINE_PATH = File.expand_path('../lib/solidus_jwt/engine', __dir__)
|
9
|
+
|
10
|
+
# Set up gems listed in the Gemfile.
|
11
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
12
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
13
|
+
|
14
|
+
require 'rails/all'
|
15
|
+
require 'rails/engine/commands'
|
data/bin/rails-sandbox
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
app_root = 'sandbox'
|
5
|
+
|
6
|
+
unless File.exist? "#{app_root}/bin/rails"
|
7
|
+
warn 'Creating the sandbox app...'
|
8
|
+
Dir.chdir "#{__dir__}/.." do
|
9
|
+
system "#{__dir__}/sandbox" or begin # rubocop:disable Style/AndOr
|
10
|
+
warn 'Automatic creation of the sandbox app failed'
|
11
|
+
exit 1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Dir.chdir app_root
|
17
|
+
exec 'bin/rails', *ARGV
|
data/bin/rake
ADDED
data/bin/sandbox
CHANGED
@@ -53,7 +53,9 @@ gem 'solidus', github: 'solidusio/solidus', branch: '$BRANCH'
|
|
53
53
|
gem 'solidus_auth_devise', '>= 2.1.0'
|
54
54
|
gem 'rails-i18n'
|
55
55
|
gem 'solidus_i18n'
|
56
|
+
|
56
57
|
gem '$extension_name', path: '..'
|
58
|
+
|
57
59
|
group :test, :development do
|
58
60
|
platforms :mri do
|
59
61
|
gem 'pry-byebug'
|
@@ -69,6 +71,7 @@ unbundled bundle exec rails generate spree:install \
|
|
69
71
|
--auto-accept \
|
70
72
|
--user_class=Spree::User \
|
71
73
|
--enforce_available_locales=true \
|
74
|
+
--with-authentication=false \
|
72
75
|
$@
|
73
76
|
|
74
77
|
unbundled bundle exec rails generate solidus:auth:install
|
@@ -78,4 +81,4 @@ echo "🚀 Sandbox app successfully created for $extension_name!"
|
|
78
81
|
echo "🚀 Using $RAILSDB and Solidus $BRANCH"
|
79
82
|
echo "🚀 Use 'export DB=[postgres|mysql|sqlite]' to control the DB adapter"
|
80
83
|
echo "🚀 Use 'export SOLIDUS_BRANCH=<BRANCH-NAME>' to control the Solidus version"
|
81
|
-
echo "🚀 This app is intended for test purposes."
|
84
|
+
echo "🚀 This app is intended for test purposes."
|
data/bin/sandbox_rails
ADDED
data/config/routes.rb
CHANGED
data/lib/solidus_jwt.rb
CHANGED
data/lib/solidus_jwt/config.rb
CHANGED
data/lib/solidus_jwt/engine.rb
CHANGED
data/lib/solidus_jwt/version.rb
CHANGED
data/solidus_jwt.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'lib/solidus_jwt/version'
|
2
4
|
|
3
5
|
Gem::Specification.new do |s|
|
@@ -29,7 +31,7 @@ Gem::Specification.new do |s|
|
|
29
31
|
s.add_dependency 'jwt'
|
30
32
|
s.add_dependency 'solidus_auth_devise'
|
31
33
|
s.add_dependency 'solidus_core', ['>= 2.0.0', '< 3']
|
32
|
-
s.add_dependency 'solidus_support', '~> 0.
|
34
|
+
s.add_dependency 'solidus_support', '~> 0.5.0'
|
33
35
|
|
34
36
|
s.add_development_dependency 'byebug'
|
35
37
|
s.add_development_dependency 'solidus_dev_support'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'spree/testing_support/factories/user_factory'
|
3
5
|
|
@@ -46,11 +48,11 @@ RSpec.describe 'SolidusJwt Authentication', type: :request do
|
|
46
48
|
end
|
47
49
|
|
48
50
|
context 'when spree api key is not allowed' do
|
49
|
-
before
|
51
|
+
before do
|
50
52
|
SolidusJwt::Config.allow_spree_api_key = false
|
51
53
|
end
|
52
54
|
|
53
|
-
after
|
55
|
+
after do
|
54
56
|
SolidusJwt::Config.allow_spree_api_key = true
|
55
57
|
end
|
56
58
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_jwt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taylor Scott
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|
@@ -64,14 +64,14 @@ dependencies:
|
|
64
64
|
requirements:
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: 0.
|
67
|
+
version: 0.5.0
|
68
68
|
type: :runtime
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: 0.
|
74
|
+
version: 0.5.0
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: byebug
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,19 +120,24 @@ files:
|
|
120
120
|
- README.md
|
121
121
|
- Rakefile
|
122
122
|
- _config.yml
|
123
|
-
- app/controllers/spree/api/
|
124
|
-
- app/decorators/solidus_jwt/spree/
|
125
|
-
- app/decorators/solidus_jwt/spree/user_decorator.rb
|
123
|
+
- app/decorators/controllers/solidus_jwt/spree/api/base_controller_decorator.rb
|
124
|
+
- app/decorators/models/solidus_jwt/spree/user_decorator.rb
|
126
125
|
- app/models/solidus_jwt/base_record.rb
|
127
126
|
- app/models/solidus_jwt/token.rb
|
128
127
|
- bin/console
|
128
|
+
- bin/r
|
129
129
|
- bin/rails
|
130
|
+
- bin/rails-engine
|
131
|
+
- bin/rails-sandbox
|
132
|
+
- bin/rake
|
130
133
|
- bin/sandbox
|
134
|
+
- bin/sandbox_rails
|
131
135
|
- bin/setup
|
132
136
|
- config/locales/en.yml
|
133
137
|
- config/routes.rb
|
134
138
|
- db/migrate/20190222220038_create_solidus_jwt_tokens.rb
|
135
139
|
- db/migrate/20191212083655_add_foreign_key_to_users_table.rb
|
140
|
+
- lib/controllers/api/spree/api/oauths_controller.rb
|
136
141
|
- lib/generators/solidus_jwt/install/install_generator.rb
|
137
142
|
- lib/solidus_jwt.rb
|
138
143
|
- lib/solidus_jwt/concerns/decodeable.rb
|