Esempio n. 1
0
        private void AuthReqCallBack(IAsyncResult asyncResult)
        {
            string envelope =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
                    <soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" 
                          xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" 
                          xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">
                      <soap:Body>
                        <Login xmlns=""http://schemas.microsoft.com/sharepoint/soap/"">
                          <username>{0}</username>
                          <password>{1}</password>
                        </Login>
                      </soap:Body>
                    </soap:Envelope>";

            UTF8Encoding       encoding = new UTF8Encoding();
            AuthHTTPWebRequest request  = (AuthHTTPWebRequest)asyncResult.AsyncState;
            Stream             _body    = request.req.EndGetRequestStream(asyncResult);

            envelope = string.Format(envelope, request.userId, request.pwd);
            byte[] formBytes = encoding.GetBytes(envelope);

            _body.Write(formBytes, 0, formBytes.Length);
            _body.Close();

            request.req.BeginGetResponse(new AsyncCallback(AuthCallback), request);
        }
Esempio n. 2
0
        public void Authenticate(string userId, string pwd, string authServiceURL)
        {
            System.Uri         authServiceUri = new Uri(authServiceURL);
            AuthHTTPWebRequest authRequest    = new AuthHTTPWebRequest();

            HttpWebRequest spAuthReq = HttpWebRequest.Create(authServiceURL) as HttpWebRequest;

            authRequest.req = spAuthReq;
            authRequest.req.CookieContainer       = cookieJar;
            authRequest.req.Headers["SOAPAction"] = "http://schemas.microsoft.com/sharepoint/soap/Login";
            authRequest.req.ContentType           = "text/xml; charset=utf-8";
            authRequest.req.Method = "POST";
            authRequest.userId     = userId;
            authRequest.pwd        = pwd;

            authRequest.req.BeginGetRequestStream(new AsyncCallback(AuthReqCallBack), authRequest);
        }
Esempio n. 3
0
        private void AuthCallback(IAsyncResult asyncResult)
        {
            //TODO: AuthCallback code here
            string authResult = "";

            AuthHTTPWebRequest request  = (AuthHTTPWebRequest)asyncResult.AsyncState;
            HttpWebResponse    response =
                (HttpWebResponse)request.req.EndGetResponse(asyncResult);
            Stream responseStream = response.GetResponseStream();

            if (request != null && response != null)
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    XElement   results = XElement.Load(responseStream);
                    XNamespace n       = "http://schemas.microsoft.com/sharepoint/soap/";

                    var r = from result in results.Descendants(n + "ErrorCode")
                            select result.Value;

                    authResult = r.ToList().FirstOrDefault <String>();
                }
            }

            if (authResult == "NoError")
            {
                //Error handing omitted for clarity
                EventHandler <FBAAuthenticatedEventArgs> authenticated = OnAuthenticated;
                if (authenticated != null)
                {
                    authenticated(this, new FBAAuthenticatedEventArgs(cookieJar));
                }
            }
            else
            {
                //Error handing omitted for clarity
                EventHandler failedAuth = OnFailedAuthentication;
                if (failedAuth != null)
                {
                    failedAuth(this, null);
                }
            }
        }