Hi guys,
Is there a simple way to implement OAuth version 1 via direct access rather than user tokens?
The oauth plugin from ServoyForge is not useful here, this is not for twitter or other apps that it supports.
I don’t know much about OAuth but the example request below (offered by the OAuth provider) looks fairly simple and is not using any tokens, so I tried to put up a http request with the help of the http plugin. However, I keep getting a ‘Invalid signature’ (code 401) or ‘Internal Server Error’ (code 200) in the response.
Could someone, please, criticize what I’m doing?
According to the OAuth provider example of using their API, the request should contain the following data:
OAuth Details:
Consumer Key: some-consumer-key
Consumer Secret: very-long-abrakadabra
Signature Method: HMAC-SHA1
Access Type: 2-legged
Host/ Subnet: 0.0.0.0/0
The request itself would be similar to this (again, this is from the API provider instructions):
> POST /api/ HTTP/1.1
Host: some.host.com
Authorization: OAuth,oauth_version="1.0",oauth_nonce="VNXp1srdSxb",oauth_timestamp="1436699816",oauth_consumer_key="some-consumer-key",oauth_signature_method="HMAC-SHA1",oauth_signature="signature-as-abrakadabra"
Content-Type: application/json
Accept: application/json
Content-Length: 45
{"id":0,"method":"InvoiceSearch","params":[]}
My code looks like this:
var httpClient = plugins.http.createNewHttpClient();
var url = "https://some.host.com/api/?format=json"; //this is the main access point as specified by the OAuth provider: https://some.host.com/api/?format=(soap|json|xml)
var request = httpClient.createPostRequest(url);
request.addHeader('Authorisation', 'OAuth')
var consumer_secret_key = 'very-long-abrakadabra';
request.addParameter('oauth_version', '1.0');
request.addParameter('oauth_nonce', 'VNXp1srdSxb');
request.addParameter('oauth_timestamp', '1436699816');
request.addParameter('oauth_consumer_key', 'some-consumer-key');
request.addParameter('oauth_signature_method', 'HMAC-SHA1');
request.addParameter('oauth_signature', 'pie90pC%2FaTOiSdAB81JQZ8l2rNI%3D');
request.addParameter('id', '0');
request.addParameter('method', 'CompanySearch');
request.addParameter('params', '%5B%5D'); //I tried to pass the square brackets raw '[]' or encoded '%5B%5D' which did not seem to affect anything
My signature was generated here, I made sure I’m using the same nonce and timestamp both in my code and in that form. I haven’t bothered with my own implementation yet.
Well, the above code hasn’t worked and I’m wondering if it’s as simple as I imagine.
Appreciate any advice and help.