private void RequestAuthentication() { this.state.AuthenticationChallenge = BuildAuthenticationChallenge(); var msgAuthenticationRequest = new ServerAuthenticationRequest() { AuthenticationChallenge = this.state.AuthenticationChallenge }; this.SendFrameToClient(FrameType.ServerAuthenticationRequest, msgAuthenticationRequest.Serialize()); }
private void ProcessAuthenticationRequest(ServerAuthenticationRequest request, string signingKey) { var offlineTokenProvider = new OfflineTokenProvider("", signingKey); string token = offlineTokenProvider.CreateJWTToken(request.AuthenticationChallenge, DateTime.UtcNow.AddMinutes(15)); var cmdClientAuthenticationResponse = new ClientAuthenticationResponse() { AuthenticationToken = token }; ReliableMessaging.OnSendFrame(new UdpTransferFrame(FrameType.ClientAuthenticationResponse, cmdClientAuthenticationResponse.Serialize())); }
/// <summary>Processes the UDP transfer frame.</summary> /// <param name="frame">The frame.</param> private void ProcessUdpTransferFrame(UdpTransferFrame frame) { switch (frame.Type) { case FrameType.ServerAuthenticationRequest: var msgAuthenticationRequest = new ServerAuthenticationRequest(frame.MessageBuffer); ProcessAuthenticationRequest(msgAuthenticationRequest, this.signingKeyBase64); break; case FrameType.ServerHello: SubscribeToDefaultArea(); if (OnConnected != null) { Thread connected = new Thread(() => OnConnected()); connected.Start(); } break; case FrameType.ServerPing: var msgServerPing = new ServerPingMessage(frame.MessageBuffer); var now = TimeSpan.FromTicks(DateTime.UtcNow.Ticks); var cmdClientPong = new ClientPongMessage() { ServerRequestTimestamp = msgServerPing.ServerTimestamp, ClientRequestTimestamp = now, ClientResponseTimestamp = now }; ReliableMessaging.OnSendFrame(new UdpTransferFrame(FrameType.ClientPong, cmdClientPong.Serialize())); break; case FrameType.Message: LastMessageReceived = DateTime.Now; ReliableMessaging.ProcessMessageFrame(frame); break; default: throw new NotImplementedException(frame.Type.ToString()); } }