示例#1
0
        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()));
        }
示例#2
0
        private IActorRef CreateAuthenticatedActor(TestProbe authenticationProbe, TestProbe clientSocketProbe)
        {
            //setup
            const uint   CLIENTID         = 1234567890;
            const string TOKEN            = "TOKEN";
            string       EXPECTEDRESPONSE = $"HELLO {CLIENTID}";

            var testeeRef          = Sys.ActorOf(Props.Create(() => new ClientTwinActor(clientSocketProbe, authenticationProbe, defaultEndpoint, defaultShardRegionArea, defaultObjectRegionArea)));
            var clientHelloMessage = new ClientHelloMessage()
            {
                Message    = string.Empty,
                ClientId   = CLIENTID,
                ClientPort = 9999,
                Version    = Shared.Constants.Version.PROTOCOL,
            };
            var clientAuthenticationResponse = new ClientAuthenticationResponse()
            {
                AuthenticationToken = TOKEN,
            };

            //execute - client hello
            testeeRef.Tell(new UdpTransferFrame(FrameType.ClientHello, clientHelloMessage.Serialize()));

            //verify
            clientSocketProbe.ExpectMsg <Udp.Send>(s =>
            {
                var msg = new UdpTransferFrame(s.Payload.ToArray());
                Assert.Equal(FrameType.ServerAuthenticationRequest, msg.Type);
            });

            //execute - client authentication response
            testeeRef.Tell(new UdpTransferFrame(FrameType.ClientAuthenticationResponse, clientAuthenticationResponse.Serialize()));

            //verify
            authenticationProbe.ExpectMsg <RequestAuthenticationCommand>(c =>
            {
                Assert.Equal(TOKEN, c.Token);
            });

            //execute - authentication actor response
            testeeRef.Tell(new AuthenticationSuccess());

            //verify
            clientSocketProbe.ExpectMsg <Udp.Send>(s =>
            {
                var msg = new UdpTransferFrame(s.Payload.ToArray());
                Assert.Equal(FrameType.ServerHello, msg.Type);
                var serverHello = new ServerHelloMessage(msg.MessageBuffer);
                Assert.Equal(EXPECTEDRESPONSE, serverHello.Message);
                Assert.Equal(clientHelloMessage.Version, serverHello.Version);
            });

            return(testeeRef);
        }