Offers a solution to issue #361 (Allow Server.observe with authenticated peer) #365
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
zetta currently allows for peer link authentication using the hooks server.onPeerRequest, server.onPeerResponse, server.httpServer.onPeerConnect, and server.httpServer.onEventWebsocketConnect. This allows an initiating peer to make a link request to a receiving peer. This assumes that any peer wishing to initiate a connection must know the authorization scheme and credentials required for a particular receiver.
However, things are flipped when the receiving peer wishes to establish a connection back to the initiating peer for a Server.observe. In this situation, it should not be assumed that the receiver knows the authorization scheme and credentials for each and every initiator. Since the receiver doesn't know how to authenticate with the initiator, Server.observe fails for that peer.
This can be alieviated if the initiating peer simply passes the authorization scheme and credentials to the receiver in the response to the receiver's _initiate_peer request. The initiator handles the request in the PeerClient.checkServerReq function, and passes back the authorization in the response header. The receiver in PeerSocket.confirmConnection then keeps track of the authorization if it sees x-authorization-required set in header.
This additional code does not affect processing when peer authentication/authorization is not used. The reverse-authorization passing should work for any authorization scheme. One big assumption is that the initiator scheme and credentials will work in reverse -- that's up to the initiator to fulfill, but if not, then it doesn't fail any worse than it does currently.