Open
Description
Preflight checklist
- I could not find a solution in the existing issues, docs, nor discussions.
- I agree to follow this project's Code of Conduct.
- I have read and am following this repository's Contribution Guidelines.
- This issue affects my Ory Cloud project.
- I have joined the Ory Community Slack.
- I am signed up to the Ory Security Patch Newsletter.
Describe the bug
https://www.ory.sh/docs/guides/protect-page-login/expressjs#require-login-to-access-the-home-page
.toSession
seems to want to make a call to /.ory/.../whoami
through the proxy. However i think axios wants to make this call at localhost port 80, leading to the following error
[0] Error: connect ECONNREFUSED ::1:80
[0] at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
[0] errno: -61,
[0] code: 'ECONNREFUSED',
[0] syscall: 'connect',
[0] address: '::1',
[0] port: 80,
[0] config: {
[0] url: '/.ory/sessions/whoami',
[0] method: 'get',
[0] headers: {
[0] Accept: 'application/json, text/plain, */*',
[0] Cookie: '__cflb=0pg1QYeUHkKyPHC72r3PJ1fj2WK6WMwzqHhgHXum; csrf_token_a5d02dd42b4ef065bbbd5ed674b19b5d2e6dc4f2a3e4acc8684f15ae24c19b97=JGnPuz6b+Jqy10PCRqwvR2dgrw2UXJ1K96SHlDCWSag=; ory_session_greatgoldwasserlbe7q6kfiv=MTY1MDMwMTk3MnxnSmhfWkRBM2lSVkJwX1JpY0oyYUpGV21lbm9jel9PWkl0a2RwVzJ0eGRJT1lLSm9JMlZUUjZyc0xYalJyMS1naC0zS2FleWxaM0lsT0pxMjNSRkRGQVlTbjU2ZUtaYTAxVEQ4MWxoZUlfcFR6Rml3YkM4bE1XdmVQQms3SjhZR0NaQ2UwMklqcXc9PXygWBBkEKzVhZUiBc1uzDEO0KmKCRdEUET-qIkFgs5LkQ==',
So we need to tell axios it should match the port we used when we started the proxy
"dev:proxy": "ory proxy --no-jwt --port 8000 http://localhost:8001/"
some solutions at the doc level
- insist we pass a proxy to axios in development environments
.toSession(undefined, req.header('cookie'), {
proxy: {
host: 'localhost',
port: 8000
}
})
- in development make sure we pass the full base path inclusive of port
const ory = new orySDK.V0alpha2Api(
new orySDK.Configuration(
// @ts-ignore
{basePath: 'http://localhost:8000/.ory',
baseOptions: {
withCredentials: true
}
}
)
)
These both work and i am also wondering
- if there is a way to detect if we are proxying and on what port so this could be done automatically somehow
- perhaps having this as an envar like the sdk url
https://github.com/ory/docs/blob/master/code-examples/protect-page-login/expressjs/routes/index.js
Reproducing the bug
- follow example on https://www.ory.sh/docs/guides/protect-page-login/expressjs
- register a user
- observe redirect loop once user registered due to failing whoami request
Relevant log output
No response
Relevant configuration
No response
Version
"@ory/client": "^0.0.1-alpha.167"
On which operating system are you observing this issue?
macOS
In which environment are you deploying?
Ory Cloud
Additional Context
No response