solidus_jwt 1.0.0 → 1.1.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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +35 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/CODEOWNERS +4 -0
  5. data/.github/stale.yml +17 -0
  6. data/.gitignore +19 -0
  7. data/.rspec +1 -0
  8. data/.rubocop.yml +33 -0
  9. data/.ruby-gemset +1 -0
  10. data/.ruby-version +1 -0
  11. data/Gemfile +31 -0
  12. data/Rakefile +4 -28
  13. data/_config.yml +1 -0
  14. data/app/controllers/spree/api/oauths_controller.rb +12 -5
  15. data/app/decorators/solidus_jwt/spree/api/base_controller_decorator.rb +39 -0
  16. data/app/decorators/solidus_jwt/spree/user_decorator.rb +36 -0
  17. data/app/models/solidus_jwt/base_record.rb +11 -0
  18. data/app/models/solidus_jwt/token.rb +17 -4
  19. data/bin/console +17 -0
  20. data/bin/rails +18 -0
  21. data/bin/sandbox +81 -0
  22. data/bin/setup +8 -0
  23. data/config/locales/en.yml +2 -1
  24. data/db/migrate/20191212083655_add_foreign_key_to_users_table.rb +5 -0
  25. data/lib/generators/solidus_jwt/install/install_generator.rb +1 -11
  26. data/lib/solidus_jwt.rb +2 -0
  27. data/lib/solidus_jwt/concerns/decodeable.rb +5 -1
  28. data/lib/solidus_jwt/concerns/encodeable.rb +12 -2
  29. data/lib/solidus_jwt/devise_strategies/base.rb +23 -0
  30. data/lib/solidus_jwt/devise_strategies/password.rb +5 -11
  31. data/lib/solidus_jwt/devise_strategies/refresh_token.rb +7 -10
  32. data/lib/solidus_jwt/distributor/devise.rb +1 -1
  33. data/lib/solidus_jwt/engine.rb +6 -12
  34. data/lib/solidus_jwt/version.rb +1 -9
  35. data/solidus_jwt.gemspec +36 -0
  36. data/spec/lib/solidus_jwt/concerns/decodeable_spec.rb +0 -0
  37. data/spec/lib/solidus_jwt/concerns/encodeable_spec.rb +0 -0
  38. data/spec/lib/solidus_jwt/config_spec.rb +5 -0
  39. data/spec/lib/solidus_jwt/devise_strategies/password_spec.rb +76 -0
  40. data/spec/lib/solidus_jwt/devise_strategies/refresh_token_spec.rb +72 -0
  41. data/spec/lib/solidus_jwt/preferences_spec.rb +37 -0
  42. data/spec/lib/solidus_jwt_spec.rb +6 -0
  43. data/spec/models/solidus_jwt/token_spec.rb +41 -0
  44. data/spec/requests/spree/api/json_web_tokens_spec.rb +75 -0
  45. data/spec/requests/spree/api/oauths_spec.rb +120 -0
  46. data/spec/spec_helper.rb +24 -0
  47. data/spec/support/shared_examples/decodeable_examples.rb +21 -0
  48. data/spec/support/shared_examples/encodeable_examples.rb +27 -0
  49. metadata +65 -227
  50. data/app/assets/javascripts/spree/backend/solidus_jwt.js +0 -2
  51. data/app/assets/javascripts/spree/frontend/solidus_jwt.js +0 -2
  52. data/app/assets/stylesheets/spree/backend/solidus_jwt.css +0 -4
  53. data/app/assets/stylesheets/spree/frontend/solidus_jwt.css +0 -4
  54. data/app/controllers/spree/api/base_controller/json_web_tokens.rb +0 -22
  55. data/app/controllers/spree/api/base_controller_decorator.rb +0 -17
  56. data/app/models/application_record.rb +0 -3
  57. data/app/models/solidus_jwt/application_record.rb +0 -9
  58. data/app/models/spree/user_decorator.rb +0 -34
@@ -1,2 +0,0 @@
1
- // Placeholder manifest file.
2
- // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/backend/all.js'
@@ -1,2 +0,0 @@
1
- // Placeholder manifest file.
2
- // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/frontend/all.js'
@@ -1,4 +0,0 @@
1
- /*
2
- Placeholder manifest file.
3
- the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/backend/all.css'
4
- */
@@ -1,4 +0,0 @@
1
- /*
2
- Placeholder manifest file.
3
- the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/frontend/all.css'
4
- */
@@ -1,22 +0,0 @@
1
- ##
2
- # Prepend for Spree::Api::BaseController methods
3
- #
4
- module Spree::Api::BaseController::JsonWebTokens
5
- def load_user
6
- return super unless json_web_token.present?
7
-
8
- # rubocop:disable Naming/MemoizedInstanceVariableName
9
- @current_api_user ||= Spree.user_class.find_by(id: json_web_token['id'])
10
- # rubocop:enable Naming/MemoizedInstanceVariableName
11
- end
12
-
13
- def json_web_token
14
- @json_web_token ||= SolidusJwt.decode(api_key).first
15
- rescue JWT::DecodeError
16
- # Allow spree to try and authenticate if we still allow it. Otherwise
17
- # raise an error
18
- return if SolidusJwt::Config.allow_spree_api_key
19
-
20
- raise
21
- end
22
- end
@@ -1,17 +0,0 @@
1
- module Spree
2
- module Api
3
- module BaseControllerDecorator
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- prepend Spree::Api::BaseController::JsonWebTokens
8
-
9
- rescue_from JWT::DecodeError do
10
- render "spree/api/errors/invalid_api_key", status: 401
11
- end
12
- end
13
-
14
- Spree::Api::BaseController.include self
15
- end
16
- end
17
- end
@@ -1,3 +0,0 @@
1
- class ApplicationRecord < ActiveRecord::Base
2
- self.abstract_class = true
3
- end
@@ -1,9 +0,0 @@
1
- module SolidusJwt
2
- class ApplicationRecord < ::ApplicationRecord
3
- self.abstract_class = true
4
-
5
- def self.table_name_prefix
6
- 'solidus_jwt_'
7
- end
8
- end
9
- end
@@ -1,34 +0,0 @@
1
- module Spree
2
- module UserDecorator
3
- def self.prepended(base)
4
- base.has_many :auth_tokens, class_name: 'SolidusJwt::Token'
5
- end
6
-
7
- ##
8
- # Generate a json web token
9
- # @see https://github.com/jwt/ruby-jwt
10
- # @return [String]
11
- #
12
- def generate_jwt(expires_in: nil)
13
- SolidusJwt.encode(payload: as_jwt_payload, expires_in: expires_in)
14
- end
15
- alias generate_jwt_token generate_jwt
16
-
17
- ##
18
- # Serializes user attributes to hash and applies
19
- # the sub jwt claim.
20
- #
21
- # @return [Hash] The payload for json web token
22
- #
23
- def as_jwt_payload
24
- options = SolidusJwt::Config.jwt_options
25
- claims = { sub: id }
26
-
27
- as_json(options)
28
- .merge(claims)
29
- .as_json
30
- end
31
-
32
- Spree.user_class.prepend self
33
- end
34
- end