Search code examples
c#httpwebrequestrational-team-concertibm-jazzoslc

RTC Authorization Always Failing


(using C#) I'm trying to authenticate but it always comes back failed. I know my username and password are correct. We may be using OSLC 1.0 if that matters. I'm not sure but I see it a couple times in the services.xml file. The website I'm getting my insight from was using 3.0. Maybe there's a difference? Any idea what I'm doing wrong?

            Debug.Log("Authentication Required");
            // tried with just j_security_check as well (without "authenticated") as he seems to do both on the site
            HttpWebRequest _formPost = (HttpWebRequest)WebRequest.Create(localhost + "authenticated/j_security_check");
            _formPost.Method = "POST";
            _formPost.Timeout = 30000;
            _formPost.CookieContainer = request.CookieContainer;
            _formPost.Accept = "text/xml";
            _formPost.ContentType = "application/x-www-form-urlencoded";

            Byte[] _outBuffer = Encoding.UTF8.GetBytes("j_username=coolcat&j_password=bestPassEvar"); //store in byte buffer
            _formPost.ContentLength = _outBuffer.Length;
            Stream _str = _formPost.GetRequestStream();
            _str.Write(_outBuffer, 0, _outBuffer.Length); //update form
            _str.Close();

            //FormBasedAuth Step2:submit the login form and get the response from the server
            HttpWebResponse _formResponse = (HttpWebResponse)_formPost.GetResponse();

            string _rtcAuthHeader = _formResponse.Headers["X-com-ibm-team-repository-web-auth-msg"];
            //check if authentication has failed
            if ((_rtcAuthHeader != null) && _rtcAuthHeader.Equals("authfailed"))
            {
                Debug.Log("Authentication Failed");
                return;
            }

Solution

  • Ugh. I'm such a dummy. Username/Password were correct, but I was encoding it twice before using it! (not seen in code above as I hard-coded it for obvious security reasons).