Esempio n. 1
0
    private void SendSqrlData(SqrlData data)
    {
        var request = WebRequest.Create("http://" + data.Url);
        request.Method = "POST";

        string postData = string.Format("publickey={0}&signature={1}&url={2}",
                                        HttpServerUtility.UrlTokenEncode(data.PublicKey),
                                        HttpServerUtility.UrlTokenEncode(data.Signature),
                                        data.Url);

        var byteArray = Encoding.UTF8.GetBytes(postData);
        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = byteArray.Length;
        var dataStream = request.GetRequestStream();
        dataStream.Write(byteArray, 0, byteArray.Length);
        dataStream.Close();

        var response = request.GetResponse();

        dataStream = response.GetResponseStream();
        var reader = new StreamReader(dataStream);
        var responseFromServer = reader.ReadToEnd();

        dataView.Buffer.Text = responseFromServer;

        reader.Close();
        dataStream.Close();
        response.Close();
    }
Esempio n. 2
0
        public ActionResult Sqrl(string id, string publickey, string signature, string url)
        {
            var data = new SqrlData
            {
                PublicKey = HttpServerUtility.UrlTokenDecode(publickey),
                Signature = HttpServerUtility.UrlTokenDecode(signature),
                Url = url
            };

            var expected = string.Format("{0}/{1}",
                                         Url.Action("Sqrl",
                                                    "Login",
                                                    null,
                                                    "sqrl",
                                                    Request.Url.Host + ":" + Request.Url.Port),
                                         id);

            if(_sqrlServer.VerifySqrlRequest(data, expected) && _nutRepository.IsNutActive(id))
            {
                var user = _userRepository.Retrieve(publickey);

                if(user == null)
                {
                    // register user
                    user = new SqrlUser
                    {
                        Id = publickey,
                        Initialized = false
                    };

                    _userRepository.Create(user);
                }

                _nutRepository.Validate(id, user.Id);

                return Content("valid");
            }

            return Content("invalid");
        }