solidus_jwt 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +35 -0
- data/.gem_release.yml +5 -0
- data/.github/CODEOWNERS +4 -0
- data/.github/stale.yml +17 -0
- data/.gitignore +19 -0
- data/.rspec +1 -0
- data/.rubocop.yml +33 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +31 -0
- data/Rakefile +4 -28
- data/_config.yml +1 -0
- data/app/controllers/spree/api/oauths_controller.rb +12 -5
- data/app/decorators/solidus_jwt/spree/api/base_controller_decorator.rb +39 -0
- data/app/decorators/solidus_jwt/spree/user_decorator.rb +36 -0
- data/app/models/solidus_jwt/base_record.rb +11 -0
- data/app/models/solidus_jwt/token.rb +17 -4
- data/bin/console +17 -0
- data/bin/rails +18 -0
- data/bin/sandbox +81 -0
- data/bin/setup +8 -0
- data/config/locales/en.yml +2 -1
- data/db/migrate/20191212083655_add_foreign_key_to_users_table.rb +5 -0
- data/lib/generators/solidus_jwt/install/install_generator.rb +1 -11
- data/lib/solidus_jwt.rb +2 -0
- data/lib/solidus_jwt/concerns/decodeable.rb +5 -1
- data/lib/solidus_jwt/concerns/encodeable.rb +12 -2
- data/lib/solidus_jwt/devise_strategies/base.rb +23 -0
- data/lib/solidus_jwt/devise_strategies/password.rb +5 -11
- data/lib/solidus_jwt/devise_strategies/refresh_token.rb +7 -10
- data/lib/solidus_jwt/distributor/devise.rb +1 -1
- data/lib/solidus_jwt/engine.rb +6 -12
- data/lib/solidus_jwt/version.rb +1 -9
- data/solidus_jwt.gemspec +36 -0
- data/spec/lib/solidus_jwt/concerns/decodeable_spec.rb +0 -0
- data/spec/lib/solidus_jwt/concerns/encodeable_spec.rb +0 -0
- data/spec/lib/solidus_jwt/config_spec.rb +5 -0
- data/spec/lib/solidus_jwt/devise_strategies/password_spec.rb +76 -0
- data/spec/lib/solidus_jwt/devise_strategies/refresh_token_spec.rb +72 -0
- data/spec/lib/solidus_jwt/preferences_spec.rb +37 -0
- data/spec/lib/solidus_jwt_spec.rb +6 -0
- data/spec/models/solidus_jwt/token_spec.rb +41 -0
- data/spec/requests/spree/api/json_web_tokens_spec.rb +75 -0
- data/spec/requests/spree/api/oauths_spec.rb +120 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/shared_examples/decodeable_examples.rb +21 -0
- data/spec/support/shared_examples/encodeable_examples.rb +27 -0
- metadata +65 -227
- data/app/assets/javascripts/spree/backend/solidus_jwt.js +0 -2
- data/app/assets/javascripts/spree/frontend/solidus_jwt.js +0 -2
- data/app/assets/stylesheets/spree/backend/solidus_jwt.css +0 -4
- data/app/assets/stylesheets/spree/frontend/solidus_jwt.css +0 -4
- data/app/controllers/spree/api/base_controller/json_web_tokens.rb +0 -22
- data/app/controllers/spree/api/base_controller_decorator.rb +0 -17
- data/app/models/application_record.rb +0 -3
- data/app/models/solidus_jwt/application_record.rb +0 -9
- data/app/models/spree/user_decorator.rb +0 -34
@@ -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,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
|