Module: Sorcery::Model::Submodules::Jwt

Defined in:
lib/sorcery/model/submodules/jwt.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sorcery/model/submodules/jwt.rb', line 8

def self.included(base)
  # Define the jwt accessors on the config instance's singleton class;
  # Config#class_eval is not a valid Ruby call.
  base.sorcery_config.singleton_class.class_eval do
    # Secret used to encode JWTs. Should correspond to the type needed by the algorithm used.
    attr_accessor :jwt_secret
    # Type of the algorithm used to encode JWTs. Corresponds to the options available in jwt/ruby-jwt.
    attr_accessor :jwt_algorithm
    # How long the session should be valid for in seconds. Will be set as the exp claim in the token.
    attr_accessor :session_expiry
    # Clock-skew tolerance in seconds applied when verifying exp. nil disables leeway.
    attr_accessor :exp_leeway
  end

  base.sorcery_config.instance_eval do
    @defaults[:@jwt_algorithm] = "HS256"
    @defaults[:@session_expiry] = 60 * 60 * 24 * 7 * 2 # 2 weeks
    @defaults[:@exp_leeway] = nil

    reset!
  end

  base.sorcery_config.after_config << :validate_secret_defined

  base.extend(ClassMethods)
end