module JWTSessions
Constants
- DEFAULT_ACCESS_COOKIE
- DEFAULT_ACCESS_EXP_TIME
- DEFAULT_ACCESS_HEADER
- DEFAULT_ALGORITHM
- DEFAULT_CSRF_HEADER
- DEFAULT_REDIS_DB_NAME
- DEFAULT_REDIS_HOST
- DEFAULT_REDIS_PORT
- DEFAULT_REFRESH_COOKIE
- DEFAULT_REFRESH_EXP_TIME
- DEFAULT_REFRESH_HEADER
- DEFAULT_SETTINGS_KEYS
- DEFAULT_TOKEN_PREFIX
- JWTOptions
- NONE
- VERSION
Attributes
redis_url[RW]
Public Instance Methods
access_expiration()
click to toggle source
# File lib/jwt_sessions.rb, line 131 def access_expiration Time.now.to_i + access_exp_time.to_i end
algorithm()
click to toggle source
# File lib/jwt_sessions.rb, line 77 def algorithm @algorithm ||= DEFAULT_ALGORITHM end
algorithm=(algo)
click to toggle source
# File lib/jwt_sessions.rb, line 72 def algorithm=(algo) raise Errors::Malconfigured, "algorithm #{algo} is not supported" unless supported_algos.include?(algo) @algorithm = algo end
custom_access_expiration(time)
click to toggle source
# File lib/jwt_sessions.rb, line 139 def custom_access_expiration(time) Time.now.to_i + (time || access_exp_time).to_i end
custom_refresh_expiration(time)
click to toggle source
# File lib/jwt_sessions.rb, line 143 def custom_refresh_expiration(time) Time.now.to_i + (time || refresh_exp_time).to_i end
encryption_key=(key)
click to toggle source
should be used for hmac only
# File lib/jwt_sessions.rb, line 126 def encryption_key=(key) @public_key = key @private_key = key end
header_by(token_type)
click to toggle source
# File lib/jwt_sessions.rb, line 147 def header_by(token_type) send("#{token_type}_header") end
jwt_options()
click to toggle source
# File lib/jwt_sessions.rb, line 68 def jwt_options @jwt_options ||= JWTOptions.new(*JWT::DefaultOptions::DEFAULT_OPTIONS.values) end
refresh_expiration()
click to toggle source
# File lib/jwt_sessions.rb, line 135 def refresh_expiration Time.now.to_i + refresh_exp_time.to_i end
token_store()
click to toggle source
# File lib/jwt_sessions.rb, line 88 def token_store unless instance_variable_defined?(:@token_store) begin self.token_store = :redis rescue LoadError warn <<~MSG Warning! JWTSessions uses in-memory token store. Unless token store is specified explicitly, JWTSessions uses Redis by default and fallbacks to in-memory token store. To get rid of this message specify the memory store explicitly in the settings or make sure 'redis' gem is present in your Gemfile. MSG self.token_store = :memory end end @token_store end
token_store=(args)
click to toggle source
# File lib/jwt_sessions.rb, line 81 def token_store=(args) adapter, options = Array(args) @token_store = StoreAdapters.build_by_name(adapter, options) rescue NameError => e raise e.class, "Token store adapter for :#{adapter} haven't been found", e.backtrace end
validate?()
click to toggle source
# File lib/jwt_sessions.rb, line 107 def validate? algorithm != NONE end
Private Instance Methods
supported_algos()
click to toggle source
# File lib/jwt_sessions.rb, line 157 def supported_algos algos = JWT::Algos::ALGOS - [JWT::Algos::Unsupported] algos.map { |algo| algo::SUPPORTED }.flatten + [NONE] end