oAuth1, endpoint
lazarus / 38-Networking and Web Programming
----------------------------------------------------------------------
arneolav · 2015-01-14 12:10
I'm using the oAuth1 from this thread: http://forum.lazarus.freepascal
.org/index.php/topic,17608.msg97334.html#msg97334
I'm not able to connect another API using this oAuth1 (and the Synapse
from same link).
A synapse http header is buildt and calculate with a HMAC_SHA1
hash/signature and sendt this way:
if HTTP.Get(URL) then Result:= HTTP.ResultCode;
Reciving this:
HTTP/1.1 401 Unauthorized
OAuth Verification Failed: Verification of signature failed ...
The signature seems correct and the provider asks me " what endpoint
you are using" when sending the URL.
I have no idea of endpoint, can't find anything in the source, and
there is nothing in the oAuth1 spec, so this must have something with
the communication todo.(?)
Somebody who knows this?
Edit: Removed some confusing code
----------------------------------------------------------------------
Leledumbo · 2015-01-14 16:51
Quote from: arneolav on January 14, 2015, 01:10:02 pmThe signature
seems correct and the provider asks me " what endpoint you are using"
when sending the URL.
I have no idea of endpoint, can't find anything in the source, and
there is nothing in the oAuth1 spec, so this must have something with
the communication todo.(?)
An easy way to understand endpoint is the URL + data you send (using
the expected http protocol), defining the service you want to call.
Please take a look at both the twitter and plurk client example,
especially plurk (since I'm the one who made it, so I know it inside-
out).
----------------------------------------------------------------------
arneolav · 2015-01-14 17:44
Thank's
And after a lot of "Googling" i found that it is a simple web service.
"Web services are really nothing more than a request/ response
mechanism that allows a client to remotely access/ modify data. There
are formal standards for web services (SOAP, SOA etc), but a simple
webpage is a service too.
The main downside to printing to a page is that the service would
return HTML.
Preferable data formats are JSON and XML, because most client
frameworks (and server frameworks) are designed around using JSON and
XML.
Example of web service generated of an API
Code: [Select]
----------------------------------------------------------------------
arneolav · 2015-01-14 21:07
I'v been looking thru the *lurk*.pas but can't find some "endpoint
URL", or anythig that can leed me to it
So I need to know what to look for.
But never mind,
I only need the oAuth1 to get oauth_token and oauth_token_secret in
return
and in the next step, use this to get some sensorvalues from the
provider.
The provider asks me for "endpoint", I supose some error results will
be stored there.
As a newbee in oAuth, Question is: Where to stor the endpoint URL in
the oAuth1?
May be as a parameter, but can't find anything in specs of format etc.
----------------------------------------------------------------------
Leledumbo · 2015-01-15 05:28
Again, endpoint is nothing but a combination of URL and data you pass
to it. See, for example, the OAuthEcho method of TPlurkLib:
Code: [Select]function TPlurkLib.OAuthEcho(const EchoData: string):
TOAuthEchoResult;
...
begin
JSON := JSONHTTPMethod('POST', '/APP/echo', 'data=' +
EncodeURLElementRFC3896(EchoData));
...
And the corresponding JSONHTTPMethod:
Code: [Select]function TPlurkLib.JSONHTTPMethod(const Method, URL:
string;
const SendBody: string): TJSONObject;
...
begin
FOauth.SendBody := SendBody;
HTTPResult := FOauth.OAuthHTTPMethod(Method, PlurkBaseURL + URL);
PlurkBaseURL + URL defines the URL (PlurkBaseURL is just a convenient
constant), SendBody defines the data. Together it defines the endpoint
for '/APP/echo' service.
----------------------------------------------------------------------
arneolav · 2015-01-16 09:48
Thank's i'll have a look at it;
I'v been on this version: reiniero-fpcup-b2d024f1a6d2.zip
But accidently i found this: reiniero-fpctwit-5589ff949b4c.zip
Is this the last one?
In the last, this is missing: gvector
I copied form the other, OK?
----------------------------------------------------------------------
Leledumbo · 2015-01-17 04:48
Quote from: arneolav on January 16, 2015, 10:48:33 amThank's i'll have
a look at it;
I'v been on this version: reiniero-fpcup-b2d024f1a6d2.zip
But accidently i found this: reiniero-fpctwit-5589ff949b4c.zip
Is this the last one?
In the last, this is missing: gvector
I copied form the other, OK?
fpcup and fpctwit are two distinct projects that shares nothing in
common. I use fpc trunk to write the unit, if you use stable fpc,
change the use of TVector to something stable fpc has, such as
TObjectList or comment out the corresponding class (TPlurks) and
method of TPlurkLib (PlurksGetPlurks).
----------------------------------------------------------------------
arneolav · 2015-01-21 22:41
The main problem turned out to be utf8/ascii.
Found in some documation, oAuth is designed for Ascii.
To be sure i supplied all stringhandling in the oAuth like this:
SignatureParameters.Add(UTF8ToAnsi('oauth_consumer_key=' +
Foauth_consumer_key));
This solved the problem.
Should be corrected in all dowloads of oAuth1.pas.
I have to correct my self, no need of modify the oAuth.pas.
Just set the key's to Ansi like this in the front (Twitter.pas) pgm.:
FOauth.ConsumerKey := UTF8ToAnsi(PUBLIC_KEY);
FOauth.ConsumerSecret := UTF8ToAnsi(PRIVATE_KEY);
FOauth.AuthToken := UTF8ToAnsi(TOKEN);
FOauth.AuthSecret := UTF8ToAnsi(TOKEN_SECRET);