Search code examples
phpoauth-2.0google-oauthgoogle-calendar-api

How to Google-Authentication OAuth2 into an account with given login-data?


My aim is it to write a php script that query all events from an existing google calendar of one specific google account.

The default scripts to do this works fine. At the moment it works so: Request my php script --> it recognizes that is has no $_GET['code'] parameter --> redirect the browser to google for login --> after login google redirects back to my php script --> and the query on the calendar can be done

But what i want to do now: is that my php script performs the login into this specific google account with the username and password. I have and my script shell retrieve the $_GET['code'] parameter without any user interaction.

I have already spent lots of hours researching and testing but i have not found any solution yet.

Is that even possible? If it is there a way to pass these login datails (username and password) within the request to google authendication to the two-step login form?

In this thread is an hint to use service-accounts: Fatal error: Class 'Google_Auth_AssertionCredentials' not found but i have not figured out how to do this.

Thanks in advance.


Solution

  • Logging in to a google account using username and password i was called client login. Google shut this down in 2015.

    This is no longer an option. If you want to access private user data you need to use Oauth2 and request authorization as you are doing currently.

    service accounts

    Note: to clarify @CBroe statement in comments.

    Service accounts only work with google calendar if you are using a google workspace domain accounts. You would need to configure domain wide delegation and set up the service account to impersonate a user on the domain.

    For standard Gmail user accounts service accounts are not possible with google calendar api.