Download the PHP package ericnorris/gcp-auth-contrib without Composer

On this page you can find all versions of the php package ericnorris/gcp-auth-contrib. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package gcp-auth-contrib

= gcp-auth-contrib // asciidoc settings :toc: :toc-placement!: :toc-title!:

[.lead] image:https://github.com/ericnorris/gcp-auth-contrib/workflows/CI/badge.svg[CI status, link=https://github.com/ericnorris/gcp-auth-contrib/actions?query=workflow%3ACI] image:https://coveralls.io/repos/github/ericnorris/gcp-auth-contrib/badge.svg[Coveralls.io coverage percentage, link=https://coveralls.io/github/ericnorris/gcp-auth-contrib] image:https://shepherd.dev/github/ericnorris/gcp-auth-contrib/coverage.svg[Psalm type coverage percentage, link=https://shepherd.dev/github/ericnorris/gcp-auth-contrib]

gcp-auth-contrib is an unofficial PHP library for authenticating with Google Cloud Platform products that focuses on sane defaults, correctness, and speed.

[source, php] ....

$fetcher = \ericnorris\GCPAuthContrib\OpinionatedDefaults::get()->makeCredentialsFetcher();

$storageClient = new \Google\Cloud\Storage\StorageClient([ "credentialsFetcher" => $fetcher, ]);

// ... ....

toc::[]

== Installation

.... composer require ericnorris/gcp-auth-contrib ....

== Usage

The following examples all make use of the link:/src/OpinionatedDefaults.php[OpinionatedDefaults] class. The defaults are:

If these defaults do not work for you, the link:/src/Credentials[Credentials] directory has a flexible set of classes you may use for authentication. It is strongly encouraged that you wrap any such classes with a link:/src/Credentials/CachedCredentials.php[CachedCredentials] instance to avoid unecessary IO.

=== Authenticating with Google Cloud Platform APIs

The Google Cloud Platform PHP library generally requires a class implementing the link:https://github.com/googleapis/google-auth-library-php/blob/9ccaea6037abff9a99b8a58891b9dc8fe0f0d1b8/src/FetchAuthTokenInterface.php[FetchAuthTokenInterface] interface to be passed in to their client via the credentials or credentialsFetcher option array key. This depends on the particular client, see link:https://googleapis.github.io/google-cloud-php/#/[the docs] for your particular client to know which one to use.

You can retrieve a FetchAuthTokenInterface compatible interface by calling makeCredentialsFetcher on the OpinionatedDefaults class.

[source, php] .... $fetcher = \ericnorris\GCPAuthContrib\OpinionatedDefaults::get()->makeCredentialsFetcher();

// the StorageClient class takes the parameter as a "credentialsFetcher" option $storageClient = new \Google\Cloud\Storage\StorageClient([ "credentialsFetcher" => $fetcher, ]);

// the BigtableClient class takes the parameter as a "credentials" option $bigtableClient = new \Google\Cloud\Bigtable\BigtableClient([ "credentials" => $fetcher, ]);

// ... ....

=== Authenticating with Google Cloud Platform serverless products

Calling authenticated Cloud Run or Cloud Function services requires an OIDC identity token. All instances of link:https://github.com/ericnorris/gcp-auth-contrib/blob/master/src/Contracts/Credentials.php[Credentials] in this library offer a separate fetchIdentityToken(string $audience) method for exactly this purpose.

Note: This includes the link:https://github.com/ericnorris/gcp-auth-contrib/blob/master/src/Credentials/AuthorizedUserCredentials.php[AuthorizedUserCredentials]! You can use a user's OAuth credentials (via gcloud auth application-default login or by doing the OAuth2 flow yourself) to call authenticated serverless products.

[source, php] .... $credentials = \ericnorris\GCPAuthContrib\OpinionatedDefaults::get()->makeCredentials();

$identityTokenResponse = $credentials->fetchIdentityToken("https://your-cloud-function-or-run-url-here");

$headers = [ "Authorization: Bearer {$identityTokenResponse->getIdentityToken()}", ];

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, "https://your-cloud-function-or-run-url-here"); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

// ... ....

=== Impersonating service accounts

You may impersonate another Google Cloud Platform service account using the link:https://cloud.google.com/iam/docs/creating-short-lived-service-account-credentials[service account impersonation] flow. Assuming the service account running the below code has the roles/iam.serviceAccountTokenCreator IAM role on an imaginary service account [email protected]:

[source, php] .... $fetcher = \ericnorris\GCPAuthContrib\OpinionatedDefaults::get()->makeImpersonatedCredentialsFetcher( "[email protected]", );

// calls will be authenticated using the other account's credentials $storageClient = new \Google\Cloud\Storage\StorageClient([ "credentialsFetcher" => $fetcher, ]);

// ... ....

=== Determining the project ID

May not be supported by all credential types.

[source, php] .... $credentials = \ericnorris\GCPAuthContrib\OpinionatedDefaults::get()->makeCredentials();

echo "project ID: {$credentials->fetchProjectID()}"; ....


All versions of gcp-auth-contrib with dependencies

PHP Build Version
Package Version
Requires guzzlehttp/psr7 Version ^1.6
guzzlehttp/guzzle Version ^6
psr/cache Version ^1.0
symfony/cache Version ^5.1
firebase/php-jwt Version ^5.2
google/auth Version ^1.13
fig/http-message-util Version ^1.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ericnorris/gcp-auth-contrib contains the following files

Loading the files please wait ...