GSuite - Gmail Activity Unauthorized client error

@Mateus_Cruz Thanks for the samples, it’s really helpful.

@Mateus_Cruz While following your sample for OAuth, there is an error for “NetworkCredential” undefined.
Assign ClientSecret = new NetworkCredential(string.Empty, Password).Password
Can not find NetworkCredential in Variables in your sample, but there is no error in your sample, how come i will have this error ?

In the “Imports” tab (the one beside “Arguments”), type System.Net and add that namespace.

1 Like

Got it, thanks

Hi @Mateus_Cruz
Got an error on the browser while trying to run the process on Studio, I had AssetName “GsuiteLogin” for the credentials on the Orchestrator. Any idea where I’m missing?

Error: invalid_client
The OAuth client was not found.
access_type=offline
response_type=code
client_id=“3893xxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com
redirect_uri=http://127.0.0.1:54468/authorize/
scope=https://www.googleapis.com/auth/drive https://mail.google.com/ https://www.googleapis.com/auth/spreadsheets

Error message on Studio
19.7.0+Branch.master.Sha.8c253d13718eed5c7db27daef6facd1fe1b0d067
Source: GSuite Application Scope
Message: The client did not complete the token exchange after the default 60 seconds, and as a result the operation was canceled.
Exception Type: System.TimeoutException

RemoteException wrapping System.TimeoutException: The client did not complete the token exchange after the default 60 seconds, and as a result the operation was canceled.
at UiPath.GSuite.Activities.GSuiteApplicationScope.Execute(NativeActivityContext context)
at System.Activities.NativeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Did you take more than 60 seconds to input your username and password?

The problem is the error on browser, it stopped the process, The OAuth client was not found.
But it should get the credentials from Asset on Orchestrator, right?

Hi @Mateus_Cruz
I used your sample with my asset of credentials, got the same error, any idea where I might be wrong?
Thanks

Did you setup the OAuth account as it is written in the workflow’s annotation and then added the credential to Orchestrator?

Yes, I also use your sample with my asset of credentials on orchestrator.
Both have same error.

@MubieSam_Lin
I tried the workflow again using a completely new account and credential created just now, and it worked fine.
Could you please try with a different account to see if it works?

1 Like

Hi @Mateus_Cruz
Finally I got it working with a new account and learned the lesson, thank you very much!
One last question, the only way to make this process via unattended robot (it is not possible now because OAuth verification), is to submit for OAuth consent screen verification, right?

Good to hear you got it working!

OAuth is a bit difficult to be completely unattended because of the consent screen. It doesn’t come up everytime, but if the token expires, then it’ll appear again.
So you might want to keep that in mind when designing your solution.

1 Like

Hi @Mateus_Cruz

Sorry to bother you again. While trying to setup the OAuth client ID for our new project, found that there is no “other” application type any more as you had indicated before in your GSuiteActivitiesOAuthSample.zip

Seems there are some changes in getting GSuite Activities to work, where I can find the updated instruction to setup OAuth, or better to use Service Account if we will use it for gmail and gsheets of the same user only?

Thanks

Hello! You can choose “Desktop app” as application type and it should work.
I’ve updated the samples to the new version of the G Suite activities and also updated the instructions in them:
GSuiteActivitiesServiceAccountSample-20200709.zip (11.7 KB)
GSuiteActivitiesOAuthSample-20200709.zip (11.5 KB)
GSuiteActivitiesAPIKeySample-20200709.zip (3.8 KB)

1 Like

Hey MubieSam_Lin,

I have created a series on youtube explaining everything about GSuite. may be it can help

1 Like

Hello, I didn’t succeed to use service account access. The connection doesn’t work… Did you configure some other element before ? Btw is the service account a good solution for unattended robot ?
Thank you

Hi Alix,
I’ve been struggling with Service Accounts for Gsuite over the last few weeks but finally managed to get it working! I can confirm that the Service Account works great with unattended robots.

There’s a couple of things you need to keep in mind:

  • Service Account can not be used with Gmail account, only with Gsuite (the paid Google services). This is because you need to “Delegate domain wide access” in order for the Service Account to work, and this is not possible in Gmail.
  • If using Gsuite you should follow the steps below. I’ve written them from the top of my head, so please let me know if I missed anything…
  1. Enable Gmail API (only follow “enable APIs” from here, not “create credentials”. That will be explained more clearly in links 2 and 3.) https://docs.uipath.com/activities/docs/about-google-gsuite-activities#enable-apis
  2. Create Service Account (and download JSON keyfile) Using OAuth 2.0 for Server to Server Applications  |  Google Identity  |  Google Developers
  3. Enable Domain Wide Delegation for the Service Account, copy the Client ID
    image
    and
    image
  4. Ask your Gsuite admin to allow the Domain Wide Delegation (send him the Client ID). It took me a while to find out that you have to enable Domain Wide Delegation both on your own end, as well as on the Admin side. Uso de OAuth 2.0 para aplicaciones de servidor a servidor  |  Plataforma de identidad en Google  |  Google Developers
  5. I think this is it, but I vaguely remember having to set up the Oauth consent screen in GCP as well. If you have to configure the consent screen, just put Application Type = public, make up a name, and put your e-mail as Support Email. The consent screen won’t be shown, as you’re using a Service Account which is pre-authenticated.

Please let me know if this was of any help, and if you managed to get through.

Strangely, the Gsuite activities are working fine with 1.3.0 but not working thru 1.8.0.
When using 1.8.0 version the following error is occurring “Find Files and Folders: Error:“unauthorized_client”, Description:“Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested.”, Uri:“””.
While same activity is working fine with 1.3.0 version. Uipath studio and robot is 2019.4.4.

I used your OAuth sample and it worked great for me. BTW, “Other” is no longer an option for application type and so I used Desktop application.