From b860827787d5663472b822e58fa06d2adc9bee03 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 6 Mar 2025 12:06:21 -0700 Subject: refactor: connect twirp client/server components to rack --- bin/api | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'bin/api') diff --git a/bin/api b/bin/api index 1a47d14..0330dc8 100755 --- a/bin/api +++ b/bin/api @@ -12,6 +12,7 @@ gemfile do gem "rack", "~> 3.0" gem "rackup", "~> 2.0" gem "securerandom", "~> 0.1" + gem "twirp", "~> 1.0" gem "webrick", "~> 1.0" end @@ -79,12 +80,21 @@ class API def authorized?(request, permission) # TODO:: Check the JWT for the appropriate claim # Connect to the Authz RPC endpoint Ability.allowed?(subject, permission, resource) - client = ::Authx::Rpc::Ability::Stub.new('localhost:50051', :this_channel_is_insecure) # TODO:: memorize client - reply = client.allowed(::Authx::Rpc::AllowRequest.new(subject: "", permission: permission, resource: "")) - puts "***" * 10 - puts reply.inspect - puts "***" * 10 - reply&.result + if twirp? + client = ::Authx::Rpc::AbilityClient.new("http://idp.example.com:8080/twirp") + response = client.allowed(subject: "", permission: permission, resource: "") + puts response.inspect + response&.error&.nil? && response&.data&.result + else + client = ::Authx::Rpc::Ability::Stub.new('localhost:50051', :this_channel_is_insecure) # TODO:: memorize client + reply = client.allowed(::Authx::Rpc::AllowRequest.new(subject: "", permission: permission, resource: "")) + puts reply.inspect + reply&.result + end + end + + def twirp? + true end def json_not_found -- cgit v1.2.3