Skip to content

Instantly share code, notes, and snippets.

@mxr576
Last active July 2, 2018 13:49
Show Gist options
  • Save mxr576/e894d454dbe1c31c812ca6db7c785670 to your computer and use it in GitHub Desktop.
Save mxr576/e894d454dbe1c31c812ca6db7c785670 to your computer and use it in GitHub Desktop.
Apigee PHP API client OAuth test
<?php
require_once "vendor/autoload.php";
require_once "examples/authentication.inc";
$envCredProd = new EnvironmentCredentialProvider();
$auth = new \Apigee\Edge\HttpClient\Plugin\Authentication\Oauth($envCredProd->getUsername(), $envCredProd->getPassword(), new \Apigee\Edge\Tests\Test\HttpClient\Plugin\InMemoryOauthTokenStorage(), null, getenv('APIGEE_EDGE_PHP_SDK_CLIENT_ID') ?: null, getenv('APIGEE_EDGE_PHP_SDK_CLIENT_SECRET' ?: null), null, getenv('APIGEE_EDGE_PHP_SDK_AUTH_SERVER') ?: null);
$client = new \Apigee\Edge\Client($auth);
$envc = new \Apigee\Edge\Api\Management\Controller\EnvironmentController($envCredProd->getOrganization(), $client);
try {
$list = $envc->getEntityIds();
print_r($list);
}
catch (\Exception $e) {
print $e;
}
exit(0);
@mxr576
Copy link
Author

mxr576 commented Jul 2, 2018

git clone https://github.com/apigee/apigee-client-php.git
cd apigee-client-php
composer install
wget https://gist.githubusercontent.com/mxr576/e894d454dbe1c31c812ca6db7c785670/raw -O oauth.php

# Set required credentials.
export APIGEE_EDGE_PHP_SDK_BASIC_AUTH_USER=[[email protected]]
export APIGEE_EDGE_PHP_SDK_BASIC_AUTH_PASSWORD=[PASSWORD]
export APIGEE_EDGE_PHP_SDK_ORGANIZATION=[ORGANIZATION]
# If you have custom client id and secret set those too.
# export APIGEE_EDGE_PHP_SDK_CLIENT_ID=[CLIENT_ID]
# export APIGEE_EDGE_PHP_SDK_CLIENT_SECRET=[CLIENT_SECRET]
# export APIGEE_EDGE_PHP_SDK_AUTH_SERVER=[AUTH_SERVER]

php oauth.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment