Module: Blacklight::TokenBasedUser
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/controllers/concerns/blacklight/token_based_user.rb
Instance Method Summary collapse
-
#decrypt_user_id(encrypted_user_id) ⇒ Object
protected
Used for #export action, with encrypted user_id.
-
#encrypt_user_id(user_id, current_time = nil) ⇒ Object
protected
Used for #export action with encrypted user_id, available as a helper method for views.
- #export_secret_token ⇒ Object protected
- #message_encryptor ⇒ Object protected
- #secret_key_generator ⇒ Object protected
- #token_or_current_or_guest_user ⇒ Object protected
- #token_user ⇒ Object protected
Instance Method Details
#decrypt_user_id(encrypted_user_id) ⇒ Object (protected)
Used for #export action, with encrypted user_id.
29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/concerns/blacklight/token_based_user.rb', line 29 def decrypt_user_id(encrypted_user_id) user_id, = .decrypt_and_verify(encrypted_user_id) if < 1.hour.ago raise Blacklight::Exceptions::ExpiredSessionToken end user_id end |
#encrypt_user_id(user_id, current_time = nil) ⇒ Object (protected)
Used for #export action with encrypted user_id, available as a helper method for views.
41 42 43 44 |
# File 'app/controllers/concerns/blacklight/token_based_user.rb', line 41 def encrypt_user_id(user_id, current_time = nil) current_time ||= Time.zone.now .encrypt_and_sign([user_id, current_time]) end |
#export_secret_token ⇒ Object (protected)
46 47 48 |
# File 'app/controllers/concerns/blacklight/token_based_user.rb', line 46 def export_secret_token secret_key_generator.generate_key('encrypted user session key')[0..(key_len - 1)] end |
#message_encryptor ⇒ Object (protected)
65 66 67 |
# File 'app/controllers/concerns/blacklight/token_based_user.rb', line 65 def ActiveSupport::MessageEncryptor.new(export_secret_token) end |
#secret_key_generator ⇒ Object (protected)
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/concerns/blacklight/token_based_user.rb', line 50 def secret_key_generator @secret_key_generator ||= begin app = Rails.application secret_key_base = if app.respond_to?(:credentials) # Rails 5.2+ app.credentials.secret_key_base else # Rails <= 5.1 app.secrets.secret_key_base end ActiveSupport::KeyGenerator.new(secret_key_base) end end |
#token_or_current_or_guest_user ⇒ Object (protected)
17 18 19 |
# File 'app/controllers/concerns/blacklight/token_based_user.rb', line 17 def token_or_current_or_guest_user token_user || current_or_guest_user end |
#token_user ⇒ Object (protected)
21 22 23 24 25 26 |
# File 'app/controllers/concerns/blacklight/token_based_user.rb', line 21 def token_user @token_user ||= if params[:encrypted_user_id] user_id = decrypt_user_id params[:encrypted_user_id] User.find(user_id) end end |