summaryrefslogtreecommitdiff
path: root/bin/api
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-03-06 12:06:21 -0700
committermo khan <mo@mokhan.ca>2025-03-06 12:06:21 -0700
commitb860827787d5663472b822e58fa06d2adc9bee03 (patch)
treec2760343eedd7481603814b89b1b33e34cc80095 /bin/api
parentbad76558aca0719db95f5572c7847fd971051186 (diff)
refactor: connect twirp client/server components to rack
Diffstat (limited to 'bin/api')
-rwxr-xr-xbin/api22
1 files changed, 16 insertions, 6 deletions
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