-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add docs for using builtin auth mechanism #10719
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
base: master
Are you sure you want to change the base?
Add docs for using builtin auth mechanism #10719
Conversation
04ec47d
to
bfa5410
Compare
bfa5410
to
b9c3c6e
Compare
In addition to discoverability of the authentication mechanism being low, there also appears to be misleading information in the relevant documentation. The I can only see the authentication handshake happen between a client peer and the server, and once the authentication with the server has completed, I'm not terribly familiar with the godot source code, but that also appears to be what is happening. Ideally the previously mentioned documentation can also be updated as part of this PR to make the entire mechanism more clear. |
# signal to the MultiplayerAPI that the authentication was successful | ||
multiplayer.complete_auth(peer_id) | ||
|
||
As soon as both, the client's and the the server's :ref:`complete_auth() <class_SceneMultiplayer_method_complete_auth>`, have been called, the connection is considered to be established and the `connected_to_server` and `peer_connected` signals fire. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As soon as both, the client's and the the server's :ref:`complete_auth() <class_SceneMultiplayer_method_complete_auth>`, have been called, the connection is considered to be established and the `connected_to_server` and `peer_connected` signals fire. | |
As soon as both, the client's and the server's :ref:`complete_auth() <class_SceneMultiplayer_method_complete_auth>`, | |
have been called, the connection is considered to be established and the | |
`connected_to_server` and `peer_connected` signals fire. |
Before hosting your game online to a public audience, you may want to consider adding authentication and protecting your RPCs against unauthenticated access. | ||
For this you can use the :ref:`SceneMultiplayer <class_SceneMultiplayer>`'s builtin authentication mechanism. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before hosting your game online to a public audience, you may want to consider adding authentication and protecting your RPCs against unauthenticated access. | |
For this you can use the :ref:`SceneMultiplayer <class_SceneMultiplayer>`'s builtin authentication mechanism. | |
Before hosting your game online to a public audience, you may want to consider adding authentication and protecting your RPCs against unauthenticated access. | |
You can use the :ref:`SceneMultiplayer <class_SceneMultiplayer>`'s builtin authentication mechanism for this. |
.. tabs:: | ||
.. code-tab:: gdscript GDScript | ||
|
||
# after multiplayer.multiplayer_peer = peer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# after multiplayer.multiplayer_peer = peer | |
# This goes after `multiplayer.multiplayer_peer = peer`. |
multiplayer.auth_timout = 3 | ||
multiplayer.auth_callback = func(peer_id: int, payload: PackedByteArray): | ||
var auth_data: Dictionary = JSON.parse_string(payload.get_string_from_utf8()) | ||
# your authentication logic goes here... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# your authentication logic goes here... | |
# Your authentication logic (such as checking the supplied username/password against a database) | |
# goes here. |
var auth_data: Dictionary = JSON.parse_string(payload.get_string_from_utf8()) | ||
# your authentication logic goes here... | ||
|
||
# signal to the MultiplayerAPI that the authentication was successful |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Signal" may be confused with emitting a signal here.
# signal to the MultiplayerAPI that the authentication was successful | |
# Tell the MultiplayerAPI that the authentication was successful. |
.. tabs:: | ||
.. code-tab:: gdscript GDScript | ||
|
||
# after multiplayer.multiplayer_peer = peer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# after multiplayer.multiplayer_peer = peer | |
# This goes after `multiplayer.multiplayer_peer = peer`. |
|
||
# after multiplayer.multiplayer_peer = peer | ||
multiplayer.auth_callback = func: | ||
# we have to set this on the client in order for the peer_authenticating signal to fire |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# we have to set this on the client in order for the peer_authenticating signal to fire | |
# We have to set this on the client for the `peer_authenticating` | |
# signal to emit. |
} | ||
multiplayer.send_auth(1, JSON.stringify(auth_data).to_utf8_buffer()) | ||
|
||
# signal to the MultiplayerAPI that the authentication was successful |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# signal to the MultiplayerAPI that the authentication was successful | |
# Tell the MultiplayerAPI that the authentication was successful. |
Took a huge unnecessary detour, today. it was an upstream battle...
Since there was no mention of it whatsoever, I intuitively concluded that I would have to build my own authentication on top of
SceneMultiplayer
. The authentication part was easy, but when trying to figure out how to hook into Godot's RPC call-stack to prevent unauthenticated RPC calls, I got stuck and was made aware ofSceneMultiplayer.auth_callback
by Discord.Getting the builtin auth mechanism to work with the available docs on
SceneMultiplayer
was an upstream battle.But the main issue to me, is the complete lack of mentioning the availability of the builtin auth mechanism, at all.
Wanted to share my results and prevent others from having to take the same detour.