summaryrefslogtreecommitdiffabout
path: root/test/test-oauth-consumer.cc
authorMichael Krelin <hacker@klever.net>2008-03-07 19:53:46 (UTC)
committer Michael Krelin <hacker@klever.net>2008-03-07 19:53:46 (UTC)
commitf953b073abbf9e58e5b2a46c6ddf65f57dec1fad (patch) (unidiff)
treecd8bf29efc2dc59070c013a69a7c6d70f63322b4 /test/test-oauth-consumer.cc
parent0d19bbaa23b7bd07ec4f5e3683ffdd8df4641bc9 (diff)
downloadlibopkele-f953b073abbf9e58e5b2a46c6ddf65f57dec1fad.zip
libopkele-f953b073abbf9e58e5b2a46c6ddf65f57dec1fad.tar.gz
libopkele-f953b073abbf9e58e5b2a46c6ddf65f57dec1fad.tar.bz2
comitting updated test consumer
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (limited to 'test/test-oauth-consumer.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--test/test-oauth-consumer.cc18
1 files changed, 4 insertions, 14 deletions
diff --git a/test/test-oauth-consumer.cc b/test/test-oauth-consumer.cc
index 3b3ca70..c5a0fc0 100644
--- a/test/test-oauth-consumer.cc
+++ b/test/test-oauth-consumer.cc
@@ -1,83 +1,73 @@
1#include <iostream> 1#include <iostream>
2#include <cassert> 2#include <cassert>
3#include <stdexcept> 3#include <stdexcept>
4using namespace std; 4using namespace std;
5#include <openssl/sha.h> 5#include <openssl/sha.h>
6#include <openssl/evp.h> 6#include <openssl/evp.h>
7#include <openssl/hmac.h> 7#include <openssl/hmac.h>
8#include <opkele/exception.h> 8#include <opkele/exception.h>
9#include <opkele/debug.h> 9#include <opkele/debug.h>
10#include <opkele/util.h> 10#include <opkele/util.h>
11#include <opkele/util-internal.h> 11#include <opkele/util-internal.h>
12#include <opkele/curl.h> 12#include <opkele/curl.h>
13#include <opkele/oauth/consumer.h> 13#include <opkele/oauth/consumer.h>
14 14
15ostream& operator<<(ostream& o,const opkele::oauth::token_t& t) { 15ostream& operator<<(ostream& o,const opkele::oauth::token_t& t) {
16 o << "{ key: \"" << t.key << "\", secret: \"" << t.secret <<"\" }"; 16 o << "{ key: \"" << t.key << "\", secret: \"" << t.secret <<"\" }";
17 return o; 17 return o;
18} 18}
19 19
20int main(int,char**) { 20int main(int,char**) {
21 try { 21 try {
22 opkele::oauth::simple_consumer sc( 22 opkele::oauth::simple_consumer sc(
23 opkele::oauth::simple_provider_endpoints( 23 opkele::oauth::simple_provider_endpoints(
24 "http://term.ie/oauth/example/request_token.php", 24 "http://term.ie/oauth/example/request_token.php",
25 "http://term.ie/oauth/example/user_authorization.php", 25 "http://term.ie/oauth/example/user_authorization.php",
26 "http://term.ie/oauth/example/access_token.php", 26 "http://term.ie/oauth/example/access_token.php",
27 "HMAC-SHA1", opkele::oauth::oauth_post_body, 27 "HMAC-SHA1", opkele::oauth::oauth_post_body,
28 opkele::oauth::oauth_auth_header), 28 opkele::oauth::oauth_auth_header),
29 opkele::oauth::token_t( "key","secret" ) ); 29 opkele::oauth::token_t( "key","secret" ) );
30 opkele::oauth::token_t rt = sc.get_request_token(); 30 opkele::oauth::token_t rt = sc.get_request_token();
31 cout << "Request token: " << rt << endl; 31 cout << "Request token: " << rt << endl;
32 cout << "Authorize URL: " << sc.get_authorize_url(rt) << endl; 32 cout << "Authorize URL: " << sc.get_authorize_url(rt) << endl;
33 opkele::oauth::token_t at = sc.get_access_token(rt); 33 opkele::oauth::token_t at = sc.get_access_token(rt);
34 cout << "Access token: " << at << endl; 34 cout << "Access token: " << at << endl;
35 35
36 opkele::fields_t test; 36 opkele::fields_t test;
37 test.set_field("foo","bar"); 37 test.set_field("foo","bar");
38 opkele::util::curl_pick_t curl = opkele::util::curl_t::easy_init(); 38 opkele::util::curl_pick_t curl = opkele::util::curl_t::easy_init();
39 opkele::oauth::http_request_t hr("POST", 39 opkele::oauth::http_request_t hr("POST",
40 "http://term.ie/oauth/example/echo_api.php"); 40 "http://term.ie/oauth/example/echo_api.php");
41 sc.prepare_request(hr, 41 sc.prepare_request(hr,
42 opkele::fields_t(),test, 42 opkele::fields_t(),test,
43 opkele::oauth::oauth_auth_header,"HMAC-SHA1", 43 opkele::oauth::oauth_auth_header,"HMAC-SHA1",
44 &at,"realm"); 44 &at,"realm");
45 DOUT_("url: " << hr.url << endl 45 CURLcode r = curl.misc_sets();
46 << "body: " << hr.body << endl 46 r || (r=curl.set_write());
47 << "header: " << hr.authorize_header);
48 opkele::util::curl_slist_t rh;
49 rh.append("Authorization: "+hr.authorize_header);
50 CURLcode r;
51 (r=curl.misc_sets())
52 || (r=curl.set_write())
53 || (r=curl.easy_setopt(CURLOPT_HTTPHEADER,rh) )
54 || (r=curl.easy_setopt(CURLOPT_URL,hr.url.c_str()))
55 || (r=curl.easy_setopt(CURLOPT_POST,1))
56 || (r=curl.easy_setopt(CURLOPT_POSTFIELDS,hr.body.c_str()))
57 || (r=curl.easy_setopt(CURLOPT_POSTFIELDSIZE,hr.body.size()));
58 if(r) 47 if(r)
59 throw opkele::exception_curl(OPKELE_CP_ "failed to set curly options",r); 48 throw opkele::exception_curl(OPKELE_CP_ "failed to set curly options",r);
49 hr.setup_curl(curl);
60 if( (r=curl.easy_perform()) ) 50 if( (r=curl.easy_perform()) )
61 throw opkele::exception_curl(OPKELE_CP_ "failed to perform curly request",r); 51 throw opkele::exception_curl(OPKELE_CP_ "failed to perform curly request",r);
62 DOUT_("Response: " << endl << curl.response); 52 cout << "Response: " << curl.response << endl;
63 53
64#ifdef OPKELE_HAVE_KONFORKA 54#ifdef OPKELE_HAVE_KONFORKA
65 }catch(konforka::exception& e) { 55 }catch(konforka::exception& e) {
66 cerr 56 cerr
67 << "oops, caught " << opkele::util::abi_demangle(typeid(e).name()) << endl 57 << "oops, caught " << opkele::util::abi_demangle(typeid(e).name()) << endl
68 << " what: " << e.what() << endl 58 << " what: " << e.what() << endl
69 << " where: " << e.where() << endl; 59 << " where: " << e.where() << endl;
70 if(!e._seen.empty()) { 60 if(!e._seen.empty()) {
71 cerr << " seen:" << endl; 61 cerr << " seen:" << endl;
72 for(list<konforka::code_point>::const_iterator 62 for(list<konforka::code_point>::const_iterator
73 i=e._seen.begin();i!=e._seen.end();++i) { 63 i=e._seen.begin();i!=e._seen.end();++i) {
74 cerr << " " << i->c_str() << endl; 64 cerr << " " << i->c_str() << endl;
75 } 65 }
76 } 66 }
77#endif 67#endif
78 }catch(std::exception& e){ 68 }catch(std::exception& e){
79 cerr 69 cerr
80 << "oops, caught " << opkele::util::abi_demangle(typeid(e).name()) << endl 70 << "oops, caught " << opkele::util::abi_demangle(typeid(e).name()) << endl
81 << " what: " << e.what() << endl; 71 << " what: " << e.what() << endl;
82 } 72 }
83} 73}