OAuth1 funzionante.

TODO: fare in modo che l'utente possa passare tutti i parametri che vuole alla libreria

Signed-off-by: Luca Fulchir <luca@fulchir.it>
parent 1fcb567f
......@@ -4,7 +4,7 @@ interface OAuth1Interface {
RequestResponse:
RequestToken (OAuth1Info) (OAuth1Info) throws wrong_answer,
getReferral (OAuth1Info) (string),
getAccess (OAuth1Info) (parsed)
getAccess (OAuth1Info) (OAuth1_parsed)
}
outputPort OAuth1 {
......
......@@ -24,13 +24,12 @@ main {
sendRequest@genericHTTP(http_data) (answer);
parseAnswer@OAuth1Data(answer) (result);
token << info;
tmp.pair = result;
tmp.name = "oauth_token";
parseAnswer@OAuth1Data(answer) (tmp);
tmp.search = "oauth_token";
getPair@OAuth1Data(tmp)(token.token);
tmp.name = "oauth_token_secret";
getPair@OAuth1Data(tmp)(token.secret)
tmp.search = "oauth_token_secret";
getPair@OAuth1Data(tmp)(token.token_secret)
}]{nullProcess}
......
......@@ -11,26 +11,26 @@ type OAuth1Info:void {
.token_secret? :string
}
type pair:void {
type OAuth1_pair:void {
.name :string
.value :string
}
type parsed:void {
.pair* :pair
type OAuth1_parsed:void {
.pair* :OAuth1_pair
}
type pairSearch {
type OAuth1_pairSearch:void {
.search :string
.pair* :pair
.pair* :OAuth1_pair
}
interface OAuth1DataInterface {
RequestResponse:
DataRequestToken (OAuth1Info) (string),
DataAuthenticate (OAuth1Info) (string),
parseAnswer (string) (parsed) throws wrong_answer,
getPair (pairSearch) (string) throws not_found
parseAnswer (string) (OAuth1_parsed) throws wrong_answer,
getPair (OAuth1_pairSearch) (string) throws not_found
}
outputPort OAuth1Data {
Interfaces: OAuth1DataInterface
......
......@@ -126,22 +126,14 @@ scope (error_handler) {
[parseAnswer (answer) (token) {
scope (parsing) {
/* 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];
for (i = 0, i < #strings.result, i++) {
tmp = strings.result[i];
tmp.word = "=";
indexOf@StringUtils(tmp) (index);
undex(tmp.word);
//TODO: what if not found?
undef(tmp.word);
length@StringUtils(tmp) (length);
tmp.begin = 0;
tmp.end = index;
......@@ -156,18 +148,22 @@ scope (parsing) {
}]{nullProcess}
[getPair (pairSearch) (result) {
length@StringUtils(pairSearch.search)(search_length);
for (i = 0, i < #pairSearch.pair, i++) {
if (pairSearch.pair[i].name == pairSearch.name) {
// uhm... confronto tra due stringhe? '==' non è corretto...
length@StringUtils(pairSearch.pair[i].name)(length2);
pairSearch.pair[i].name.prefix=pairSearch.search;
startsWith@StringUtils(pairSearch.pair[i].name)(prefix);
undef(pairSearch.pair[i].name.prefix);
if (prefix && (search_length == length2)) {
result = pairSearch.pair[i].value;
i = #pairSearch.pair;
found = true
}
};
if (!is_defined(found))
throw (now_found)
throw (not_found)
}]{nullProcess}
}
......@@ -23,13 +23,18 @@ main
println@Console ("token_secret: " + answer.token_secret)();
getReferral@OAuth1 (answer) (referr);
println@Console ("auth this app with: " + referr)();
println@Console ("auth this app with (15 seconds): " + referr)();
sleep@Time(15000)();
getAccess@OAuth1 (answer) (tokens);
println@Console ("token: " + tokens.token)();
println@Console ("secret: " + tokens.token_secret)()
// use these to sign whatever data in your api calls:
println@Console("Results:")();
for (i = 0, i < #tokens.pair, i++) {
println@Console(tokens.pair[i].name + " = " +
tokens.pair[i].value)()
}
}
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