keycloak / keycloak/keycloak-nodejs-connect
Improve redirect URL making script
- Dominant language
- JavaScript
- Stars
- 740
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
Please improve redirectURL script on forceLogin function to broaden compatibility with other framework beside Express such as Fastify. Currently, it uses `request.hostname` to retrieves hostname and `request.headers.host` to retrieves port number. Unfortunately, it won't work on Fastify Framework because Fastify will assigns same value to `request.headers.host` and `request.hostname` (`host_name:port_number`).
I hope you could retrieves hostname from `request.headers.host` than `request.hostname`, thank you
**Original**
https://github.com/keycloak/keycloak-nodejs-connect/blob/773e95a2fd8b4046cb22f6e3d55853169a81e9a8/middleware/protect.js#L20-L27
**Improvement**
```
let headerHost = request.headers.host.split(':');
let host = headerHost[0];
let port = headerHost[1] || '';
```
For example, my redirect url will become:
localhost:8080/realms/myrealm/protocol/openid-connect/auth?client_id=spc-client&state=ca6cc925-acf7-474b-8057-46ba40e35f88&redirect_uri=http%3A%2F%2F**localhost%3A3000%3A3000**%2Faltair%3Fauth_callback%3D1&scope=openid openid profile email&response_type=code
Contributor guide
Research direction
Start in middleware/protect.js at the forceLogin redirectURL logic referenced by the issue. Review how hostname and port are obtained, then verify the resulting redirect URL for Fastify-style host values while preserving Express compatibility. Done means the host and port are not duplicated in the redirect URL.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- authentication, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100