Skip to content

Commit

Permalink
Merge pull request #5 from mxr576/app_credentials_fix
Browse files Browse the repository at this point in the history
API key generation: Callback URL also must be included in the request
  • Loading branch information
mxr576 authored May 23, 2018
2 parents c07bcd4 + 80ad7b0 commit 77a5b2f
Show file tree
Hide file tree
Showing 46 changed files with 433 additions and 174 deletions.
12 changes: 8 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
root = true

# All files.
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
end_of_line = LF
indent_style = space
insert_final_newline = true
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[composer.{json,lock}]
indent_size = 4
9 changes: 5 additions & 4 deletions examples/create_new_app_with_credential.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
/** @var \Apigee\Edge\Api\Management\Entity\DeveloperApp $developerApp */
$developerApp = new DeveloperApp(['name' => 'test_app_1']);
$developerApp->setDisplayName('My first app');
$developerApp->setAttributes(new AttributesProperty(['bar' => 'baz']));
$dac->create($developerApp);

$dacc = new DeveloperAppCredentialController($organization, $developerMail, $developerApp->id(), $client);
$attributes = new AttributesProperty(['foo' => 'bar']);
$credAttributes = new AttributesProperty(['foo' => 'bar']);
$apiProducts = ['product_1', 'product_2'];
$scopes = ['scope 1', 'scope 2'];

Expand All @@ -48,16 +49,16 @@
/** @var \Apigee\Edge\Api\Management\Entity\AppCredential $credential */
$credential = reset($credentials);
$dacc->addProducts($credential->id(), $apiProducts);
$dacc->overrideAttributes($credential->id(), $attributes);
$dacc->updateAttributes($credential->id(), $credAttributes);
$dacc->overrideScopes($credential->id(), $scopes);

// Create a new, auto-generated credential that expires after 1 week.
$dacc->generate($apiProducts, $attributes, $scopes, 604800000);
$dacc->generate($apiProducts, $developerApp->getAttributes(), $developerApp->getCallbackUrl(), $scopes, 604800000);

// Create a credential with a specific key and secret and add the same products, attributes and scopes to it.
$credential = $dacc->create('MY_CONSUMER_KEY', 'MY_CONSUMER_SECRET');
$dacc->addProducts($credential->id(), $apiProducts);
$dacc->overrideAttributes($credential->id(), $attributes);
$dacc->updateAttributes($credential->id(), $credAttributes);
$dacc->overrideScopes($credential->id(), $scopes);
} catch (ClientErrorException $e) {
// HTTP code >= 400 and < 500. Ex.: 401 Unauthorised.
Expand Down
4 changes: 3 additions & 1 deletion src/Api/Management/Controller/AppCredentialController.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public function create(string $consumerKey, string $consumerSecret): AppCredenti
public function generate(
array $apiProducts,
AttributesProperty $appAttributes,
string $callbackUrl,
array $scopes = [],
string $keyExpiresIn = '-1'
): AppCredentialInterface {
Expand All @@ -102,8 +103,9 @@ public function generate(
(string) json_encode((object) [
'apiProducts' => $apiProducts,
'attributes' => $this->entityTransformer->normalize($appAttributes),
'scopes' => $scopes,
'callbackUrl' => $callbackUrl,
'keyExpiresIn' => $keyExpiresIn,
'scopes' => $scopes,
])
);
// It returns a complete developer app entity, but we only returns the newly created credential for the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public function create(string $consumerKey, string $consumerSecret): AppCredenti
* @param \Apigee\Edge\Structure\AttributesProperty $appAttributes
* Current attributes of the app. "In this API call, be sure to include any existing app attributes.
* If you don't, the existing attributes are deleted."
* @param string callbackUrl
* Current callback url of the app. (If you don't include it then the existing callback url gets deleted.)
* @param string[] $scopes
* List of OAuth scopes (from API products).
* @param string $keyExpiresIn
Expand All @@ -66,6 +68,7 @@ public function create(string $consumerKey, string $consumerSecret): AppCredenti
public function generate(
array $apiProducts,
AttributesProperty $appAttributes,
string $callbackUrl,
array $scopes = [],
string $keyExpiresIn = '-1'
): AppCredentialInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public function testGenerate(): string
$credential = $controller->generate(
[static::$apiProductName],
$app->getAttributes(),
$app->getCallbackUrl(),
['scope 1'],
604800000
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"lastModifiedBy": "[email protected]",
"name": "phpunit_test",
"proxies": [],
"quota" : "10",
"quota": "10",
"quotaInterval": "1",
"quotaTimeUnit": "minute",
"scopes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"lastModifiedBy": "[email protected]",
"name": "phpunit_test",
"proxies": [],
"quota" : "10",
"quota": "10",
"quotaInterval": "1",
"quotaTimeUnit": "minute",
"scopes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"lastModifiedBy": "[email protected]",
"name": "phpunit_test",
"proxies": [],
"quota" : "1000",
"quota": "1000",
"quotaInterval": "12",
"quotaTimeUnit": "hour",
"scopes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"value": "value2"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"value": "value2"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "name1",
"value": "value1"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "name1",
"value": "value1-edited"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
"name": "phpunit_test_app",
"scopes": [],
"status": "approved"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"value": "value2"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
"value": "This is a test app created by PHP Unit."
}
]
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "name1",
"value": "value1"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "name1",
"value": "value1-edited"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"issuedAt": 648345600000,
"scopes": [],
"status": "approved"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"issuedAt": 648345600000,
"scopes": [],
"status": "approved"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"issuedAt": 648345600000,
"scopes": [],
"status": "approved"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"scope 1"
],
"status": "approved"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,4 @@
"lastModifiedBy": "[email protected]"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
"status": "approved"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
"name": "phpunit_test_app",
"scopes": [],
"status": "approved"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
"name": "phpunit_test_app",
"scopes": [],
"status": "approved"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
"name": "phpunit_test_app",
"scopes": [],
"status": "approved"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"value": "value2"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
"value": "This is a test app created by PHP Unit."
}
]
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "name1",
"value": "value1"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "name1",
"value": "value1-edited"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"issuedAt": 648345600000,
"scopes": [],
"status": "approved"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"issuedAt": 648345600000,
"scopes": [],
"status": "approved"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"issuedAt": 648345600000,
"scopes": [],
"status": "approved"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"scope 1"
],
"status": "approved"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"value": "value2"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"value": "value2"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "name1",
"value": "value1"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "name1",
"value": "value1-edited"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"value": "value2"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"value": "value2"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "name1",
"value": "value1"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "name1",
"value": "value1-edited"
}
}
Loading

0 comments on commit 77a5b2f

Please sign in to comment.