Class: Himari::Decisions::Authorization

Inherits:
Base
  • Object
show all
Defined in:
lib/himari/decisions/authorization.rb

Defined Under Namespace

Classes: Context

Constant Summary collapse

DEFAULT_ALLOWED_CLAIMS =
%i(
  sub
  name
  nickname
  preferred_username
  profile
  picture
  website
  email
  email_verified
)

Instance Attribute Summary collapse

Attributes inherited from Base

#effect, #effect_comment, #effect_suggestion, #effect_user_facing_message, #rule_name

Instance Method Summary collapse

Methods inherited from Base

#allow!, allow_effects, #continue!, #decide!, #deny!, #evolve, #set_rule_name, #skip!, #to_h, valid_effects

Constructor Details

#initialize(claims: {}, allowed_claims: DEFAULT_ALLOWED_CLAIMS, lifetime: 3600) ⇒ Authorization

Returns a new instance of Authorization.



23
24
25
26
27
28
# File 'lib/himari/decisions/authorization.rb', line 23

def initialize(claims: {}, allowed_claims: DEFAULT_ALLOWED_CLAIMS, lifetime: 3600)
  super()
  @claims = claims
  @allowed_claims = allowed_claims
  self.lifetime = lifetime
end

Instance Attribute Details

#allowed_claimsObject (readonly)

Returns the value of attribute allowed_claims.



30
31
32
# File 'lib/himari/decisions/authorization.rb', line 30

def allowed_claims
  @allowed_claims
end

#claimsObject (readonly)

Returns the value of attribute claims.



30
31
32
# File 'lib/himari/decisions/authorization.rb', line 30

def claims
  @claims
end

#lifetimeObject

Returns the value of attribute lifetime.



31
32
33
# File 'lib/himari/decisions/authorization.rb', line 31

def lifetime
  @lifetime
end

Instance Method Details

#as_logObject



50
51
52
# File 'lib/himari/decisions/authorization.rb', line 50

def as_log
  to_h.merge(claims: output_claims, lifetime: @lifetime.to_h)
end

#output_claimsObject



54
55
56
# File 'lib/himari/decisions/authorization.rb', line 54

def output_claims
  claims.select { |k,_v| allowed_claims.include?(k) }
end

#to_evolve_argsObject



42
43
44
45
46
47
48
# File 'lib/himari/decisions/authorization.rb', line 42

def to_evolve_args
  {
    claims: @claims.dup,
    allowed_claims: @allowed_claims.dup,
    lifetime: @lifetime,
  }
end