Recent

Author Topic: Synapse ahd XOAUTH2 (gmail)?  (Read 37021 times)

epergola

  • Full Member
  • ***
  • Posts: 157
Re: Synapse ahd XOAUTH2 (gmail)?
« Reply #15 on: July 08, 2015, 05:11:03 pm »
Thanks very much.

I downloaded your last library an now it works.

I only had to correct this line
Authorize_token := Copy(Found, Length(SearchFor) + 1,1000);
(added the ',1000') in google_oauth2.

One question. During my previous test, in the end I changed client_id and secret from yours to mine. Now running the working program, I LEFT your credentials if frmMain.pas, but it takes my default gmail account when sending (I assume it uses the token created with my preivous Get Access).
Is that because the token was saved earlier and it does not get a new one (from your credentials in this case) until it expires?

Btw, using xp Lazarus 1.4.0 18-apr-2015


rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Synapse ahd XOAUTH2 (gmail)?
« Reply #16 on: July 08, 2015, 05:22:11 pm »
I only had to correct this line
Authorize_token := Copy(Found, Length(SearchFor) + 1,1000);
(added the ',1000') in google_oauth2.
Woops. Yes. The Copy(String, 1) method only works in trunk. It copies from position 1 to the end of the string. I'll need to test this with Laz1.4 :)

One question. During my previous test, in the end I changed client_id and secret from yours to mine. Now running the working program, I LEFT your credentials if frmMain.pas, but it takes my default gmail account when sending (I assume it uses the token created with my preivous Get Access).
Is that because the token was saved earlier and it does not get a new one (from your credentials in this case) until it expires?
Yes. You authenticated with "my App"-credentials and for that the tokens are created. So as long as you don't wipe the access_token and refresh_token it still uses "My App" for sending mail (but via your Google-account). You can just delete the tokens.dat file (or use the button in the screen to remove tokens.dat). After that you'll get a new authentication screen with your Consent-screen info and after that Google knows it's your program which is sending the mail (via your Google account).

Btw, using xp Lazarus 1.4.0 18-apr-2015
Ok, I'll test that too if I get the chance.

B.T.W. I take it the first option (with the "Use browser-title for authentication-code" checked) is the one that worked ??

epergola

  • Full Member
  • ***
  • Posts: 157
Re: Synapse ahd XOAUTH2 (gmail)?
« Reply #17 on: July 08, 2015, 06:18:19 pm »
Yes, the browser dialog worked

epergola

  • Full Member
  • ***
  • Posts: 157
Re: Synapse ahd XOAUTH2 (gmail)?
« Reply #18 on: August 04, 2015, 02:02:11 am »
Rvk
something really weird is happening.
Your functions work perfectly in Lazarus.
However i made a DLL out of them for importing in D5.
All works fine, the authorization and all.
EXCEPT at this point in the ssl_openssl.lib
function TSSLOpenSSL.Init(server:Boolean): Boolean;
var
  s: AnsiString;
begin
  Result := False;
  FLastErrorDesc := '';
  FLastError := 0;
  Fctx := nil;
  case FSSLType of
    LT_SSLv2:
      Fctx := SslCtxNew(SslMethodV2);
    LT_SSLv3:
      Fctx := SslCtxNew(SslMethodV3);
    LT_TLSv1:
      Fctx := SslCtxNew(SslMethodTLSV1);
    LT_all:
      Fctx := SslCtxNew(SslMethodV23);
  else
    Exit;
  end;
  if Fctx = nil then 
IT IS NIL. 
The FSSLType  is LT_all, exacclty as in Lazarus.
It seems to be a matter of the dll's (the function is not found).
I put the dll's from windows\system32 yo the App directory. I even changed their name (and the DLLSSLName name as well) to make sure they are the ones that load, to no avail.
Where would the Lazarus EXE load the DLL from? According to the rules s/b windows\system32 (in XP).
I just cannot understand the difference.
Do you have any clue?

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Synapse ahd XOAUTH2 (gmail)?
« Reply #19 on: August 04, 2015, 11:27:24 am »
I wouldn't place the DLL's in windows\system32. On a 64bit system you don't know where they end up. You have windows\system32 for 64bit dll's and windows\SysWOW64 for 32bit dll's. Is your Windows XP is 32bit I would still just use the application directory. No chance of getting the wrong dll's that way.

Did you copy both ssleay32.dll and libeay32.dll  to your exe and dll directory? The correct 32bit ones? It's best to download clean correct ones. For instance this one for 32bit.
« Last Edit: August 04, 2015, 11:31:03 am by rvk »

renabor

  • Jr. Member
  • **
  • Posts: 73
Re: Synapse ahd XOAUTH2 (gmail)?
« Reply #20 on: August 04, 2015, 02:03:33 pm »
I was able to compile under Linux using Ararat Synapse (http://sourceforge.net/p/synalist/code/HEAD/tree/trunk/), which give support for ssl, and LazWebkit (http://sourceforge.net/projects/lazwebkit/files/) which is a webbroser.
All Lazarus native.
But still have some problems on setting up client_id and secret
FPC 3.2.2 | Lazarus 2.2.3 | Kubuntu 22.04 64bit

epergola

  • Full Member
  • ***
  • Posts: 157
Re: Synapse ahd XOAUTH2 (gmail)?
« Reply #21 on: August 04, 2015, 06:01:22 pm »
Thanks RVK.
I meant this:
From lazarus EXE all is fine.
I do not have the libeay32 and ssleay32 in the same directory of the laz. EXE, therefore the laz. EXE *must* load it from windows\system32 (where they were since long) and all works.
Now, using my own dll (YOUR code, nothing to do with the ssl dll) in a delphi app, I get the error (SslCtxNew(SslMethodV23) returns Nil, which I assume is because the function is not found in the dll).
I tried the 2 dll you suggested, same result.
I even did an FC on the synapse sources (in Lazarus and in Delphi): there are no differences.
ALL seems to be IDENTICAL except the result (which is the only thing that matters)

epergola

  • Full Member
  • ***
  • Posts: 157
Re: Synapse ahd XOAUTH2 (gmail)?
« Reply #22 on: August 04, 2015, 08:52:32 pm »
Uhm now I lost Lazarus.
I did absolutly nothing, except running an rer-unning my (RVK) code to check variables value, and suddenly started complaining
about incompatible ppu!.
I eliminated the installlation directory of Lazarus. I re-installed to a newly named directory. and I get ppu impompatible for Interfacebase.
I tried ro re-compile the IDE and now gives me an error: Panic: C:\laz\fpc\2.6.4\bin\i386-win32\make.exe: Interrupt/Exception caught (code = 0xc0000005, addr = 0x72415c3b).
It looks like a nightmare.

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Synapse ahd XOAUTH2 (gmail)?
« Reply #23 on: August 04, 2015, 11:14:24 pm »
I re-installed to a newly named directory. and I get ppu impompatible for Interfacebase.
If you reinstalled to a different directory you should check all the paths. Is your previous installation still in the same place. (Try renaming that old directory to Lazarus.old or something). And last you could try Tools>Rescan FPC directory.

From lazarus EXE all is fine.
I do not have the libeay32 and ssleay32 in the same directory of the laz. EXE, therefore the laz. EXE *must* load it from windows\system32 (where they were since long) and all works.
Laz. EXE...?? Are you talking about a Lazarus executable or a Lazarus dll?

You should put your Lazarus .dll, your Delphi .exe and both libeay32 and ssleay32 all in the same directory and it should work ok.

Now, using my own dll (YOUR code, nothing to do with the ssl dll) in a delphi app, I get the error (SslCtxNew(SslMethodV23) returns Nil, which I assume is because the function is not found in the dll).
I tried the 2 dll you suggested, same result.
I even did an FC on the synapse sources (in Lazarus and in Delphi): there are no differences.
ALL seems to be IDENTICAL except the result (which is the only thing that matters)
I've never tried creating a DLL in Lazarus so I'm not sure why it wouldn't work. Let's get some facts in a row:

Are you running outside of the Lazarus IDE? Then libeay32 and ssleay32 could just be placed in whatever .exe you run. In this case your Delphi .exe but since you call a Lazarus .dll with that they should be in that directory. But as said before, the easiest way is to all have them in the same directory.

Your Lazarus dll with authentication together with a Lazarus application? Does that work?
If Lazarus application with your Lazarus dll works correctly I'll need to look at the DLL-code and the way it is called.

Now, using my own dll (YOUR code, nothing to do with the ssl dll) in a delphi app, I get the error (SslCtxNew(SslMethodV23) returns Nil, which I assume is because the function is not found in the dll).
This could also be the result of the correct DLL not being loaded. The SslCtxNew function first checks InitSSLInterface to see if SSL-dlls are loaded. You could check yourself after this call with IsSSLloaded is it is loaded. If it is not loaded when calling your DLL from Delphi but it does load when called from a Lazarus .exe which calls your DLL, this would be very strange.


(I was planning to convert this code to Delphi sometime in the future but that doesn't help you now :))

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Synapse ahd XOAUTH2 (gmail)?
« Reply #24 on: August 04, 2015, 11:29:26 pm »
I was able to compile under Linux using Ararat Synapse (http://sourceforge.net/p/synalist/code/HEAD/tree/trunk/), which give support for ssl, and LazWebkit (http://sourceforge.net/projects/lazwebkit/files/) which is a webbroser.
All Lazarus native.
But still have some problems on setting up client_id and secret
What kind of problems? (I take it you have it running with the demo-id and secret)

The steps to setup your own Client_id and secret:
  • Goto https://console.developers.google.com/project
  • Create a project (i.e. My testapp)
  • Enter the project
  • Click APIs & auth
  • Click APIs
  • Choose Gmail API
  • Click Enable API
  • Press the back-icon (left of Disable API)
  • Do the same for Google+ API (for the person information)
  • If you want Calendar access do the same with Calendar API
  • On the left click on Credentials
  • Click Create new client ID
  • Choose "Installed application" as "Application type
  • Choose "Other" as "Installed application type"
  • Choose Create Client ID
  • Now you see a Client ID and a Client secret
  • Copy those to the frmmain.pas in the demo-application
  • Click on Consent Screen on the left
  • Here you can design the screen your users see when the application asks for consent

epergola

  • Full Member
  • ***
  • Posts: 157
Re: Synapse ahd XOAUTH2 (gmail)?
« Reply #25 on: August 04, 2015, 11:47:38 pm »
Thanks Rvk.
What i meant was:
the lazarus Application that uses your code, the application i created to test it, was in c:\lazarus\xoauth2.
In that directory I have no DLL, so the lib*.dll that openssl uses must load from \windows\system32.
In the Laz App I created all  worked fine.
Now the Delphi App using the dll I made out of your code, should also load the
openssl dll from windows\system32, i.e. the 2 apps should use the same dll's.
Why in ssl_opesssl_lib.pas when called by Delphi the ssl is not loaded ( SslCtxNew(SslMethodV23) returns Nil) is a mistery, given tha all is or s/b the same.
At the moment I can't do anything in Lazarus b/c I just does not compile my App anymore. I am spending the day trying to re-install.... until hell freezes over, and then maybe it will work.
As to the Delphi version, I did not wait because I could not find a Json object that works in D5. That is why I created a DLL with that part of your code: to get the json info.

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Synapse ahd XOAUTH2 (gmail)?
« Reply #26 on: August 04, 2015, 11:54:46 pm »
As to the Delphi version, I did not wait because I could not find a Json object that works in D5. That is why I created a DLL with that part of your code: to get the json info.
Yeah... the json-part was also what stopped me from porting it right away. I did find some json-libraries I could use but haven't got the time to look which one I could use best.

At the moment I can't do anything in Lazarus b/c I just does not compile my App anymore. I am spending the day trying to re-install.... until hell freezes over, and then maybe it will work.
I also replied in your other thread as to how to delete the config-directory. That should give you the opportunity to reinstall Lazarus clean. But I would advice going for Lazarus 1.4.2 (instead of the Laz1.10 you mentioned) I see you are already on 1.4.2 :)

If you get it going I wonder what happens if you write a small Lazarus application which calls the DLL. Otherwise I would need to take a look at the DLL code and test some things for myself.

epergola

  • Full Member
  • ***
  • Posts: 157
Re: Synapse ahd XOAUTH2 (gmail)?
« Reply #27 on: August 05, 2015, 01:00:40 am »
For now hell froze and Lazarus (as expected)
... resuscitaded.
The problems is in ssl_openssl.lib.pas.
In d5 i get 26864832 for
_SslMethodV23 := GetProcAddr(SSLLibHandle, 'SSLv23_method');.
in Lazarus I get:
268435456.
(the pointer to the funcion _SslCtxNew is the same).
I wonder if Fpc uses a different calling convention for DLL. I will try to change
cdecl to stdcall in D5.
If that dows not work i try to make a laz app using my dll.

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Synapse ahd XOAUTH2 (gmail)?
« Reply #28 on: August 05, 2015, 01:07:07 am »
I wonder if Fpc uses a different calling convention for DLL. I will try to change
cdecl to stdcall in D5.
Yes, I think you should leave synapse calling openssl dlls at cdecl (c convention) and use stdcall for your own dll.

epergola

  • Full Member
  • ***
  • Posts: 157
Re: Synapse ahd XOAUTH2 (gmail)?
« Reply #29 on: August 05, 2015, 05:25:43 am »
Ok RVK,
(my dll uses stdcall).
I amd sending you the sample program in Fpc that uses the DLL also created inFpc.
Notes.
1. The program is test.lpi, and it uses Unit1.pas, nothing more.
It calls the xoauth2.dll (in Uni1pas).

2. Project1.lp1 is the Library that created
    the dll. Note: I did not change the output name to "xoauth2.dll" so it creates a Procect1.ddl that s/b renamed to "xoauth2.dll" to be used by Test.lp1.
Now from the Lazarus app it gives me an error in StartTLS(). In D5 that was ok, but the ssl returned NIL as I showed previously.
WARNING!!!
do NOT try to recompile Project1 (the DLL) b/c you would LOOSE Lazarus after doing it: you will not be able to compile any porgram and will have to re-install Lazarus ..... hopefully not until hell freezes over, like in my case!
 

 

TinyPortal © 2005-2018