How do I authenticate Google Calendar API v3 without user interaction? - delphi

I'm using Google and external calendar sync (console application). I've tried several ways to connect to my calendar in Delphi. In the latest version of the Google API, you can choose two options:
API Key (public calendar)
OAuth2.0 (private calendar)
The calendar is not public. I looked at a couple of examples, but everywhere the need for user interaction. I want to identify myself with no user interaction. How can I do that?

I don't know about using it in Delphi but there is a client API library for java, python... I've already used the java one and it's clearly explained how to use it in the documentation.
Google Calendar API 3 Doc page:
https://developers.google.com/google-apps/calendar/
However, the service asks you to be authentified to used it (which is your problem if I understand it well, you don't want the user to have to authenticate). So I suggest you to have a look on OAuth2.0. https://developers.google.com/google-apps/calendar/auth
Here are some simple of using google-api-java-client for exemple : https://code.google.com/p/google-api-java-client/wiki/OAuth2
And you should look more precisely at Google OAuth service account possibilities.
Service Account with OAuth2.0. (See here : https://developers.google.com/accounts/docs/OAuth2#serviceaccount).
It will provide a service account for your application, from which you will be able to handle calendars for your app.
And here you will find a sample showing how to do it with Java. (https://code.google.com/p/google-api-java-client/wiki/OAuth2#Service_Accounts). But maybe this is the public API Key you are talking about... Not sure I remember properly.
I hope this will help you to figure out how to do it.

Related

Automate OAUTH2 authentication

I need to authenticate to an API using OAUTH2, however, it has to be made programmatically, no user typing stuff in a browser is permitted.
This seems like such a simple use case, but I haven't found anything online, the only thing close to it was this post, and the only answer is "yeah, you don't want to use a web browser, but what if you do?"... This doesn't help.
So, please, opening a web browser is not an option, I just want to know if Google provides any way to authenticate purely through code.
Thank you!
In order to achieve your goal, I would like to propose to use the Service account. When the Service account is used, the access token can be retrieved without using the browser.
As the points for using the Service account, please check the following points.
The Service account is not your own Google account.
For example, as one of several situations, if you want to manage a file in your Google Drive using the Service account, please share the file with the Service account. By this, the Service account can access to the file in your Google Drive.
References:
OAuth2ServiceAccount
Several cases using the Service account
Google Drive Access - Service Account or OAuth - To read/write user files
Google service account not being authorized for calendar API
Service Account for google sheets returns not found

Linking Google Assistant with Firebase Auth

I am attempting to connect a Google Assistant app using DialogFlow(Api.AI) with Firebase Auth. My App uses Firebase Auth to maintain user accounts and the realtime database to store data. I would like to be able to make changes to a user's data through the Google Assistant, maybe using something like a cloud function. In order to make any user changes through Google Assistant, I need to link the user's Google Assistant account with their Firebase Auth account. The current mechanism appears to be using an OAuth flow documented here.
The question I have is, what is the best way to accomplish this? Do I need to set up a custom OAuth server? There is a lot of documentation on Google's cloud website about OAuth, but it all appears to be related to using OAuth to access Google's APIs, and I can't really see a simple way to host this linking mechanism in GCP.
There is this question that is pretty close, but the difference I have is that I don't have an external API, I just want to authenticate my user and be able to modify their data in the realtime database.
Thank you for your help!
here is an example: https://github.com/malikasinger1/Quiz-Assistant
i have done it myself with following best practices,
feel free to comment if you don't understand something.

Access Google Calendar in IOS using Service Account

I need to access a NON-public Google calendar WITHOUT requiring the user to log in or even have a Google account.
I created an Android app that accesses a Google calendar using a service account:
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(serviceAccountID)
.setServiceAccountScopes(scopes)
.setServiceAccountPrivateKeyFromP12File(licenseFile)
.build();
com.google.api.services.calendar.Calendar.Builder builder = new com.google.api.services.calendar.Calendar.Builder(httpTransport, jsonFactory, credential);
builder.setApplicationName(appName);
com.google.api.services.calendar.Calendar client = builder.build();
com.google.api.services.calendar.Calendar.Events.List list = client.events().list(calendarID);
list.setMaxAttendees(maxAttendees);
list.setTimeZone(timeZone);
list.setTimeMin(startTime);
list.setTimeMax(endTime);
list.setOrderBy(orderBy);
list.setShowDeleted(showDeleted);
list.setSingleEvents(true);
Events events = list.execute();
This included:
Creating a project in the Google App console
Creating a Service Account
Giving the Service Account access rights to the Google calendar
It works GREAT!
I need to do the same thing in IOS. I have read every question/answer I can find on this topic and have found VERY different answers. Many say that Google hasn't allowed this in the IOS SDK because service accounts are intended to be used by server-based applications. I don't agree since the functionality I need is available in Android. So, now what?
The use case is this:
My IOS app needs to access a Google calendar. That part is not too tough if you are okay with using OAuth. My problems with this approach are:
Requires to user to have a Google account. Many of my users are Apple-Only. I can't require them to get a Google account just to use my app.
I can't make the calendar public. So, I would need to give access to every new user. I guess I could do that with a web-based application but this doesn't fix the problem (refer to previous problem - no Google account).
I really need to be able to query the events in the NON-public Google Calendar WITHOUT the user needing a Google account. The solution IS using a "Service Account" (I think).
I read one question/answer that said this is possible but the solution was never posted. (How to list Google Calendar Events without User Authentication)
HELP!!!!
The official documentation suggests that if you want to handle Calendar API (for example), you'll have to have a Google Apps for Work (source).
If you have a Google Apps domain—if you use Google Apps for Work, for example—an administrator of the Google Apps domain can authorize an application to access user data on behalf of users in the Google Apps domain. For example, an application that uses the Google Calendar API to add events to the calendars of all users in a Google Apps domain would use a service account to access the Google Calendar API on behalf of users.
Once the prerequisite is met, you can try to just call the REST URLs of Calendar API based on your implementation (since there seems to be no iOS support or samples available in the documentation).

Single Sign-On For Google Calendar API?

I have recently implemented the Google Calendar API into my iOS project using the instructions from this: https://developers.google.com/google-apps/calendar/quickstart/ios#further_reading
After some testing I noticed that I have to sign in each time the user wants to update the calendars from Google, which is not what I want.
I looked around and saw something like GPPSignIn, however that is not incorporated into this specific library.
Does anyone know a way to implement SSO for the calendar specific API that google offers, or do I have to implement it another way using the Google Plus library somehow. Any advice would be appreciated.

Google Drive API for iOS: OAuth2.0 with an application-owned account

I'm creating a simple iPhone app. The basic premise is that the app will display some data (That I provide online) on the application. The data changes over time, so the app has to draw the data from online and display it. I don't have a significant programming background so I don't want to use my own server.
Thus, I thought it would be significantly easier to just put the data into some documents on a Google account and then access them programmatically via the Google Drive API. I could then update the data in my Drive account and it would get updated in the application. The key here is that I am ONLY accessing ONE account that I own MYSELF. The users' accounts are not being accessed. Therefore the goal is to never have to log in manually. It should all happen behind the scenes, aka, it should look like a server, not a google doc.
With this in mind, it doesn't make sense to show the Google Accounts sign-in page to my users as the standard OAuth2.0 tutorial shows here:https://developers.google.com/drive/quickstart-ios#step_1_enable_the_drive_api
I should be able to access my own data by somehow hardcoding in my username, password etc. Google agrees here: https://developers.google.com/drive/service-accounts#use_regular_google_accounts_as_application-owned_accounts
The above link mentions a "refresh token" that I'm supposed to save. However, I have no idea how to build and save that token, or even for that matter, where to find it.
I've gone through both the basic tutorial and the Dr. Edit Tutorial for iOS, but they both assume that the application is accessing USER accounts not application-owned accounts.
I'm not asking for someone to write the code for me (though tidbits are nice), but if you can point me to a step-by-step guide or related sample code that would help me get started that would be awesome. I'll even come back and post the code that I use!
EDIT: Since I realized that the Google Drive API wasn't something I could use for what I am trying to do, I eventually found Parse which is an awesome tool that handles all the server backend for me and is free at the basic level.
Google APIs objective-C client library doesn't support service (application-owned) accounts, because they are supposed to be used by a server-side apps, instead of clients -- you shouldn't be distributing your private key as a part of an app.
If you would like to distribute content from a service account, maybe you should write a server leg to do the authentication and pass clients credentials in a secure way for them to talk to the API on the behalf of the service account. Or, use Web publishing to make documents universally accessible without authorization and authentication if privacy is not a concern.

Resources