rewrite of OAuth1 started, not working right now

Signed-off-by: Luca Fulchir <luca@fulchir.it>
parent dd66e199
......@@ -4,7 +4,7 @@ interface OAuth1Interface {
RequestResponse:
RequestToken (OAuth1Info) (OAuth1Info) throws wrong_answer,
getReferral (OAuth1Info) (string),
getAccess (OAuth1Info) (tokenPair)
getAccess (OAuth1Info) (parsed)
}
outputPort OAuth1 {
......
......@@ -12,23 +12,25 @@ execution { concurrent}
main {
[RequestToken (where) (token) {
[RequestToken (info) (token) {
http_data.URI = where.location_request;
toUpperCase@StringUtils (where.method) (http_data.method);
where.method = http_data.method;
http_data.URI = info.location_request;
toUpperCase@StringUtils (info.method) (http_data.method);
info.method = http_data.method;
http_data.headers[0].name = "userAgent";
http_data.headers[0].value = "Jolie-OAuth";
http_data.headers[1].name = "Authorization";
DataRequestToken@OAuth1Data (where) (http_data.headers[1].value);
DataRequestToken@OAuth1Data (info) (http_data.headers[1].value);
sendRequest@genericHTTP(http_data) (answer);
parseAnswer@OAuth1Data(answer) (result);
token << where;
token.token = result.token;
token.token_secret = result.token_secret
token << info;
tmp.pair = result;
tmp.name = "oauth_token";
getPair@OAuth1Data(tmp)(token.token);
tmp.name = "oauth_token_secret";
getPair@OAuth1Data(tmp)(token.secret)
}]{nullProcess}
......@@ -38,8 +40,10 @@ main {
http_data.headers[0].value = "Jolie-OAuth";
http_data.query[0].name = "oauth_token";
http_data.query[0].value = info.token;
http_data.query[1].name = "oauth_callback";
http_data.query[1].value = "";
if (is_defined(info.callback)) {
http_data.query[1].name = "oauth_callback";
http_data.query[1].value = info.callback
};
http_data.method = "GET";
buildURI@genericHTTP (http_data) (output)
......
......@@ -11,16 +11,26 @@ type OAuth1Info:void {
.token_secret? :string
}
type tokenPair:void {
.token :string
.token_secret :string
type pair:void {
.name :string
.value :string
}
type parsed:void {
.pair* :pair
}
type pairSearch {
.search :string
.pair* :pair
}
interface OAuth1DataInterface {
RequestResponse:
DataRequestToken (OAuth1Info) (string),
DataAuthenticate (OAuth1Info) (string),
parseAnswer (string) (tokenPair) throws wrong_answer
parseAnswer (string) (parsed) throws wrong_answer,
getPair (pairSearch) (string) throws not_found
}
outputPort OAuth1Data {
Interfaces: OAuth1DataInterface
......
......@@ -14,7 +14,7 @@ inputPort OAuth1Data{
execution {concurrent}
main {
[DataRequestToken (where) (postString)
[DataRequestToken (info) (postString)
{
scope (error_handler) {
install( Hmac_fault =>
......@@ -33,24 +33,24 @@ scope (error_handler) {
toSort.item[1] = "oauth_timestamp=" + tmp_timestamp;
toSort.item[2] = "oauth_nonce=" + oauth_nonce;
toSort.item[3] = "oauth_version=1.0";
toSort.item[4] = "oauth_consumer_key=" + where.consumer_key;
toSort.item[4] = "oauth_consumer_key=" + info.consumer_key;
count = 4;
if (is_defined(where.callback)) {
if (is_defined(info.callback)) {
count = count + 1;
toSort.item[count] = "oauth_callback=" + where.callback
toSort.item[count] = "oauth_callback=" + info.callback
};
sort@StringUtils (toSort) (sorted);
toEncode.encoding = "UTF8";
toEncode.input = where.location_request;
toEncode.input = info.location_request;
encode@URLEncoder (toEncode) (encodedLocation);
toHash.secret = "";
if (is_defined(where.secret))
toHash.secret = where.secret;
if (is_defined(info.secret))
toHash.secret = info.secret;
toHash.secret = toHash.secret + "&";
toHash.data = where.method + "&" + encodedLocation + "&";
toHash.data = info.method + "&" + encodedLocation + "&";
tmp = "";
for (i = 0, i < count, i++) {
tmp = tmp + sorted.item[i] + "&"
......@@ -65,15 +65,15 @@ scope (error_handler) {
encode@URLEncoder (toEncode) (signature);
postString = "OAuth " +
"oauth_consumer_key=\"" + where.consumer_key + "\"," +
"oauth_consumer_key=\"" + info.consumer_key + "\"," +
"oauth_signature_method=\"HMAC-SHA1\"," +
"oauth_timestamp=\"" + tmp_timestamp + "\"," +
"oauth_nonce=\"" + oauth_nonce + "\"," +
"oauth_version=\"1.0\"," +
"oauth_signature=\"" + signature + "\"";
if ( is_defined(where.callback))
if ( is_defined(info.callback))
postString = postString +
"oauth_callback=\"" + where.callback + "\","
",oauth_callback=\"" + info.callback + "\""
}
}]{nullProcess}
......@@ -113,78 +113,60 @@ scope (error_handler) {
toEncode.input = tmpSignature;
encode@URLEncoder (toEncode) (signature);
postString = "OAuth" +
postString = "OAuth " +
"oauth_consumer_key=\"" + info.consumer_key + "\"," +
"oauth_signature_method=\"HMAC-SHA1\"," +
"oauth_timestamp=\"" + tmp_timestamp + "\"," +
"oauth_nonce=\"" + oauth_nonce + "\"," +
"oauth_version=\"1.0\"," +
"oauth_token=\"" + info.token + "\"," +
"oauth_signature=\"" + signature + "\""
}]{nullProcess}
[parseAnswer (answer) (token) {
scope (parsing) {
install( StringIndexOutOfBoundsException =>
throw(wrong_answer)
);
answer.word = "&";
indexOf@StringUtils (answer) (index);
undef(answer.word);
// TODO: 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);
undef(answer.begin);
undef(answer.end);
// 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);
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)
}
/* now we search for 5 parameters:
* - "uid"
* - "token"
* - "token_secret"
* - "oauth_token"
* - "oauth_token_secret"
* everything else is wrong here.
*/
answer.regex = "&";
split@StringUtils(answer)(strings);
foreach (i = 0, i < #strings.result, i++) {
tmp = string.result[i];
tmp.word = "=";
indexOf@StringUtils(tmp) (index);
undex(tmp.word);
length@StringUtils(tmp) (length);
tmp.begin = 0;
tmp.end = index;
substring@StringUtils(tmp) (token.pair[i].name);
tmp.begin = index + 1;
tmp.end = length;
substring@StringUtils(tmp) (token.pair[i].value);
undef(tmp.begin);
undef(tmp.end)
}
}
}]{nullProcess}
[getPair (pairSearch) (result) {
for (i = 0, i < #pairSearch.pair, i++) {
if (pairSearch.pair[i].name == pairSearch.name) {
result = pairSearch.pair[i].value;
i = #pairSearch.pair;
found = true
}
};
if (!is_defined(found))
throw (now_found)
}]{nullProcess}
}
......
......@@ -2,7 +2,8 @@
include "console.iol"
include "OAuth1.iol"
include "security_utils.iol"
include "time.iol"
include "string_utils.iol"
main
{
......@@ -13,6 +14,7 @@ main
data.method = "post";
data.consumer_key = "27250pnzil7tmhx";
data.secret = "6yj3c6mjbdixm6i";
data.callback = "";
// send the message
RequestToken@OAuth1 (data) (answer);
......@@ -23,6 +25,8 @@ main
getReferral@OAuth1 (answer) (referr);
println@Console ("auth this app with: " + referr)();
sleep@Time(15000)();
getAccess@OAuth1 (answer) (tokens);
println@Console ("token: " + tokens.token)();
println@Console ("secret: " + tokens.token_secret)()
......
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