How can I do the oAuth authentication from another webcontrol
How to implement the oAuth authentication from a web control? Or is there some other nicer way to do it?
What I tried:
I used the REST Client on Google Chrome and tried to POST the form with username/password to the https://server:port/jts/j_security_check
The headers are:
Accept: application/rdf+xml
Oslc-core-version: 2.0
Content-Type: application/x-www-form-urlencoded
And the content is:
j_username=myUserName&j_password=mypwd
I also tried to set the conten after encoding like: j_username%3DmyUserName%26j_password%3Dmypwd
But I am always getting HTTP/1.1 408 Request Timeout
Accepted answer
def __login__(self):# Grab secured resource to initiate loginresponse, content = self.http.request( self.base_url + "/authenticated/identity", 'GET', headers=self.headers)if response.__contains__('x-com-ibm-team-repository-web-auth-msg'):if response['x-com-ibm-team-repository-web-auth-msg'] != 'authrequired':raise Exception("Server error authenticating: " + response.__str__())# TODO: Post login information, Jazz uses j_security_check for FORM auth.response, content = self.http.request(self.base_url+'/authenticated/j_security_check' , 'POST',headers=self.headers, body=urllib.urlencode({'j_username': self.user, 'j_password': self.password}))# Confirm that we are connected, and can grab the secure resource nowresponse, content = self.http.request( self.base_url + "/authenticated/identity", 'GET', headers=self.headers)if response.__contains__('x-com-ibm-team-repository-web-auth-msg'):raise Exception("Login was not successful, server response: " + response.__str__() )
Comments
@SeanWilbur: Great buddy. This works for me. But, once authenticated, further request to any other secured resource is failing - either a 401 Unauthorised, or request timed out. I wanted to capture the token and token secret when I authenticate. How can I do that?
I am having this same issue, I do a get and get challenged, I send the POST and it shows that I have credentials, but on my next get, I again have no authorization. In another post someone mentioned it may be because the RTC server that I am using is running Tomcat instead of WebSphere.
Has this been answered or solved?
Don
Today in 2021 you would use a requests session for all http operations because this propagates the (successful) authentication cookies to all subsequent get/put/post etc.
5 other answers
- Arne
apparently somebody else had the same problem, eventually solved it and posted it to this website including code snippet for .NET oAuth login vs. RRC.
- Arne
P.S.: keep in mind these changes for oAuth starting with RTC 3.0.1
P.P.S.: in case you use non-secure http or JTS and RRC are on different servers, be sure to also scan this technote.
Comments
@ArneBister: Thanks for digging into. The post that you are referring to with .NET code snippet is written by me. That I did from a windows app and it uses a browser window to login. The same technique can not be used when calling from a web application. So, I wanted to try something different and the form base authentication is good, I felt. However, I am not being able to get positive result so far.
The solution is out there. We will find it.
- Arne
Comments
@ArneBister: I am sure, there is some roadblock and I am not able to see the road properly. With light from all of you, we shall reach where we intend to go.
@KangkanGoswami The article http://phkrief.wordpress.com/2010/09/15/jazz-form-based-authentication/ describes the process for Jazz Form-based Authentication. The steps are the same for .NET. One you get the OAuth Url, open it in a WebBrowser control, and onces the user logs in trap the Document Closing event and get the Cookie. This Cookie can be used to access the actual resource url. We are in a process of creating a sample application .NET, will update you once its ready.
@SeanWilbur: Great buddy. This works for me. But, once authenticated, further request to any other secured resource is failing - either a 401 Unauthorised, or request timed out. I wanted to capture the token and token secret when I authenticate. How can I do that?Has this been worked out and if so, how?
Thanks, Don
Comments
I'm facing the same problem using RDM4.0.1 on tomcat.