Class: AuthenticJwt::Authorizer

Inherits:
Object
  • Object
show all
Defined in:
lib/authentic_jwt/authorizer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account_id: ENV["AUTHENTIC_AUTH_ACCOUNT_ID"]) ⇒ Authorizer

Returns a new instance of Authorizer.



3
4
5
6
7
# File 'lib/authentic_jwt/authorizer.rb', line 3

def initialize(account_id: ENV["AUTHENTIC_AUTH_ACCOUNT_ID"])
  unless .to_s.empty?
    @account_id = .to_s
  end
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



9
10
11
# File 'lib/authentic_jwt/authorizer.rb', line 9

def 
  @account_id
end

Instance Method Details

#call(payload:, scope: nil) ⇒ Object



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/authentic_jwt/authorizer.rb', line 11

def call(payload:, scope: nil)
  return unless 

   = payload.accounts.detect { || .aud ==  }

  unless 
    raise Forbidden, "No access to account"
  end

  roles = .roles.collect(&:to_s).collect(&:downcase)

  unless roles.any?
    raise Forbidden, "Account has no roles"
  end

  acceptable_roles = calculate_acceptable_roles(scope: scope)

  unless (acceptable_roles & roles).any?
    raise Forbidden, "Account role is too low"
  end

  true
end