RTC Authorization Always Failing

204 views Asked by At

(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;
            }
2

There are 2 answers

0
CodeMonkey On BEST ANSWER

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).

1
jad On

You can find some sample code that communicates with Jazz-based products using OSLC, under this github repository https://github.com/OSLC/lyo-samples.

I found this sample code that particularly deals with Form authentication. https://github.com/OSLC/lyo-samples/blob/master/oslc4j-client-samples/src/main/java/org/eclipse/lyo/oslc4j/client/samples/ERMSample.java

A number of programs in that same folder try to connect to different Jazz solutions.