Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google API Authentication for server

I've been trying to get Google's Calendar API working in a PHP web application, but I'm having a hard time getting authenticated.

What I want to do is to allow users to interact with calendars of a single account known by the server.

Each type of scenario covered in the OAuth 2.0 docs talks about "user consent" which involves a login form and the individual user logging in, but I want the server itself to authenticate directly and obtain an access token for itself.

Is there some part of OAuth or some alternative mechanism I can use to do this?

like image 499
andy Avatar asked Mar 14 '12 14:03

andy


People also ask

How do I authenticate my Google API?

With a user account, you can authenticate to Google APIs and services in the following ways: Use the gcloud CLI to set up Application Default Credentials (ADC). Use the gcloud CLI to generate access tokens. Use your user credentials to impersonate a service account.

How can I use Google API without OAuth?

The strict answer to "Is there a way to do this without OAuth and just an API key and/or client id and secret?" is no. However, you can achieve what you are looking for using OAuth. You simply need to store a Refresh Token, which you can then use any time to request an Auth Token to access your gmail.


1 Answers

In order to do this, you must go through the steps for user consent and then copy the access tokens it gives you into the PHP code.

The usual procedure for OAuth is like this:

  1. Send user to authentication page.
  2. User comes back with $_GET['code']
  3. Send $_GET['code'] to OAuth server for a token
  4. Store token in database for the user (or session, if it's very short lived)

But when doing it with a single calendar like this, you modify step 4. Instead, you dump the token to screen and copy it into your PHP file as variables, instead of putting it in the database. Then when you go to pass the access token to the server, you just pass the known, static token rather than a dynamic token from the database / session.

like image 100
kingcoyote Avatar answered Sep 21 '22 05:09

kingcoyote