Skip to content

Commit

Permalink
feat!: v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Feb 18, 2021
1 parent b346c07 commit 1bbcabb
Show file tree
Hide file tree
Showing 114 changed files with 6,955 additions and 11,061 deletions.
19 changes: 0 additions & 19 deletions .github/actions/unittest/entrypoint.sh

This file was deleted.

24 changes: 0 additions & 24 deletions .github/actions/unittest/retry.php

This file was deleted.

72 changes: 3 additions & 69 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
operating-system: [ ubuntu-latest ]
php: [ "5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0" ]
php: [ 7.1, 7.2, 7.3, 7.4, "8.0" ]
name: PHP ${{matrix.php }} Unit Test
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
strategy:
matrix:
operating-system: [ ubuntu-latest ]
php: [ "5.6", "7.0", "7.1", "7.2" ]
php: [ 7.1 ]
name: PHP ${{matrix.php }} Unit Test Prefer Lowest
steps:
- uses: actions/checkout@v2
Expand All @@ -58,72 +58,6 @@ jobs:
command: composer update --prefer-lowest
- name: Run Script
run: vendor/bin/phpunit
guzzle6:
runs-on: ubuntu-latest
strategy:
matrix:
operating-system: [ ubuntu-latest ]
php: [ "5.6", "7.2" ]
name: PHP ${{ matrix.php }} Unit Test Guzzle 6
steps:
- uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- name: Install Dependencies
uses: nick-invision/retry@v1
with:
timeout_minutes: 10
max_attempts: 3
command: composer require guzzlehttp/guzzle:^6 && composer update
- name: Run Script
run: vendor/bin/phpunit
# use dockerfiles for oooooolllllldddd versions of php, setup-php times out for those.
test_php55:
name: "PHP 5.5 Unit Test"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run Unit Tests
uses: docker://php:5.5-cli
with:
entrypoint: ./.github/actions/unittest/entrypoint.sh
test_php55_lowest:
name: "PHP 5.5 Unit Test Prefer Lowest"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run Unit Tests
uses: docker://php:5.5-cli
env:
composerargs: "--prefer-lowest"
with:
entrypoint: ./.github/actions/unittest/entrypoint.sh
test_php54:
name: "PHP 5.4 Unit Test"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run Unit Tests
uses: docker://php:5.4-cli
with:
entrypoint: ./.github/actions/unittest/entrypoint.sh
test_php54_lowest:
name: "PHP 5.4 Unit Test Prefer Lowest"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run Unit Tests
uses: docker://php:5.4-cli
env:
composerargs: "--prefer-lowest"
with:
entrypoint: ./.github/actions/unittest/entrypoint.sh
style:
runs-on: ubuntu-latest
name: PHP Style Check
Expand All @@ -132,7 +66,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"
php-version: 7.4
- name: Install Dependencies
uses: nick-invision/retry@v1
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ composer.lock
.cache
.docs
.gitmodules
.phpunit.result.cache

# IntelliJ
.idea
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@

## 1.5.1 (04/16/2019)

* [fix] Moved `getClientName()` from `Google\Auth\FetchAuthTokenInterface`
to `Google\Auth\SignBlobInterface`, and removed `getClientName()` from
* [fix] Moved `getClientEmail()` from `Google\Auth\FetchAuthTokenInterface`
to `Google\Auth\SignBlobInterface`, and removed `getClientEmail()` from
`InsecureCredentials` and `UserRefreshCredentials`. (#223)

## 1.5.0 (04/15/2019)
Expand Down
92 changes: 27 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
<dt>Homepage</dt><dd><a href="http://www.github.com/google/google-auth-library-php">http://www.github.com/google/google-auth-library-php</a></dd>
<dt>Reference Docs</dt><dd><a href="https://googleapis.github.io/google-auth-library-php/master/">https://googleapis.github.io/google-auth-library-php/master/</a></dd>
<dt>Authors</dt>
<dd><a href="mailto:[email protected]">Tim Emiola</a></dd>
<dd><a href="mailto:[email protected]">Stanley Cheung</a></dd>
<dd><a href="mailto:[email protected]">Brent Shaffer</a></dd>
<dt>Copyright</dt><dd>Copyright © 2015 Google, Inc.</dd>
<dd><a href="mailto:[email protected]">David Supplee</a></dd>
<dt>Copyright</dt><dd>Copyright © 2020 Google LLC</dd>
<dt>License</dt><dd>Apache 2.0</dd>
</dl>

Expand All @@ -19,17 +18,10 @@ authorization and authentication with Google APIs.
### Installing via Composer

The recommended way to install the google auth library is through
[Composer](http://getcomposer.org).
[Composer](http://getcomposer.org). Run the Composer command to install the latest stable version:

```bash
# Install Composer
curl -sS https://getcomposer.org/installer | php
```

Next, run the Composer command to install the latest stable version:

```bash
composer.phar require google/auth
composer require google/auth
```

## Application Default Credentials
Expand Down Expand Up @@ -78,62 +70,38 @@ As long as you update the environment variable below to point to *your* JSON
credentials file, the following code should output a list of your Drive files.

```php
use Google\Auth\ApplicationDefaultCredentials;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Google\Auth\GoogleAuth;
use GuzzleHttp\Psr7\Request;

// specify the path to your application credentials
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/credentials.json');

// define the scopes for your API call
$scopes = ['https://www.googleapis.com/auth/drive.readonly'];

// create middleware
$middleware = ApplicationDefaultCredentials::getMiddleware($scopes);
$stack = HandlerStack::create();
$stack->push($middleware);
// create the auth client
$auth = new GoogleAuth();

// create the HTTP client
$client = new Client([
'handler' => $stack,
'base_uri' => 'https://www.googleapis.com',
'auth' => 'google_auth' // authorize all requests
]);
// authorize an http client
$client = $auth->makeHttpClient(['scope' => $scope]);

// make the request
$response = $client->get('drive/v2/files');
$request = new Request('GET', 'https://www.googleapis.com/drive/v2/files');
$response = $client->send($request);

// show the result!
print_r((string) $response->getBody());
```

##### Guzzle 5 Compatibility

If you are using [Guzzle 5][Guzzle 5], replace the `create middleware` and
`create the HTTP Client` steps with the following:

```php
// create the HTTP client
$client = new Client([
'base_url' => 'https://www.googleapis.com',
'auth' => 'google_auth' // authorize all requests
]);

// create subscriber
$subscriber = ApplicationDefaultCredentials::getSubscriber($scopes);
$client->getEmitter()->attach($subscriber);
```

#### Call using an ID Token
If your application is running behind Cloud Run, or using Cloud Identity-Aware
Proxy (IAP), you will need to fetch an ID token to access your application. For
this, use the static method `getIdTokenMiddleware` on
`ApplicationDefaultCredentials`.
`GoogleAuth`.

```php
use Google\Auth\ApplicationDefaultCredentials;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Google\Auth\GoogleAuth;
use GuzzleHttp\Psr7\Request;

// specify the path to your application credentials
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/credentials.json');
Expand All @@ -144,21 +112,15 @@ putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/credentials.json');
// $targetAudience = 'https://service-1234-uc.a.run.app';
$targetAudience = 'YOUR_ID_TOKEN_AUDIENCE';

// create middleware
$middleware = ApplicationDefaultCredentials::getIdTokenMiddleware($targetAudience);
$stack = HandlerStack::create();
$stack->push($middleware);

// create the HTTP client
$client = new Client([
'handler' => $stack,
'auth' => 'google_auth',
// Cloud Run, IAP, or custom resource URL
'base_uri' => 'https://YOUR_PROTECTED_RESOURCE',
]);
// create the auth client
$auth = new GoogleAuth();

// authorize an http client
$client = $auth->makeHttpClient(['targetAudience' => $targetAudience]);

// make the request
$response = $client->get('/');
$request = new Request('GET', 'https://YOUR_PROTECTED_RESOURCE');
$response = $client->send($request);

// show the result!
print_r((string) $response->getBody());
Expand All @@ -178,9 +140,9 @@ If you are [using Google ID tokens to authenticate users][google-id-tokens], use
the `Google\Auth\AccessToken` class to verify the ID token:

```php
use Google\Auth\AccessToken;
use Google\Auth\GoogleAuth;

$auth = new AccessToken();
$auth = new GoogleAuth();
$auth->verify($idToken);
```

Expand All @@ -190,11 +152,11 @@ appropriate certificate URL for IAP. This is because IAP signs the ID
tokens with a different key than the Google Identity service:

```php
use Google\Auth\AccessToken;
use Google\Auth\GoogleAuth;

$auth = new AccessToken();
$auth = new GoogleAuth();
$auth->verify($idToken, [
'certsLocation' => AccessToken::IAP_CERT_URL
'certsLocation' => GoogleAuth::IAP_CERT_URL
]);
```

Expand Down
Loading

0 comments on commit 1bbcabb

Please sign in to comment.