relazione + refactor

Signed-off-by: Luca Fulchir <luca@fulchir.it>
parent f6b1471b
File added
......@@ -34,7 +34,7 @@ execution {sequential}
main {
[RequestToken (info) (token) {
[requestToken (info) (token) {
scope (error_handler) {
install (wrong_answer =>
println@Console("OAuth1:wrong answer from server")();
......
......@@ -177,14 +177,9 @@ scope (parsing) {
}]{nullProcess}
[getPair (pairSearch) (result) {
length@StringUtils(pairSearch.search)(search_length);
result = "";
for (i = 0, i < #pairSearch.pair, i++) {
// 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)) {
if (pairSearch.pair[i].name == pairSearch.search) {
result = pairSearch.pair[i].value;
i = #pairSearch.pair;
found = true
......
......@@ -36,8 +36,8 @@ type OAuth1Info:void {
.token_secret? :string
.verifier? :string
// HTTP additional user-specified parameters
.headers? :OAuth1Pair
.query? :OAuth1Pair
.headers* :OAuth1Pair
.query* :OAuth1Pair
}
type OAuth1_pair:void {
......@@ -63,7 +63,7 @@ interface OAuth1DataInterface {
}
interface OAuth1Interface {
RequestResponse:
RequestToken (OAuth1Info) (OAuth1Info) throws wrong_answer,
requestToken (OAuth1Info) (OAuth1Info) throws wrong_answer,
getReferral (OAuth1Info) (string),
getAccess (OAuth1Info) (OAuth1_parsed)
getAccess (OAuth1Info) (OAuth1_parsed) throws wrong_answer
}
......@@ -19,7 +19,6 @@
* For details about the authors of this software, see the AUTHORS file. *
***************************************************************************/
include "string_utils.iol"
include "OAuth2Types.iol"
inputPort OAuth2Data{
......@@ -30,7 +29,7 @@ inputPort OAuth2Data{
execution {concurrent}
main {
[DataAuth (info) (data) {
[dataAuth (info) (data) {
data.pair[0].name = "client_id";
data.pair[0].value = info.client_id;
data.pair[1].name = "response_type";
......@@ -53,7 +52,7 @@ main {
}
}]{nullProcess}
[DataAccess (info) (data) {
[dataAccess (info) (data) {
if (!is_defined(info.code) || !is_defined(info.client_secret)) {
throw (oauth2_missing_data)
};
......@@ -78,8 +77,8 @@ main {
}
}]{nullProcess}
[DataRefresh (info) (data) {
if (!is_defined(info.refresh_token) || !is_defined(info.client_secret)) {
[dataRefresh (info) (data) {
if (!is_defined(info.refresh_token) || !is_defined(info.client_secret)){
throw (oauth2_missing_data)
};
data.pair[0].name = "client_id";
......@@ -96,17 +95,28 @@ main {
}
}]{nullProcess}
[dataPassword (info) (data) {
if (!is_defined(info.username) || !is_defined(info.password)){
throw (oauth2_missing_data)
};
data.pair[0].name = "grant_type";
data.pair[0].value = "password";
data.pair[1].name = "username";
data.pair[1].value = info.username;
data.pair[2].name = "passowrd";
data.pair[2].value = info.password;
if (is_defined(info.scope)) {
data.pair[3].name = "scope";
data.pair[3].value = info.scope
}
}]{nullProcess}
[getPair (pairSearch) (result) {
result="";
result = "";
result.found = false;
length@StringUtils(pairSearch.search)(search_length);
for (i = 0, i < #pairSearch.pair, i++) {
// 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)) {
if (pairSearch.pair[i].name == pairSearch.search) {
result = pairSearch.pair[i].value;
i = #pairSearch.pair;
result.found = true
......
......@@ -19,6 +19,7 @@
* For details about the authors of this software, see the AUTHORS file. *
***************************************************************************/
include "protocols/http.iol"
include "../utils/HTTPTypes.iol"
type OAuth2Pair:void {
......@@ -35,6 +36,7 @@ type OAuth2Info:void {
.redirect_uri? :string
.scope? :string
.state? :string
.extensionGrant? :string
.access_token? :string
.token_type? :string
.refresh_token? :string
......@@ -58,19 +60,34 @@ type OAuth2_data:void {
.pair* :OAuth2Pair
}
type HTTPinfo:void {
.http :DefaultOperationHttpRequest
.info :OAuth2Info
}
interface OAuth2DataInterface {
RequestResponse:
DataAuth (OAuth2Info) (OAuth2_data),
DataAccess (OAuth2Info) (OAuth2_data),
DataRefresh (OAuth2Info) (OAuth2_data),
getPair (OAuth2_Search) (OAuth2_SearchRes)
getPair (OAuth2_Search) (OAuth2_SearchRes),
dataAuth (OAuth2Info) (OAuth2_data),
dataAccess (OAuth2Info) (OAuth2_data)
throws oauth2_missin_data,
dataRefresh (OAuth2Info) (OAuth2_data)
throws oauth2_missin_data,
dataPassword(OAuth2Info) (OAuth2_data)
throws oauth2_missin_data
}
interface OAuth2Interface {
RequestResponse:
Auth (OAuth2Info) (string),
Access (OAuth2Info) (OAuth2Info),
Refresh (OAuth2Info) (OAuth2Info),
acgAuth (OAuth2Info) (string) throws OAuth2_error,
acgAccess (OAuth2Info) (OAuth2Info) throws OAuth2_error,
implicitGrant (OAuth2Info) (string) throws OAuth2_error,
passwordGrant (OAuth2Info) (OAuth2Info) throws OAuth2_error,
extensionGrant(OAuth2Info) (OAuth2Info) throws OAuth2_error,
parseAnswer (HTTPinfo) (OAuth2Info) throws OAuth2_error,
refresh (OAuth2Info) (OAuth2Info) throws OAuth2_error,
clientCredentialGrant (OAuth2Info) (OAuth2Info)
throws OAuth2_error
}
......@@ -34,7 +34,7 @@ init
data.callback = "http://localhost:8011/access";
// send the message
RequestToken@OAuth1 (data) (answer);
requestToken@OAuth1 (data) (answer);
println@Console ("token: " + answer.token)();
println@Console ("token_secret: " + answer.token_secret)();
......
......@@ -34,7 +34,7 @@ main
data.scope = "https://www.googleapis.com/auth/plus.me";
// send the message
Auth@OAuth2 (data) (referr);
acgAuth@OAuth2 (data) (referr);
println@Console ("auth this app with " + referr)();
// now we wait for the http redirect which will bring us
......@@ -55,15 +55,7 @@ main
println@Console("We got a redirect, but it wasn't ours")();
out = ERR
};
length@StringUtils(codeRequest.state)(ln1);
length@StringUtils(data.state)(ln1);
if (ln1 != ln2) {
println@Console("We got a redirect, but it wasn't ours")();
out = ERR
};
codeRequest.state.startsWith = data.state;
startsWith@StringUtils(codeRequest.state)(boolTest);
if (! boolTest ) {
if (codeRequest.state != data.state) {
println@Console("We got a redirect, but it wasn't ours")();
out = ERR
}
......@@ -81,7 +73,7 @@ main
data.code = codeRequest.code;
data.method = "POST";
// next step in Auth2 authentication.
Access@OAuth2 (data) (answer);
acgAccess@OAuth2 (data) (answer);
println@Console("token:" + answer.access_token)();
println@Console("expires_in:" + answer.expires_in)();
if (is_defined(answer.refresh_token)) {
......@@ -89,8 +81,12 @@ main
};
println@Console("Now refreshing the token:")();
Refresh@OAuth2(answer)(refresh_answer)
refresh@OAuth2(answer)(refresh_answer);
println@Console("token:" + refresh_answer.access_token)();
println@Console("expires_in:" + refresh_answer.expires_in)();
if (is_defined(refresh_answer.refresh_token)) {
println@Console("refresh_token:" + refresh_answer.refresh_token)()
}
}
}
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