parse response & add urls

Signed-off-by: Luca Fulchir <luca@fulchir.it>
parent 9e5e2def
include "OAuth1Data.iol"
type OAuth1Init:void {
.location :string
.method :string
.consumer_key :string
.secret? :string
.location_request :string
.location_authorize :string
.location_access :string
.method :string
.consumer_key :string
.secret? :string
}
type OAuth1Token: void {
.location_request :string
.location_authorize :string
.location_access :string
.method :string
.consumer_key :string
.secret? :string
.token :string
.token_secret :string
}
interface OAuth1Interface {
RequestResponse:
RequestToken (OAuth1Init) (string)
RequestToken (OAuth1Init) (OAuth1Token)
}
outputPort OAuth1 {
......
include "OAuth1.iol"
include "console.iol"
include "jolie/net/utils/genericHTTP.iol"
include "string_utils.iol"
include "console.iol"
inputPort OAuth1 {
Location: "local"
......@@ -9,10 +9,9 @@ inputPort OAuth1 {
}
main {
RequestToken (where) (answer) {
RequestToken (where) (token) {
http_data.URI = where.location;
http_data.URI = where.location_request;
toUpperCase@StringUtils (where.method) (http_data.method);
where.method = http_data.method;
http_data.headers[0].name = "userAgent";
......@@ -21,8 +20,63 @@ RequestToken (where) (answer) {
http_data.headers[1].value = "";
DataRequestToken@OAuth1Data (where) (http_data.headers[1].value);
sendRequest@genericHTTP(http_data) (answer)
}
sendRequest@genericHTTP(http_data) (answer);
answer.word = "&";
indexOf@StringUtils (answer) (index);
undef(answer.word);
// UNDOCOMENTED: what if we can not find the string??
answer.begin = 0;
answer.end = index;
substring@StringUtils(answer) (tmp1);
undef(answer.begin);
undef(answer.end);
length@StringUtils(answer) (answer.end);
answer.begin = index + 1;
substring@StringUtils(answer) (tmp2);
// now search "oauth_token" and "oauth_token_secret"
// and put them in the right data structure
tmp1.prefix="oauth_token";
startsWith@StringUtils (tmp1) (prefix1Ok);
tmp2.prefix="oauth_token_secret";
startsWith@StringUtils (tmp2) (prefix2Ok);
token << where;
if (prefix1Ok && prefix2Ok) {
// found them, right order. now extract only the tokens
undef(tmp1.prefix);
length@StringUtils(tmp1) (tmp1.end);
tmp1.begin = 12;
substring@StringUtils(tmp1) (token.token);
undef(tmp2.prefix);
length@StringUtils(tmp2) (tmp2.end);
tmp2.begin = 19;
substring@StringUtils(tmp2) (token.token_secret)
} else {
// wrong order ?
tmp1.prefix = "oauth_token_secret";
tmp2.prefix = "oauth_token";
startsWith@StringUtils (tmp1) (prefix1Ok);
startsWith@StringUtils (tmp2) (prefix2Ok);
if (prefix1Ok && prefix2Ok) {
// found them, wrong order. now extract only the tokens
undef(tmp2.prefix);
length@StringUtils(tmp2) (tmp2.end);
tmp2.begin = 12;
substring@StringUtils(tmp2) (token.token);
undef(tmp1.prefix);
length@StringUtils(tmp1) (tmp1.end);
tmp1.begin = 19;
substring@StringUtils(tmp1) (token.token_secret)
} else {
throw (wrong_answer)
}
}
}
}
......@@ -7,8 +7,9 @@ main
{
// data needed for the connection: where to connect, how and who we are
data.location = "http://api.dropbox.com/1/oauth/request_token";
//data.location = "http://codepedia.eu/oauth";
data.location_request = "https://api.dropbox.com/1/oauth/request_token";
data.location_authorize = "https://api.dropbox.com/1/oauth/authorize";
data.location_access = "https://api.dropbox.com/1/oauth/access_token";
data.method = "post";
data.consumer_key = "27250pnzil7tmhx";
data.secret = "6yj3c6mjbdixm6i";
......@@ -16,7 +17,8 @@ main
// send the message
RequestToken@OAuth1 (data) (answer);
println@Console (answer)()
println@Console (answer.token)();
println@Console (answer.token_secret)()
}
type OAuth1Locations:void {
.location :string
.method :string
.callback? :string
.consumer_key :string
.secret? :string
.location_request :string
.location_authorize :string
.location_access :string
.method :string
.callback? :string
.consumer_key :string
.secret? :string
}
interface OAuth1DataInterface {
......
......@@ -17,7 +17,7 @@ DataRequestToken (where) (postString)
scope (error_handler) {
install( Hmac_fault =>
println@Console("HmacError") ();
postString = "ERROR"
throw(Hmac_fault)
);
// getCurrentTimeMillis is a temporary interface, but there's
// nothing better :(
......@@ -27,9 +27,6 @@ scope (error_handler) {
// a little too much as a nonce, but it's easier this way :p
createSecureToken@SecurityUtils(void)(oauth_nonce);
oauth_nonce = "5ae8bce2-6be6-4376-920a-d3433c30f141";
tmp_timestamp = "1365968926";
toSort.item[0] = "oauth_signature_method=HMAC-SHA1";
toSort.item[1] = "oauth_timestamp=" + tmp_timestamp;
toSort.item[2] = "oauth_nonce=" + oauth_nonce;
......@@ -44,7 +41,7 @@ scope (error_handler) {
sort@StringUtils (toSort) (sorted);
toEncode.encoding = "UTF8";
toEncode.input = where.location;
toEncode.input = where.location_request;
encode@URLEncoder (toEncode) (encodedLocation);
toHash.secret = "";
......@@ -65,8 +62,6 @@ scope (error_handler) {
toEncode.input = tmpSignature;
encode@URLEncoder (toEncode) (signature);
println@Console(">>>>>" + toHash.data + ">>>>" + signature) ();
postString = "OAuth " +
"oauth_consumer_key=\"" + where.consumer_key + "\"," +
"oauth_signature_method=\"HMAC-SHA1\"," +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment