Class: Himari::Services::DownstreamAuthorization
- Inherits:
-
Object
- Object
- Himari::Services::DownstreamAuthorization
- Defined in:
- lib/himari/services/downstream_authorization.rb
Defined Under Namespace
Classes: ForbiddenError, Result
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(session:, client:, request: nil, authz_rules: [], logger: nil) ⇒ DownstreamAuthorization
constructor
A new instance of DownstreamAuthorization.
- #perform ⇒ Object
Constructor Details
#initialize(session:, client:, request: nil, authz_rules: [], logger: nil) ⇒ DownstreamAuthorization
Returns a new instance of DownstreamAuthorization.
41 42 43 44 45 46 47 |
# File 'lib/himari/services/downstream_authorization.rb', line 41 def initialize(session:, client:, request: nil, authz_rules: [], logger: nil) @session = session @client = client @request = request @authz_rules = authz_rules @logger = logger end |
Class Method Details
.from_request(session:, client:, request:) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/himari/services/downstream_authorization.rb', line 52 def self.from_request(session:, client:, request:) new( session: session, client: client, request: request, authz_rules: Himari::ProviderChain.new(request.env[Himari::Middlewares::AuthorizationRule::RACK_KEY] || []).collect, logger: request.env['rack.logger'], ) end |
Instance Method Details
#perform ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/himari/services/downstream_authorization.rb', line 62 def perform context = Himari::Decisions::Authorization::Context.new(claims: @session.claims, user_data: @session.user_data, request: @request, client: @client).freeze = Himari::RuleProcessor.new(context, Himari::Decisions::Authorization.new(claims: @session.claims.dup)).run(@authz_rules) raise ForbiddenError.new(Result.new(@client, nil, nil, )) unless .allowed claims = .decision.output_claims lifetime = .decision.lifetime Result.new(@client, claims, lifetime, ) end |