tel / oauthenticated

Authentication-ho! OAuth 1.0 for Haskell atop http-conduit.
MIT License
6 stars 6 forks source link

Include simple twitter example #8

Open bbangert opened 10 years ago

bbangert commented 10 years ago

While I enjoy reading Haskell code, it'd be nice if there was a basic example of how all the parts should be used together. Using Network.HTTP.Client is not exactly intuitive (nor apparently documented very well), and oauthenticate builds on top of that to sign its requests. I managed to slowly assemble everything necessary to construct a request, and finally sign it with oauthenticate, just to get a *\ Exception: TlsNotSupported when attempting to actually run it. Eventually I will likely figure out how to update the manager to use Tls and get a request sent.

I found an outdated example of making a basic request here: https://gist.github.com/miikka/548120

Unfortunately since oauthenticate was refactored, these instructions no longer work.

ibotty commented 10 years ago

i guess a tutorial on using http-client is out of scope for oauthenticated, but it is fairly simple, so it might as well include a haddock session about it.

i can refer you to http://lpaste.net/99726 where a stripped down example can be found.

for ssl/tls support substitute defaultManagerSettings with one of the manager settings from either http-client-tls or http-client-openssl. be sure to understand the consequences though. -tls is easier and does not depend on external C libraries, but is wide open to side channel attacks.

edit: maybe you need to replace Data.Default with Data.Default.Class, because of changes in http-client, but that might be an artifact of my dev environment.

tel commented 10 years ago

ibotty :+1:

I think genuine documentation should have an example use of http-client with and without oauthenticated. The TLS issue is outside the scope of oauthenticated, however.

bbangert commented 10 years ago

Thanks, that definitely helps. I was apparently very close already, I didn't see quite how to combine the credentials. I figured out from the http-client docs how to make a manager and use it after a bit.

I have some code now that looks like this: http://paste.ofcode.org/8LBVF699sQxDNkEHRH9qkW

Apparently it fails oauth though with "Bad Authentication data" in the response. Still looking to see whats up.

bbangert commented 10 years ago

For docs, most oauth libs include just a few short examples of 3-legged auth, and making a single request. I'm rather familiar with OAuth and API usage so the docs I was looking for were mainly an example or two like: http://hackage.haskell.org/package/hoauth-0.3.5/docs/Network-OAuth-Consumer.html Except with a basic API call as well (they only show a 3-legged call, which I'm unsure how to make with oauthenticated).

bbangert commented 10 years ago

Ah ha, Issue #6 is why I'm getting Bad Authentication.

Edit: Yup, checked out the fix-issue6 branch and linked it in, and it worked fine. I could clean-up my example here and flesh it out a bit to include as a basic 'how-to' set of docs if that would help. I still need to figure out how to do a 3-legged auth though.

tel commented 10 years ago

Ahh, sorry about that. I'm going to find some time to dig into issue ibotty's #4 and then try to release both of those fixes together shortly.