Forums Mingle API

Calling Mingle REST API with WinForms#578

Subscribe to Calling Mingle REST API with WinForms 8 post(s), 2 voice(s)

 
Avatar Bil Simser 58 post(s) #1417

I’ve been building in a web app without issue accessing the Mingle REST API. Now I’m trying to get it to work in a WinForms app (C#) and not getting any success.

I’ve tried the following combinations, none of which work and all return me an unauthorized error:

WebClient client = new WebClient();
client.Credentials = CredentialCache.DefaultCredentials;
string result = client.DownloadString(new Uri(“http://[server]:[port]/projects/[project]/cards.xml”));

WebClient client = new WebClient();
client.Credentials = CredentialCache.DefaultCredentials;
string result = client.DownloadString(new Uri(“http://[user]:[password]@[server]:[port]/projects/[project]/cards.xml”));

WebClient client = new WebClient();
string result = client.DownloadString(new Uri(“http://[user]:[password]@[server]:[port]/projects/[project]/cards.xml”));

WebClient client = new WebClient();
string result = client.DownloadString(new Uri(“http://[server]:[port]/projects/[project]/cards.xml”));

Like I said, nothing is working. They all return a 401 error (Unauthorized) but the username I’m specifying is me (an admin) and I’m running the application under my credentials.

I’ve tried adding “basic_auth_enabled: true” to the auth_config.yml file but that doesn’t help either. Anyone have a suggested combination that works?

 
Avatar LiXiao Administrator 21 post(s) #1427

For making sure the Mingle server enabled basic auth, you can simply type the uri into browser to test it. For example, you can type ‘http://[user]:[password]@[server]:[port]/projects/[project]/cards.xml’ in your browser to see whether there is xml responded.

For WinForms app, please check how WebClinet works with HTTP Basic Auth.
I am not sure what’s CredentialCache.DefaultCredentials in your code. I did some search on WebClient
I think the following code is closed to work with Http Basic Auth:

WebClient client = new WebClient();
client.Credentials = new NetworkCredential(“username”, “password”);
string response = client.DownloadString(“http://[server]:[port]/projects/[project]/cards.xml”);

Here is original post where I got the code: http://www.eggheadcafe.com/tutorials/aspnet/c841f26a-bcff-453f-8305-3c644cac25a9/webclient-class-gotchas.aspx

I don’t get an environment to try it, hope it can help you.

 
Avatar Bil Simser 58 post(s) #1431

I have basic_auth_enabled: true in my config file, but I’m looking up users via LDAP so that’s configured as well (and working).

If I try the http://[user]:[password]@[server]:[port] in my browser (after signing out of Mingle) I just get a blank page (I’m assumine a 401 or 500 error)

CredentialCache.DefaultCredentials just grabs the credentials from the current user signed into the OS and uses it.

The syntax you listed doesn’t work and results in a 401 (unauthorized) error.

For the life of me, I cannot figure out how to do this with a LDAP integrated setup (Mingle users/passwords works fine) and it’s highly frustrating.

 
Avatar Bil Simser 58 post(s) #1432

One more thing, if I sign out of Mingle and enter this into the browser:

http://[server]:[port]/projects/[project]/cards.xml

Using fiddler I see this header come back (using IE6):

HTTP/1.1 401 Unauthorized
Content-Type: application/xml; charset=utf-8
Set-Cookie: _session_id=4eb2940600bcc00be22ffc975514cddf; path=/
Cache-Control: no-cache
Content-Length: 32
Server: Jetty(6.1.5)

Incorrect username or password.

 
Avatar LiXiao Administrator 21 post(s) #1438

Hi Bil,

Since you said: “If I try the http://[user]:[password]@[server]:[port] in my browser (after signing out of Mingle) I just get a blank page (I’m assumine a 401 or 500 error)”

Please type in a correct rest api url, e.g. http://[user]:[password]@[server]:[port]/projects/[project]/cards.xml
to test the basic auth.
If you tried the cards.xml url, I think the basic auth of the Mingle server haven’t been enabled.
You may changed wrong config file, please confirm the config file(auth_config.yml) you updated is in your Mingle Data Directory which is created when first time Mingle server started. It should not be the directory installed Mingle.
And restart the Mingle server after you saved configuration.

The following config content works for me(I just put the ‘basic_auth_enabled’ at the end of the config:
—start—-
ldap_settings: ldapserver: ldaphost.mycompany.com ldapport: 389 ldapbinduser: ldapbind@ldaphost.mycompany.com ldapbindpasswd: password ldapbasedn: ou=Employees,ou=Enterprise, ... ldapfilter: sAMAccountName ldapobjectclass: organizationalPerson ldap_map_fullname: cn ldap_map_mail: mail
password_format:
auto_enroll_as_mingle_admin: true
auto_enroll: true
basic_auth_enabled: true
—end--

 
Avatar LiXiao Administrator 21 post(s) #1439

the url “http://[server]:[port]/projects/[project]/cards.xml” you typed in the browser can’t be authorized since you didn’t provide the user name and password. In the browser, for using the http basic auth, you should always provide user and password between ‘http://’ and ‘[server]’, e.g. http://user:password@[server]:[port]....

So the response is correct.

 
Avatar Bil Simser 58 post(s) #1446

@LiXiao: Sorry, I did mean to use the full URL in the original message, just figured I didn’t have to spell everything out.

I’m giving up on trying to get LDAP and the REST API to work as I just can’t get it to work. I’ve got the configuration you mentioned and restarted the server.

I’ve entered this in my browser (IE6):
http://[username]:[password]@[server]:[port]/projects/test/cards.xml

Where [username] is my username (I’ve signed out of Mingle previously and opened a new browser session). This is my username without the domain prefix, same as what I sign into the Mingle login page with.

I can’t tell what error is coming back. I get a title bar of “Invalid syntax error” and some text on the page that says “The page cannot be displayed” and “The page you are looking for might have been removed or had its name changed”

At this point I’m only going to provide support for my plugin for non-LDAP setups until someone can get me information that works in my test setup. Problem is there’s no information Mingle is providing me to help diagnose the problem.

Thanks.

 
Avatar Bil Simser 58 post(s) #1447

More information. Turns out that I’m using IE6 and they’ve disabled the username:password@server syntax with a security patch some time ago. Unfortunately I don’t have access to anything but IE6 for testing right now (so FF or something is a problem).

I did find a registry hack to remove this behavior and just trying to get the link working in the browser first. I still think there’s something wrong in the Mingle API to get this working. For example, I’m trying to run against my own local install (localhost) on port 8080 with non-LDAP authentication (Mingle is keeping track of usernames and passwords).

Here’s the request when I use the username:password@server:port syntax in my browser:

GET /projects/test/cards.xml HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, application/x-silverlight, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/x-silverlight-2-b1, /*
Accept-Language: en-ca
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 1.1.4322; .NET CLR 3.0.04506.648)
Host: localhost:8080
Proxy-Connection: Keep-Alive
Cookie: last-visited-project=brms; MINGLE20SESSIONID=1kzb9dfuh9meb; _session_id=e19df056d9eb37d38f87f49e23f73657

And here’s the response:
HTTP/1.1 401 Unauthorized
Content-Type: application/xml; charset=utf-8
Set-Cookie: _session_id=e19df056d9eb37d38f87f49e23f73657; path=/
Cache-Control: no-cache
Content-Length: 32
Server: Jetty(6.1.5)

Incorrect username or password.

I know I’m using the correct username/password here (typed it into the login form).

Is it possible Mingle cannot handle the username:password url *and a specified port number? Or maybe this just won’t work in IE6 no matter what?

Forums Mingle API