Example #1
0
/*
 * Main Test and Example Code.
 * 
 * compile:
 *  gcc -lssl -loauth -o oauthtest oauthtest.c
 */
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";
			 //< the url to sign
  const char *c_key    = "1234567890abcdef1234567890abcdef123456789";
  			//< consumer key
  const char *c_secret = "01230123012301230123012301230123";
  			//< consumer secret
  const char *t_key    = "0987654321fedcba0987654321fedcba098765432";
  			//< token key
  const char *t_secret = "66666666666666666666666666666666";
  			//< token secret

#if 1 // example sign GET request and print the signed request URL
  {
    char *geturl = NULL;
    geturl = oauth_sign_url2(url, NULL, OA_HMAC, NULL, c_key, c_secret, t_key, t_secret);
    printf("GET: URL:%s\n\n", geturl);
    if(geturl) free(geturl);
  }
#endif

#if 1 // sign POST ;) example 
  {
    char *postargs = NULL, *post = NULL;
    post = oauth_sign_url2(url, &postargs, OA_HMAC, NULL, c_key, c_secret, t_key, t_secret);
    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");

// These two will perform a HTTP request, requesting an access token. 
// it's intended both as test (verify signature) 
// and example code.
#if 1 // POST a request-token request
  request_token_example_post();
#endif
#if 1 // GET a request-token
  request_token_example_get();
#endif

  return (fail?1:0);
}
Example #2
0
void oauth_test()
{
	// the url to sign
	const char *url = "http://base.url/&just=append?post=or_get_parameters"
					"&arguments=will_be_formatted_automatically?&dont_care"
					"=about_separators";
	// consumer key
	const char *c_key = "1234567890abcdef1234567890abcdef123456789";
	// consumer secret
	const char *c_secret = "01230123012301230123012301230123";
	// token key
	const char *t_key    = "0987654321fedcba0987654321fedcba098765432";
	// token secret
	const char *t_secret = "66666666666666666666666666666666";

	/*
	 * example sign GET request and print the signed request URL
	 */
	{
		char *geturl = NULL;
		geturl = oauth_sign_url2(url, NULL, OA_HMAC, NULL,
					c_key, c_secret, t_key, t_secret);
		printf("GET URL:\n\t%s\n", geturl);
		if (geturl)
			free(geturl);
	}

	/*
	 * sign POST example 
	 */
	{
		char *postargs = NULL, *post;
		post = oauth_sign_url2(url, &postargs, OA_HMAC, NULL,
					c_key, c_secret, t_key, t_secret);
		printf("POST URL:\n\t%s\nPARAM:%s\n", post, postargs);
		if (post)
			free(post);
		if (postargs)
			free(postargs);
	}

	/*
	 * These two will perform a HTTP request, requesting an access token. 
	 * it's intended both as test (verify signature) 
	 */
	request_token_example_get();
	request_token_example_post();
}
Example #3
0
/*
 * Main Test and Example Code.
 */
int main (int argc, char **argv) {
  request_token_example_get();
  return (0);
}