OAUTH2.0 GMAIL

Rob Mostyn mostyn at platformis.net
Fri Oct 4 08:53:59 UTC 2024


To cope with the scenario Joe has highlighted we have a method to start the asynchronous request from a separate task within Omnis.

That way if the form or window closes, the task in the background is there to receive the confirmation of the request and record the result.

e.g. when I send an email to someone from a remote form in Omnis it is quite possible I will have moved onto another record. So the steps in this technique involve:
- initiate the task
- send the task some data that reflects the record affected by the asynchronous request (typically an email that has been sent)
- also send the task a reference back to the initiating instance, with a callback method
- when the asynchronous task completes the task: logs that the email was sent, relating to the specified record
- if the instance is still available, call back to the instance that the operation has completed (there may be something visual to present to user)
- if the instance is an ultra thin request (that certainly won’t exist when the asynchronous request completes) then do not provide a callback instance/method name.

It took a while to get my head around it and for a generic Task class to be written to handle different scenarios.  If folk are interested I will upload an 11.1 infra library.  Please let me know.

Rob Mostyn

> On 3 Oct 2024, at 22:59, Joe Maus <jmaus at theccgllc.com> wrote:
> 
> Hi,
> 
> $alaysfinish is a property of the SMTP worker object.  So, when you have an instance reference to the OW3 SMTP object, you should be able to see the property by looking at the variable to see its settings.  So, using the below code line as an example, you'd right-click on the iorSMTP and select the "Variable iorSMTP" menu selection and that will show you all of the settings and states of the object (after it has been instantiated, of course).
> 
> This is how you set $alwaysfinish():
> 
> Calculate iorSMTP.$alwaysfinish as kTrue
> 
> Since you have it setup as an instance variable, $alwaysfinish is probably not needed as the variable is not going out of scope like a local var would.  But even so, given that the worker objects are asynchronous, it's possible if the instance var is part of a window that the user closes after sending an email.  The user could start the process and then, since control is returned to the user, they could close the window before everything has the chance to complete.  If such a possibility exists, then you'll want to set $alwaysfinsih to kTrue.
> 
> Regards,
> 
> Joe Maus
> 
> 
>> On Oct 2, 2024, at 3:00 PM, Martin Obongita via omnisdev-en <omnisdev-en at lists.omnis-dev.com> wrote:
>> 
>> Hi Joe, where is this property $alwaysfinish() found at? I'm using the sample library and I can't seem to find it. The worker object is an instance variable not a local variable. Would the status of the $alwaysfinish also apply?
>> Regards,Martin Obongita
>>   On Wednesday, October 2, 2024 at 07:01:18 PM GMT+3, Joe Maus <jmaus at theccgllc.com> wrote:  
>> 
>> Just a side note, the user account's password is not needed when using oAuth.
>> 
>> Second side note, if you end up using your SMTP worker object reference in a local variable, you'll probably want to set the $alwaysfinish() property to kTrue as otherwise the object ref may go out of scope before it has finished the sending of the email.  In addition, you may find your object sends email great when you step through the code, but suddenly stops working consistently when you stop stepping through the code, this situation is likely due to $alwaysfinish being set to kFalse (the default).
>> 
>> Regards,
>> 
>> Joe Maus
>> 
>>> On Sep 30, 2024, at 7:20 PM, Martin Obongita via omnisdev-en <omnisdev-en at lists.omnis-dev.com> wrote:
>>> 
>>> Hooray! It has finally sent.
>>> You deserve a flower, Paul.
>>> Thank you so much for the leads.
>>> Regards, Martin.
>>> 
>>> 
>>> 
>>>    On Tuesday, October 1, 2024 at 02:15:45 AM GMT+3, Paul Mulroney <pmulroney at logicaldevelopments.com.au> wrote:  
>>> 
>>> Hi Martin,
>>> Just a double check - the username and password on the front screen of the sample must have username which is the full gmail address eg <username>@gmail.com?
>>> If you get the authorise part OK, it's got to be something like this.
>>> RegardsPaul.
>>> 
>>> 
>>> 
>>> On 30 Sep 2024, at 4:48 pm, Martin Obongita via omnisdev-en <omnisdev-en at lists.omnis-dev.com> wrote:
>>> Hi Paul,
>>> I hope you are fine.
>>> I followed your instructions given below and the smtp authorizes and logs in to my GMAIL and is able to start the process.  But I get errors in the result tab with error code 67 error info "login denied". The error log says, username and password not accepted. Yet I have counter checked & with confirmation the password and user are correct.
>>> We are almost there. Any further help on error 67?
>>> Regards,Martin.
>>> 
>>> 
>>> 
>>> 
>>>    On Thursday, September 26, 2024 at 11:35:41 AM GMT+3, Paul Mulroney <pmulroney at logicaldevelopments.com.au> wrote:  
>>> 
>>> Hi Martin,
>>> Are you talking about the SMTP OW3 Worker sample library?  If so, then going from memory I think that the sequence is:- Open the window (if you currently have it open, then close it)- Check "Use OAuth2"- Click the "OAuth2" tab- Enter Client ID, Client Secret, (you need to set these up in the Google Developer Console)- Enter Authorisation URL (eg https://accounts.google.com/o/oauth2/v2/auth), Access Token URL (eg https://oauth2.googleapis.com/token), Scope (eg https://mail.google.com/)- Go back to the "Server connection" tab- Click "Authorize" -> this should open a browser window where you sign onto Google and allow you authorise to send- Click the "Server connection" tab again- Enter your from email address (username) and email password- Click on the "message" tab and enter from/to- Click on the "subject" tab and enter the message body- click "Start".
>>> I know that you if you click Start first and then try to authorise it gets upset.  I just stepped through these instructions and they seemed to work for me - Studio 10.22 build 31896.
>>> RegardsPaul.
>>> 
>>> On 26 Sep 2024, at 12:19 am, Martin Obongita <martin.obongita at yahoo.com> wrote:
>>> Hi all,
>>> I have managed to get the clientID, clientSecret and the accessToken for the OAUTH2. I update the entry fields. I then mark on Use AUTH2 then click on Authorize button. I get the error authorize() cannot run while the OAUTH2Worker object is assigned to the $aouth2 property of an OW3 worker.
>>> 
>>> Where can I get the $aouth2 property? Where can I get the OAUTH2 object class?
>>> 
>>> Regards
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>>    On Tuesday, September 24, 2024 at 02:23:30 AM GMT+3, Paul Mulroney <pmulroney at logicaldevelopments.com.au> wrote:  
>>> 
>>> Hi Martin,
>>> We did this recently for one of our clients.  They use gmail for their primary setup.
>>> In the past, you could use the SMTP settings to send using Gmail's smtp server.  However, they started restricting how that was accessed in a bid to increase security. They then introduced "application specific passwords", which allowed you to create a password for your particular application that allowed you to send using Gmail's smtp server.  I'm not sure if that's an option any longer, I think that was discontinued in the recent past.  The only option to send email via Gmail is using the OAuth method.
>>> To do that, you need to setup some stuff at Google's end to permit OAuth - what you're actually doing is accessing Google's Gmail APIs to send/receive email.  Here's the link to Google's documentation to do this: https://developers.google.com/identity/protocols/oauth2
>>> It's a difficult thing to setup, but here are the basic steps:- You need a google developer account.  It's been a while since we did this, but think if you have a google account you can just go to console.cloud.google.com and it should allow you do setup what you need- Create a new google project- Enable the "Gmail API"- Create credentials - use the OAuth client ID option-> this will give you a client ID and a client secret
>>> Once you have these, the OAuth example in Omnis will work - you use the client ID and secret, it will ask you to sign into your google account and authorise, then redirect you back to your app.
>>> We had a few false starts and did things out of sequence which required us to start over - 
>>> If this all sounds too hard (and it is!) then you should consider using a mail service like SMTP2Go, or Twillio SendGrid - they allow you to send email via their service.  Again, there will be some setup required, but probably a lot less effort than google!
>>> Regards,Paul.
>>> 
>>> 
>>> 
>>> On 23 Sep 2024, at 5:27 pm, Martin Obongita via omnisdev-en <omnisdev-en at lists.omnis-dev.com> wrote:
>>> Hi all,
>>> Has anyone managed to setup smtpsend sample library with OAUTH2.0 with a gmail server?
>>> Question 1: When is it necessary to use Oauth with Gmail?Question 2: Which is the best sample libraries HTTP, IMAP, POP and SMTP to work with gmail?Question 3: Is there a way to setup a complete emailing utility with Omnis so that I can have sent items, incoming emails? Where can I get such a sample library? Or instead, it's just best to store emails in the database and mark them as either sent or pending?
>>> Any useful leads will be apprieciated.
>>> Kind regards,Martin Obongita.
>>> _____________________________________________________________
>>> Manage your list subscriptions at https://lists.omnis-dev.com
>>> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com 
>>> 
>>> 
>>> 
>>> 
>>> Fishing is a matter of Bait and Sea @gingermeggs1921
>>> -- 
>>> Paul W. Mulroney                                            We Don't Do Simple Pty Ltd 
>>> pmulroney at logicaldevelopments.com.au      Trading as Logical Developments
>>> www.logicaldevelopments.com.au                  ACN 161 009 374 
>>> Ph: +61 8 9458 3889                                      86 Coolgardie Street
>>>                                                                          BENTLEY  WA  6102
>>> 
>>> 
>>> 
>>> 
>>> _____________________________________________________________
>>> Manage your list subscriptions at https://lists.omnis-dev.com
>>> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com 
>>> 
>>> 
>>> I'm riding in the month of October to raise funds for the Royal Flying Doctor Service.  Would you help me support this worthy cause?  You can donate here: https://www.oceanstooutback.org.au/fundraisers/paulmulroney
>>> 
>>> 
>>> 
>>> |    | Paul W Mulroney
>>> Logical Developments
>>> Customised Software Solutions
>>> Ph: 08 9458 3889
>>> |    | We Don't Do Simple Pty Ltd
>>> trading as
>>> Logical Developments
>>> ACN 161 009 374
>>> |
>>> |  |        |
>>> 
>>> 
>>> 
>>> _____________________________________________________________
>>> Manage your list subscriptions at https://lists.omnis-dev.com
>>> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com
>> 
>> _____________________________________________________________
>> Manage your list subscriptions at https://lists.omnis-dev.com
>> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com 
>> 
>> _____________________________________________________________
>> Manage your list subscriptions at https://lists.omnis-dev.com
>> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com
> 
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com
> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com



More information about the omnisdev-en mailing list