Hi! Just joined the slack today and I have a quest...
# talk-keto
a
Hi! Just joined the slack today and I have a question about the Keto nodejs client: I'm trying to run a permission check but my keto proxy on
localhost:3004
is giving me
Copy code
error: {
  code: 401,
  status: 'Unauthorized',
  request: '98aaa3f0-096e-9cbd-91e5-ee148beefcd3',
  message: 'Access credentials are invalid'
}
when I run below code, where
import.meta.env.ORY_PAT
is my personal access token:
Copy code
import keto from "@ory/keto-client";
...
  try {
    const config = new keto.Configuration({
      basePath: "<http://localhost:3004>",
      accessToken: import.meta.env.ORY_PAT,
    });
    const readClient = new keto.ReadApi(config);
    const response = await readClient.getCheck(
      "venues",
      "se-hq-it",
      "assortment:read",
      session.identity.id
    );
  } catch (error: any) {
    console.error(error.response);
  }
...
Anyone have a clue what I'm missing here?
Able to run it through Postman so I'll skip the SDK for now I guess, and just go with
fetch
...
So, I ran into some more confusion. Running below code with my Ory project URL in
import.meta.env.ORY_API_URL
and Ory access token in `import.meta.env.ORY_PAT`:
Copy code
const url = `${import.meta.env.ORY_API_URL}/relation-tuples/check`;
const body = {
  namespace: "venues",
  object: "se-hq-it",
  relation: "assortment:read",
  subject: session.identity.id,
};
const headers = new Headers({
  Authorization: `Bearer ${import.meta.env.ORY_PAT}`,
  "Content-Type": "application/json"
});
const response = await fetch(url, {
  body: JSON.stringify(body),
  headers,
  method: "POST",
});
the request fails with:
Copy code
{
  status: 502,
  statusText: 'Bad Gateway',
}
but the same request via Postman and cUrl works perfectly fine. Any input here is very appreciated.
This is run in
node
, for the record
Here's the cUrl I run which works:
Copy code
curl --location --request POST 'https://{project}.<http://projects.oryapis.com/relation-tuples/check|projects.oryapis.com/relation-tuples/check>' \
--header 'Authorization: Bearer ORY_PAT' \
--header 'Content-Type: application/json' \
--data-raw '{
    "namespace": "venues",
    "object": "se-hq-it",
    "relation": "assortment:read",
    "subject_id": "a79e6e35-029f-4c50-b64f-305308c7eb9d"
}'
s
so are you using
ory proxy
or
ory tunnel
to forward the requests? that should not really be needed as keto is not cookie/browser based
a
I've gone directly to my Cloud project link, as in the cUrl snippet. So those aren't passing through a local proxy, right?
s
it should not give you
Bad Gateway
, but one difference I see is that in the node fetch you have the wrong key,
subject
while in curl you use the right one
subject_id
a
The error I receive is a cloudflare 502 response, so I'm currently investigating if my api, which is run on the server, somehow is identified as a browser call. I'm using Astro SSR api routes
Oh
Would you look at that, switching to subject_id works
s
can you try again? maybe it was just a flake during an upgrade on our side
a
Yeah, malformed (i.e subject) payload responds with a 502 cloudflare error html, but with proper payload (i.e subject_id) it goes through smoothly
s
ok thanks, I'll investigate that error
a
Thanks for the help
s
for the SDK, can you verify you were using the latest version?
a
Sure, using
"@ory/keto-client": "^0.10.0-alpha.0",
s
also we recommend to use https://www.npmjs.com/package/@ory/client for ory cloud, it is the sdks for all ory projects merged and should definitely work with the proper auth
a
Alright, I'll give that a shot
Yeah, @ory/client works.
s
nice 🎉
a
Thanks again! Getting started with this has been slightly... rough around the edges, but I can see you guys working on a bunch of things, makes sense that some documentation falls behind.
Looking forward to getting into Ory more going forward!
I'll also try to make some pull requests for the docs with my findings, when I find the time
s
yeah there is so much to do but only so many hours a day 😅
n
Fix for the 502 is here: https://github.com/ory/keto/pull/1039