PHPackages                             digitalzenworks/google-api-authorization - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. digitalzenworks/google-api-authorization

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

digitalzenworks/google-api-authorization
========================================

Google API Authorization Package File

1.2.4(3y ago)144MITPHP

Since Aug 11Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/jamesjohnmcguire/GoogleApiAuthorizerPhp)[ Packagist](https://packagist.org/packages/digitalzenworks/google-api-authorization)[ Docs](https://github.com/jamesjohnmcguire/GoogleApiAuthorizationPhp/)[ RSS](/packages/digitalzenworks-google-api-authorization/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (8)Versions (9)Used By (0)

GoogleApiAuthorization
======================

[](#googleapiauthorization)

A library for making authorization for Google API services easy.

Getting Started
---------------

[](#getting-started)

### Requirements/dependencies

[](#requirementsdependencies)

- [PHP &gt;= 8.1.1](http://php.net/)

Installation
------------

[](#installation)

### Git

[](#git)

git clone

### Composer

[](#composer)

composer require

Usage:
------

[](#usage)

There is one main class with one main static method. You can specify the authorization mode, such as 'by tokens' or 'service account' You can also use Mode::Discover, which will attempt to go through several different types of authorization until success. If none of the automatic modes succeed and promptUser is true, it will try some of the user interaction modes. You can call it like this:

```
require_once  'vendor/autoload.php';

use DigitalZenWorks\GoogleApiAuthorization\GoogleAuthorization;
use DigitalZenWorks\GoogleApiAuthorization\Mode;

$client = Authorizer::authorize(
	Mode::Discover,
	$credentialsFilePath,
	$serviceAccountFilePath,
	$tokensFilePath,
	'Google Drive API File Uploader',
	['https://www.googleapis.com/auth/drive'],
	'http://localhost:8000/test.php',
	['promptUser' => false, 'showWarnings' => false]);

if ($client === null)
{
	echo 'Oops, authorization failed';
}
else
{
	echo 'Client is initialized and authorized, lets go';
}
```

The main method parameters are:

Type:Parameter:ModeThe Mode to use.?stringThe standard project credentials json file.?stringThe service account credentials json file.?stringThe tokens json file.?stringThe name of the project requesting authorization.?arrayThe requested scopes of the project.?stringThe URL which the authorization will complete to.?arrayAdditional options.The different modes are:

Mode:DiscoverTry several different types of authorization until successOAuthPrompt the user for OAuth approval (HTTP)RequestPrompt the user for custom approval (CLI)ServiceAccountUse serice account credentialsTokenUse existing OAuth tokensThe different options are:

Option:defaultpromptUserIf needed, prompt the user for additional actiontrueshowWarningsOutput warnings, if presenttrueAdditional Examples
-------------------

[](#additional-examples)

You can call the authorization modes directly, such as:

```
		$client = Authorizer::authorizeServiceAccount(
			$serviceAccountFilePath,
			'Google Drive API File Uploader',
			['https://www.googleapis.com/auth/drive'],
			false);

		$client = Authorizer::authorizeToken(
			$credentialsFilePath,
			$tokensFilePath,
			'Google Drive API File Uploader',
			['https://www.googleapis.com/auth/drive'],
			false);
```

Using an instanciated object:

```
		$authorizer = new Authorizer('Google Drive API File Uploader',
		['https://www.googleapis.com/auth/drive'],
		['promptUser' => false, 'showWarnings' => false]);

		$client = $authorizer->apiAuthorize(
			Mode::Discover,
			$this->credentialsFilePath,
			$this->serviceAccountFilePath,
			$this->tokensFilePath,
			'http://localhost:8000/test.php');
```

View the tests.php or UnitTests.php files for more examples.

Additional Notes
----------------

[](#additional-notes)

Even when using the 'service account' mode, the service account file is optional. If a valid file doesn't exist, it will attempt to use the file specified in the environment variable GOOGLE\_APPLICATION\_CREDENTIALS.

Contributing
------------

[](#contributing)

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".

### Process:

[](#process)

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

### Coding style

[](#coding-style)

Please match the current coding style. Most notably:

1. One operation per line
2. Use complete English words in variable and method names
3. Attempt to declare variable and method names in a self-documenting manner

License
-------

[](#license)

Distributed under the MIT License. See `LICENSE` for more information.

Contact
-------

[](#contact)

James John McGuire - [@jamesmc](https://twitter.com/jamesmc) -

Project Link:

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance53

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

7

Last Release

1357d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4a9e376eda04edeaf2c673778edef648297505ea1ab769bc5c807b8f4613c4b2?d=identicon)[jamesjohnmcguire](/maintainers/jamesjohnmcguire)

---

Top Contributors

[![jamesjohnmcguire](https://avatars.githubusercontent.com/u/10033525?v=4)](https://github.com/jamesjohnmcguire "jamesjohnmcguire (133 commits)")

---

Tags

tokensoauthauthorizationgoogle apiservice account

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/digitalzenworks-google-api-authorization/health.svg)

```
[![Health](https://phpackages.com/badges/digitalzenworks-google-api-authorization/health.svg)](https://phpackages.com/packages/digitalzenworks-google-api-authorization)
```

###  Alternatives

[league/oauth2-server

A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.

6.6k136.0M248](/packages/league-oauth2-server)[league/oauth2-client

OAuth 2.0 Client Library

3.8k118.6M1.2k](/packages/league-oauth2-client)[hybridauth/hybridauth

PHP Social Authentication Library

3.4k8.5M94](/packages/hybridauth-hybridauth)[league/oauth1-client

OAuth 1.0 Client Library

99898.8M106](/packages/league-oauth1-client)[lusitanian/oauth

PHP 7.2 oAuth 1/2 Library

1.1k23.2M121](/packages/lusitanian-oauth)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

42121.2M118](/packages/league-oauth2-google)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
