-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from therealgambo/basic-auth-plugin
Add wrapper class for basic auth plugin
- Loading branch information
Showing
3 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace TheRealGambo\Kong\Apis\Plugins; | ||
|
||
use TheRealGambo\Kong\Apis\AbstractApi; | ||
use TheRealGambo\Kong\Apis\Consumer; | ||
|
||
final class BasicAuth extends AbstractApi implements BasicAuthInterface | ||
{ | ||
/** | ||
* Create a new consumer in Kong | ||
* | ||
* @see https://getkong.org/plugins/basic-authentication/#create-a-consumer | ||
* | ||
* @param array $body | ||
* @param array $headers | ||
* | ||
* @return array|\stdClass | ||
*/ | ||
public function createConsumer(array $body = [], array $headers = []) | ||
{ | ||
$consumer = new Consumer($this->url, $this->port); | ||
|
||
return $consumer->add($body, $headers); | ||
} | ||
|
||
/** | ||
* Create a new basic auth credential for a consumer | ||
* | ||
* @see https://getkong.org/plugins/basic-authentication/#create-a-credential | ||
* | ||
* @param string $identifier | ||
* @param array $body | ||
* @param array $headers | ||
* | ||
* @return array|\stdClass | ||
*/ | ||
public function create($identifier, array $body = [], array $headers = []) | ||
{ | ||
$this->setAllowedOptions(['username', 'password']); | ||
$body = $this->createRequestBody($body); | ||
|
||
return $this->postRequest('consumers/' . $identifier . '/basic-auth', $body, $headers); | ||
} | ||
|
||
/** | ||
* Delete a basic auth credential for a consumer | ||
* | ||
* @see | ||
* | ||
* @param $identifier | ||
* @param $auth_identifier | ||
* @param array $headers | ||
* | ||
* @return array|\stdClass | ||
*/ | ||
public function delete($identifier, $auth_identifier, array $headers = []) | ||
{ | ||
return $this->deleteRequest('consumers/' . $identifier . '/basic-auth/' . $auth_identifier, $headers); | ||
} | ||
|
||
/** | ||
* List all basic auth credentials for a consumer | ||
* | ||
* @see | ||
* | ||
* @param string $identifier | ||
* @param array $params | ||
* @param array $headers | ||
* | ||
* @return array|\stdClass | ||
*/ | ||
public function list($identifier, array $params = [], array $headers = []) | ||
{ | ||
return $this->getRequest('consumers/' . $identifier . '/basic-auth', $params, $headers); | ||
} | ||
|
||
/** | ||
* Get a single basic auth credential for a consumer | ||
* | ||
* @see | ||
* | ||
* @param string $identifier | ||
* @param string $auth_identifier | ||
* @param array $params | ||
* @param array $headers | ||
* | ||
* @return array|\stdClass | ||
*/ | ||
public function get($identifier, $auth_identifier, array $params = [], array $headers = []) | ||
{ | ||
return $this->getRequest('consumers/' . $identifier . '/basic-auth/' . $auth_identifier, $params, $headers); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace TheRealGambo\Kong\Apis\Plugins; | ||
|
||
interface BasicAuthInterface | ||
{ | ||
public function createConsumer(array $body = [], array $headers = []); | ||
public function create($identifier, array $body = [], array $headers = []); | ||
public function delete($identifier, $auth_identifier, array $headers = []); | ||
public function list($identifier, array $params = [], array $headers = []); | ||
public function get($identifier, $auth_identifier, array $params = [], array $headers = []); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters