New to Ory and to OAuth2 in general. I have read a...
# talk-hydra
b
New to Ory and to OAuth2 in general. I have read all the documentation and trying to configure simple app using express. I followed the example for integrating OAuth2 and it works fine, I can login and the browser shows the access_token, refresh_token, etc. However, when I attempt to also verify the session, it always tells me the session is not valid. I am using the example from the quickstart for identities. I have tried debugging this down into the @ory/client package and it appears that all the cookies I received are being passed back. It always fails to find the session despite me being able to see it in the Ory console as active. I am totally out of ideas on what I am doing wrong. Please help
Copy code
app.get("/", requiresAuth(), (req, res) => {

  // From the quickstart identitiy section
  // Always fails
   ory
    .toSession({ cookie: req.header("cookie") })
    .then(({ data: session }) => {
       console.log("************ All good with Ory ****************");
     })
    .catch((err) => {
       console.log("************* Not so good with Ory ***********");
       console.dir(err.data);
       //res.redirect("/.ory/ui/login")
    })

  // From the quickstart OAuth2/OIDC section
  // Shows tokens
   req.oidc.fetchUserInfo().then((userInfo) => {
    res.send(
     `<html lang='en'><body><pre><code>${JSON.stringify(
      {
       accessToken: req.oidc.accessToken,
       refreshToken: req.oidc.refreshToken,
       idToken: req.oidc.idToken,
       idTokenClaims: req.oidc.idTokenClaims,
       userInfo,
      },
      null,
      2,
     )}</code></pre></body></html>`,
    )
   })
})