solidus_jwt 0.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.
Files changed (67) 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 +16 -0
  9. data/.ruby-gemset +1 -0
  10. data/.ruby-version +1 -0
  11. data/Gemfile +33 -0
  12. data/README.md +71 -2
  13. data/Rakefile +4 -28
  14. data/_config.yml +1 -0
  15. data/app/decorators/controllers/solidus_jwt/spree/api/base_controller_decorator.rb +41 -0
  16. data/app/decorators/models/solidus_jwt/spree/user_decorator.rb +58 -0
  17. data/app/models/solidus_jwt/base_record.rb +13 -0
  18. data/app/models/solidus_jwt/token.rb +63 -0
  19. data/bin/console +17 -0
  20. data/bin/r +9 -0
  21. data/bin/rails +8 -0
  22. data/bin/rails-engine +15 -0
  23. data/bin/rails-sandbox +17 -0
  24. data/bin/rake +7 -0
  25. data/bin/sandbox +84 -0
  26. data/bin/sandbox_rails +9 -0
  27. data/bin/setup +8 -0
  28. data/config/locales/en.yml +2 -1
  29. data/config/routes.rb +3 -0
  30. data/db/migrate/20190222220038_create_solidus_jwt_tokens.rb +14 -0
  31. data/db/migrate/20191212083655_add_foreign_key_to_users_table.rb +7 -0
  32. data/lib/controllers/api/spree/api/oauths_controller.rb +47 -0
  33. data/lib/generators/solidus_jwt/install/install_generator.rb +3 -11
  34. data/lib/solidus_jwt.rb +8 -0
  35. data/lib/solidus_jwt/concerns/decodeable.rb +7 -1
  36. data/lib/solidus_jwt/concerns/encodeable.rb +14 -2
  37. data/lib/solidus_jwt/config.rb +2 -0
  38. data/lib/solidus_jwt/devise_strategies/base.rb +25 -0
  39. data/lib/solidus_jwt/devise_strategies/password.rb +46 -0
  40. data/lib/solidus_jwt/devise_strategies/refresh_token.rb +48 -0
  41. data/lib/solidus_jwt/distributor/devise.rb +3 -1
  42. data/lib/solidus_jwt/engine.rb +8 -12
  43. data/lib/solidus_jwt/factories.rb +13 -0
  44. data/lib/solidus_jwt/preferences.rb +8 -0
  45. data/lib/solidus_jwt/version.rb +3 -9
  46. data/solidus_jwt.gemspec +38 -0
  47. data/spec/lib/solidus_jwt/concerns/decodeable_spec.rb +0 -0
  48. data/spec/lib/solidus_jwt/concerns/encodeable_spec.rb +0 -0
  49. data/spec/lib/solidus_jwt/config_spec.rb +7 -0
  50. data/spec/lib/solidus_jwt/devise_strategies/password_spec.rb +78 -0
  51. data/spec/lib/solidus_jwt/devise_strategies/refresh_token_spec.rb +74 -0
  52. data/spec/lib/solidus_jwt/preferences_spec.rb +39 -0
  53. data/spec/lib/solidus_jwt_spec.rb +8 -0
  54. data/spec/models/solidus_jwt/token_spec.rb +43 -0
  55. data/spec/requests/spree/api/json_web_tokens_spec.rb +77 -0
  56. data/spec/requests/spree/api/oauths_spec.rb +122 -0
  57. data/spec/spec_helper.rb +26 -0
  58. data/spec/support/shared_examples/decodeable_examples.rb +23 -0
  59. data/spec/support/shared_examples/encodeable_examples.rb +29 -0
  60. metadata +86 -222
  61. data/app/assets/javascripts/spree/backend/solidus_jwt.js +0 -2
  62. data/app/assets/javascripts/spree/frontend/solidus_jwt.js +0 -2
  63. data/app/assets/stylesheets/spree/backend/solidus_jwt.css +0 -4
  64. data/app/assets/stylesheets/spree/frontend/solidus_jwt.css +0 -4
  65. data/app/controllers/spree/api/base_controller/json_web_tokens.rb +0 -22
  66. data/app/controllers/spree/api/base_controller_decorator.rb +0 -17
  67. data/app/models/spree/user_decorator.rb +0 -30
@@ -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,30 +0,0 @@
1
- module Spree
2
- module UserDecorator
3
- ##
4
- # Generate a json web token
5
- # @see https://github.com/jwt/ruby-jwt
6
- # @return [String]
7
- #
8
- def generate_jwt(expires_in: nil)
9
- SolidusJwt.encode(payload: as_jwt_payload, expires_in: expires_in)
10
- end
11
- alias generate_jwt_token generate_jwt
12
-
13
- ##
14
- # Serializes user attributes to hash and applies
15
- # the sub jwt claim.
16
- #
17
- # @return [Hash] The payload for json web token
18
- #
19
- def as_jwt_payload
20
- options = SolidusJwt::Config.jwt_options
21
- claims = { sub: id }
22
-
23
- as_json(options)
24
- .merge(claims)
25
- .as_json
26
- end
27
-
28
- Spree.user_class.prepend self
29
- end
30
- end