Access/get-identity returns "could not retrieve identity"

Hello everyone,

Im currently moving a lot of services to Cloudflare. We have a webtool running which we made available via Zero Trust Gateway. This works well. Now i saw the /cdn-cgi/access/get-identity Endpoint to get the User Information which looks promising in the further development of the webapp. For example we could use the email adress to send emails.

I implemented on the backend service of the webapp an rest endpoint.

The rest endpoint is for testing /identity rn and its fetching with the Cf-Access-Jwt-Assertion JWT in the session: CF_Authorization=… header.

Now when I want to access this /identity endpoint which calls the Cloudflare .../access/get-identity endpoint I get the error message could not retrieve identity.

I have no clue whats the problem here.
Could anyone give me some information how I get this up and running?

Thank you and have a beautiful day!
With kind regards

Here is the code snipped. Im using in the Worker.

app.get("/identity", async (c) => {
  const identity = await fetch(
      headers: {
        cookie: `CF_Authorization=${c.req.header("Cf-Access-Jwt-Assertion")!}`,
  return c.json({ identity: await identity.json(), header: c.req.header("Cf-Access-Jwt-Assertion")! });

We typically see this error when the JWT is missing the identity_nonce value. This can occur if you authenticated via a non-identity/service auth method. Could that be the issue here?