Beispiel #1
0
        public string Authenticate()
        {
            if (!AuthenticateTokenProvider.Current.IsExpired)
            {
                return(AuthenticateTokenProvider.Current.TokenKey);
            }

            var token = new TokenServiceClient(new WSHttpBinding(SecurityMode.None, true)
            {
                ReceiveTimeout = new TimeSpan(0, 0, 0, 0, _timeout)
            }, new EndpointAddress(_tokenUrl));
            var authenticate = token.Authenticate(GenerateGuid(), Convert.ToInt32(_customerCode), _password);

            Audit("Authenticate" + authenticate);

            var body = authenticate.Element("MsgBody");

            if (body == null)
            {
                AuthenticateTokenProvider.Current =
                    new ErrorToken(authenticate.Element("MsgHeader").Element("Result").ToString());
            }
            else
            {
                var expdate = body.Element("TokenConf").Element("ExpiryDate").Value;
                var key     = body.Element("TokenConf").Element("TokenKey").Value;
                AuthenticateTokenProvider.Current = new SuccessToken(expdate, key);
            }

            return(AuthenticateTokenProvider.Current.TokenKey);
        }
Beispiel #2
0
        public void authenticate_success()
        {
            var token = new TokenServiceClient(new WSHttpBinding(SecurityMode.None, true),
                                               new EndpointAddress(UriContext.Authenticate));
            var authenticate = token.Authenticate(GenerateGuid(), 158, "Test@1234");

            Assert.IsNotNull(authenticate.Element("MsgHeader"));
        }
Beispiel #3
0
        private string GetToken()
        {
            var binding = new WSHttpBinding(SecurityMode.None, true);

            var token   = new TokenServiceClient(binding, new EndpointAddress(UriContext.Authenticate));
            var element = token.Authenticate(Guid.NewGuid().ToString(), 158, "Test@1234");

            return(element.Element("MsgBody").Element("TokenConf").Element("TokenKey").Value);
        }
Beispiel #4
0
        public void authenticate_fail()
        {
            var token = new TokenServiceClient(new WSHttpBinding(SecurityMode.None, true),
                                               new EndpointAddress(UriContext.Authenticate));
            var authenticate = token.Authenticate(GenerateGuid(), 158, "Test@1235");

            var o = authenticate.Element("MsgBody");

            Assert.IsNull(o);
        }