little cleanup OAuth1

Signed-off-by: Luca Fulchir <luca@fulchir.it>
parent f66d73e0
......@@ -10,7 +10,7 @@ java:
- mkdir -p ${BUILDDIR} 2>/dev/null
${JAVAC} -cp ${JOLIEDIR}/jolie.jar -d ${BUILDDIR} jolie/net/utils/URLEncoder.java
${JAVAC} -cp ${JOLIEDIR}/jolie.jar:${JARDIR}/commons-codec-1.6.jar -d ${BUILDDIR} jolie/net/utils/Hmac.java
${JAVAC} -cp ${JOLIEDIR}/jolie.jar:${JARDIR}/httpcore-4.2.2.jar:${JARDIR}/httpclient-4.2.3.jar:${JARDIR}/commons-io-2.4.jar:${JARDIR}/commons-codec-1.6.jar -d ${BUILDDIR} jolie/net/utils/genericHTTP.java
${JAVAC} -cp ${JOLIEDIR}/jolie.jar:${JARDIR}/httpcore-4.2.2.jar:${JARDIR}/httpclient-4.2.3.jar:${JARDIR}/commons-io-2.4.jar:${JARDIR}/commons-codec-1.6.jar -d ${BUILDDIR} jolie/net/utils/HTTP.java
cd ${BUILDDIR} && jar cvf ${PACKAGE_NAME} ./jolie/net/utils/*class && cd ${CWD}
......@@ -22,5 +22,5 @@ install: java
cp ${JARDIR}/*.jar ${JOLIEDIR}/javaServices/
demo1: install
jolie jolie/net/OAuth/demo.ol
jolie jolie/net/OAuth/demo1.ol
/* *************************************************************************
* Copyright (C) 2013 by Luca Fulchir <luca@fulchir.it> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
* For details about the authors of this software, see the AUTHORS file. *
***************************************************************************/
include "OAuth1Data.iol"
interface OAuth1Interface {
......
/* *************************************************************************
* Copyright (C) 2013 by Luca Fulchir <luca@fulchir.it> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
* For details about the authors of this software, see the AUTHORS file. *
***************************************************************************/
include "OAuth1.iol"
include "jolie/net/utils/HTTP.iol"
include "string_utils.iol"
......
/* *************************************************************************
* Copyright (C) 2013 by Luca Fulchir <luca@fulchir.it> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
* For details about the authors of this software, see the AUTHORS file. *
***************************************************************************/
type OAuth1Pair:void {
.name :string
.value :string
}
type OAuth1Info:void {
.location_request :string
.location_authorize :string
......@@ -9,6 +33,9 @@ type OAuth1Info:void {
.secret? :string
.token? :string
.token_secret? :string
// HTTP additional user-specified parameters
.headers? :OAuth1Pair
.query? :OAuth1Pair
}
type OAuth1_pair:void {
......
/* *************************************************************************
* Copyright (C) 2013 by Luca Fulchir <luca@fulchir.it> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
* For details about the authors of this software, see the AUTHORS file. *
***************************************************************************/
include "security_utils.iol"
include "time.iol"
include "OAuth1Data.iol"
include "string_utils.iol"
include "jolie/net/utils/Hmac.iol"
include "jolie/net/utils/URLEncoder.iol"
include "console.iol"
include "jolie/net/utils/HTTP.iol"
inputPort OAuth1Data{
Location: "local"
......@@ -43,8 +64,8 @@ scope (error_handler) {
sort@StringUtils (toSort) (sorted);
toEncode.encoding = "UTF8";
toEncode.input = info.location_request;
encode@URLEncoder (toEncode) (encodedLocation);
toEncode = info.location_request;
URLencode@HTTP (toEncode) (encodedLocation);
toHash.secret = "";
if (is_defined(info.secret))
......@@ -56,13 +77,13 @@ scope (error_handler) {
tmp = tmp + sorted.item[i] + "&"
};
tmp = tmp + sorted.item[count];
toEncode.input = tmp;
encode@URLEncoder (toEncode) (encodedParams);
toEncode = tmp;
URLencode@HTTP (toEncode) (encodedParams);
toHash.data = toHash.data + encodedParams;
sha1@Hmac (toHash) (tmpSignature);
toEncode.input = tmpSignature;
encode@URLEncoder (toEncode) (signature);
toEncode = tmpSignature;
URLencode@HTTP (toEncode) (signature);
postString = "OAuth " +
"oauth_consumer_key=\"" + info.consumer_key + "\"," +
......@@ -96,22 +117,22 @@ scope (error_handler) {
sort@StringUtils (toSort) (sorted);
toEncode.encoding = "UTF8";
toEncode.input = info.location_access;
encode@URLEncoder (toEncode) (encodedLocation);
toEncode = info.location_access;
URLencode@HTTP (toEncode) (encodedLocation);
tmp = "";
for (i = 0, i < (#toSort.item - 1), i++) {
tmp = tmp + sorted.item[i] + "&"
};
tmp = tmp + sorted.item[#sorted.item - 1];
toEncode.input = tmp;
encode@URLEncoder (toEncode) (encodedParams);
toEncode = tmp;
URLencode@HTTP (toEncode) (encodedParams);
toHash.secret = info.secret + "&" + info.token_secret;
toHash.data = info.method + "&" + encodedLocation + "&" + encodedParams;
sha1@Hmac (toHash) (tmpSignature);
toEncode.input = tmpSignature;
encode@URLEncoder (toEncode) (signature);
toEncode = tmpSignature;
URLencode@HTTP (toEncode) (signature);
postString = "OAuth " +
"oauth_consumer_key=\"" + info.consumer_key + "\"," +
......
......@@ -37,10 +37,15 @@ type HTTPResponse:void {
.output :string
}
type HTTPURLEncoding:string {
.encoding :string
}
interface HTTPInterface {
RequestResponse:
sendRequest (HTTPRequest) (string) throws send_error,
buildURI (HTTPRequest) (string) throws buildURI_fault
sendRequest (HTTPRequest) (string) throws send_error,
buildURI (HTTPRequest) (string) throws buildURI_fault,
URLencode (HTTPURLEncoding) (string) throws Encoding_fault
}
outputPort HTTP {
......
......@@ -44,6 +44,18 @@ public class HTTP extends JavaService
{
@RequestResponse
public static String URLencode (Value req) throws FaultException
{
try {
URLCodec codec = new URLCodec(req.getFirstChild("encoding")
.strValue());
return codec.encode(req.strValue());
} catch (Exception e) {
throw new FaultException("Encoding_fault", e);
}
}
@RequestResponse
public static String sendRequest (Value req) throws FaultException
{
HttpClient httpclient = new DefaultHttpClient();
......@@ -65,10 +77,9 @@ public static String buildURI (Value req) throws FaultException
if (req.hasChildren("query")) {
for (Value pair : req.getChildren("query")) {
String name = codec.encode(
pair.getFirstChild("name").strValue(), "UTF8");
pair.getFirstChild("name").strValue());
String value = codec.encode(
pair.getFirstChild("value").strValue(),
"UTF8");
pair.getFirstChild("value").strValue());
if (notFirst) {
query += "&";
}
......@@ -155,4 +166,3 @@ private static String sendPost (HttpClient httpclient, Value req)
}
}
}
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