Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: need Request in static onAuth #693

Open
hunkydoryrepair opened this issue Feb 6, 2024 · 6 comments
Open

[Feature]: need Request in static onAuth #693

hunkydoryrepair opened this issue Feb 6, 2024 · 6 comments
Milestone

Comments

@hunkydoryrepair
Copy link
Contributor

Context & Description

with the switch to static onAuth, the biggest issue we face is not being able to access the Request object.
That is needed to get the player IP address.

Use cases

allowing switch to static onAuth for any game that uses the Request object.

Proposed API

pass Request object to the static onAuth as a new parameter.

@endel
Copy link
Member

endel commented Feb 7, 2024

Hi @hunkydoryrepair, thanks for the feedback.

For the uWebSockets transport I had to pass a "mocked" version of the request due to the optimizations uWebSockets does internally pruning the instance. (request is not available on async calls)

So far only the headers are present in that mocked object: 600534c

Can you share how are you currently retrieving the IP address from the uWebSockets' so we can include it as well?

I think this is a good opportunity to start thinking on unifying all transports into a single API. For WebTransport I'm afraid we'll need a similar approach.

The mocked structure would look like this so far:

{
  ip: "xxx.xxx.xxx.xxx",
  headers: {
    key: "value"
  },
}

(Might be a good idea to provide URLs, protocol, paths, etc as well 🤔 )

@endel
Copy link
Member

endel commented Feb 7, 2024

On the regular ws library this is the recommendation we have in the documentation, but I'm afraid it doesn't cover all cases, using behind a proxy and/or different load-balancers:

request.headers['x-forwarded-for'] || request.socket.remoteAddress

@hunkydoryrepair
Copy link
Contributor Author

hunkydoryrepair commented Feb 7, 2024

Sorry, I guess I was referring to an earlier version that did not pass in the request at all (at least, was not documented). Yes, we use x-forwarded-for and the request.connection.remoteAddress...I've never seen a request.socket on the request, so that's odd.

The issue we have remaining is we need the options passed to joinById. We have a lot of data we need to do our authentication in the options passed in:

this.client.joinById( roomId, {
        mapId,
        token: token || 'iamguest',
        isGuest: !token,
        cryptoWallet: {...},
        username,
        world: worldId,
        ver: GAME_CLIENT_VERSION,
        ...spawnParams,
        avatar: !!token || !avatar ? '' : JSON.stringify(avatar),
        lastSavedAt,
        recaptchaKey,
      }

We check bots, require a matching client version, require our own token registered with Stytch, we validate that the player hasn't changed since with authenticated using the save date, etc. We need it all. Switching to static onAuth not an option without the data.

@hunkydoryrepair
Copy link
Contributor Author

We do other checks, too, that require the room state, but those can probably be moved to onJoin

@hunkydoryrepair
Copy link
Contributor Author

can close this. would be nice to have the options in the onAsync, but not required.

@endel endel added this to the 1.0 milestone Feb 12, 2024
@endel endel removed the 👀 triage label Feb 12, 2024
@endel
Copy link
Member

endel commented Feb 12, 2024

Thanks @hunkydoryrepair, let's keep this open for discussion, though - as I think for v1.0 we could provide a unified "request/context" object that is the same for every transport during static onAuth 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants