#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void request_token_example_get(void) {
#if 0
const char *request_token_uri = "http://oauth-sandbox.mediamatic.nl/module/OAuth/request_token";
const char *req_c_key = "17b09ea4c9a4121145936f0d7d8daa28047583796";
const char *req_c_secret = "942295b08ffce77b399419ee96ac65be";
#else
const char *request_token_uri = "http://term.ie/oauth/example/request_token.php";
const char *req_c_key = "key";
const char *req_c_secret = "secret";
#endif
char *res_t_key = NULL;
char *res_t_secret = NULL;
char *req_url = NULL;
char *reply;
printf("request URL:%s\n\n", req_url);
if (!reply)
printf("HTTP request for an oauth request-token failed.\n");
else {
int rc;
char **rv = NULL;
printf("HTTP-reply: %s\n", reply);
if( rc==2
&& !strncmp(rv[0],"oauth_token=",11)
&& !strncmp(rv[1],"oauth_token_secret=",18) ){
res_t_key=strdup(&(rv[0][12]));
res_t_secret=strdup(&(rv[1][19]));
printf("key: '%s'\nsecret: '%s'\n",res_t_key, res_t_secret);
}
if(rv) free(rv);
}
if(req_url) free(req_url);
if(reply) free(reply);
if(res_t_key) free(res_t_key);
if(res_t_secret) free(res_t_secret);
}
void request_token_example_post(void) {
#if 0
const char *request_token_uri = "http://oauth-sandbox.mediamatic.nl/module/OAuth/request_token";
const char *req_c_key = "17b09ea4c9a4121145936f0d7d8daa28047583796";
const char *req_c_secret = "942295b08ffce77b399419ee96ac65be";
#else
const char *request_token_uri = "http://term.ie/oauth/example/request_token.php";
const char *req_c_key = "key";
const char *req_c_secret = "secret";
#endif
char *res_t_key = NULL;
char *res_t_secret = NULL;
char *postarg = NULL;
char *req_url;
char *reply;
printf("request URL:%s\n\n", req_url);
if (!reply)
printf("HTTP request for an oauth request-token failed.\n");
else {
int rc;
char **rv = NULL;
printf("HTTP-reply: %s\n", reply);
if( rc==2
&& !strncmp(rv[0],"oauth_token=",11)
&& !strncmp(rv[1],"oauth_token_secret=",18) ){
res_t_key=strdup(&(rv[0][12]));
res_t_secret=strdup(&(rv[1][19]));
printf("key: '%s'\nsecret: '%s'\n",res_t_key, res_t_secret);
}
if(rv) free(rv);
}
if(req_url) free(req_url);
if(postarg) free(postarg);
if(reply) free(reply);
if(res_t_key) free(res_t_key);
if(res_t_secret) free(res_t_secret);
}
int main (int argc, char **argv) {
int fail=0;
const char *url = "http://base.url/&just=append?post=or_get_parameters"
"&arguments=will_be_formatted_automatically?&dont_care"
"=about_separators";
const char *c_key = "1234567890abcdef1234567890abcdef123456789";
const char *c_secret = "01230123012301230123012301230123";
const char *t_key = "0987654321fedcba0987654321fedcba098765432";
const char *t_secret = "66666666666666666666666666666666";
#if 1
{
char *geturl = NULL;
printf("GET: URL:%s\n\n", geturl);
if(geturl) free(geturl);
}
#endif
#if 1
{
char *postargs = NULL, *post = NULL;
printf("POST: URL:%s\n PARAM:%s\n\n", post, postargs);
if(post) free(post);
if(postargs) free(postargs);
}
#endif
printf(" *** sending HTTP request *** \n\n");
#if 1
request_token_example_post();
#endif
#if 1
request_token_example_get();
#endif
return (fail?1:0);
}
OAuth.net implementation in POSIX-C.
int oauth_cmpstringp(const void *p1, const void *p2)
string compare function for oauth parameters.
@ OA_HMAC
use HMAC-SHA1 request signing method
int oauth_split_url_parameters(const char *url, char ***argv)
splits the given url into a parameter array.
char * oauth_http_get(const char *u, const char *q) attribute_deprecated
do a HTTP GET request, wait for it to finish and return the content of the reply.
char * oauth_sign_url2(const char *url, char **postargs, OAuthMethod method, const char *http_method, const char *c_key, const char *c_secret, const char *t_key, const char *t_secret)
calculate OAuth-signature for a given HTTP request URL, parameters and oauth-tokens.
char * oauth_http_post(const char *u, const char *p) attribute_deprecated
do a HTTP POST request, wait for it to finish and return the content of the reply.