-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
andreals
committed
Feb 23, 2024
1 parent
b31a0a3
commit 1b7b3b0
Showing
22 changed files
with
481 additions
and
29 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
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,36 @@ | ||
|
||
# Basic Authentication | ||
|
||
|
||
|
||
Documentation for accessing and setting credentials for httpBasic. | ||
|
||
## Auth Credentials | ||
|
||
| Name | Type | Description | Setter | Getter | | ||
| --- | --- | --- | --- | --- | | ||
| BasicAuthUserName | `string` | The username to use with basic authentication | `username` | `getBasicAuthUserName()` | | ||
| BasicAuthPassword | `string` | The password to use with basic authentication | `password` | `getBasicAuthPassword()` | | ||
|
||
|
||
|
||
**Note:** Auth credentials can be set using `BasicAuthCredentialsBuilder::init()` in `basicAuthCredentials` method in the client builder and accessed through `getBasicAuthCredentials` method in the client instance. | ||
|
||
## Usage Example | ||
|
||
### Client Initialization | ||
|
||
You must provide credentials in the client as shown in the following code snippet. | ||
|
||
```php | ||
$client = PagarmeApiSDKClientBuilder::init() | ||
->basicAuthCredentials( | ||
BasicAuthCredentialsBuilder::init( | ||
'BasicAuthUserName', | ||
'BasicAuthPassword' | ||
) | ||
) | ||
->build(); | ||
``` | ||
|
||
|
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
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
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,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* PagarmeApiSDKLib | ||
* | ||
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ). | ||
*/ | ||
|
||
namespace PagarmeApiSDKLib\Authentication; | ||
|
||
use Core\Utils\CoreHelper; | ||
|
||
/** | ||
* Utility class for initializing BasicAuth security credentials. | ||
*/ | ||
class BasicAuthCredentialsBuilder | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $config; | ||
|
||
private function __construct(array $config) | ||
{ | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* Initializer for BasicAuthCredentialsBuilder | ||
* | ||
* @param string $username | ||
* @param string $password | ||
*/ | ||
public static function init(string $username, string $password): self | ||
{ | ||
return new self(['basicAuthUserName' => $username, 'basicAuthPassword' => $password]); | ||
} | ||
|
||
/** | ||
* Setter for BasicAuthUserName. | ||
* | ||
* @param string $username | ||
* | ||
* @return $this | ||
*/ | ||
public function username(string $username): self | ||
{ | ||
$this->config['basicAuthUserName'] = $username; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Setter for BasicAuthPassword. | ||
* | ||
* @param string $password | ||
* | ||
* @return $this | ||
*/ | ||
public function password(string $password): self | ||
{ | ||
$this->config['basicAuthPassword'] = $password; | ||
return $this; | ||
} | ||
|
||
public function getConfiguration(): array | ||
{ | ||
return CoreHelper::clone($this->config); | ||
} | ||
} |
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,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* PagarmeApiSDKLib | ||
* | ||
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ). | ||
*/ | ||
|
||
namespace PagarmeApiSDKLib\Authentication; | ||
|
||
use Core\Authentication\CoreAuth; | ||
use Core\Request\Parameters\HeaderParam; | ||
use PagarmeApiSDKLib\BasicAuthCredentials; | ||
|
||
/** | ||
* Utility class for authorization and token management. | ||
*/ | ||
class BasicAuthManager extends CoreAuth implements BasicAuthCredentials | ||
{ | ||
private $basicAuthUserName; | ||
|
||
private $basicAuthPassword; | ||
|
||
/** | ||
* Returns an instance of this class. | ||
* | ||
* @param string $basicAuthUserName The username to use with basic authentication | ||
* @param string $basicAuthPassword The password to use with basic authentication | ||
*/ | ||
public function __construct(string $basicAuthUserName, string $basicAuthPassword) | ||
{ | ||
parent::__construct( | ||
HeaderParam::init('Authorization', 'Basic ' . base64_encode("$basicAuthUserName:$basicAuthPassword")) | ||
->required() | ||
); | ||
$this->basicAuthUserName = $basicAuthUserName; | ||
$this->basicAuthPassword = $basicAuthPassword; | ||
} | ||
|
||
/** | ||
* String value for basicAuthUserName. | ||
*/ | ||
public function getBasicAuthUserName(): string | ||
{ | ||
return $this->basicAuthUserName; | ||
} | ||
|
||
/** | ||
* String value for basicAuthPassword. | ||
*/ | ||
public function getBasicAuthPassword(): string | ||
{ | ||
return $this->basicAuthPassword; | ||
} | ||
|
||
/** | ||
* Checks if provided credentials match with existing ones. | ||
* | ||
* @param string $basicAuthUserName The username to use with basic authentication | ||
* @param string $basicAuthPassword The password to use with basic authentication | ||
*/ | ||
public function equals(string $basicAuthUserName, string $basicAuthPassword): bool | ||
{ | ||
return $basicAuthUserName == $this->basicAuthUserName && | ||
$basicAuthPassword == $this->basicAuthPassword; | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* PagarmeApiSDKLib | ||
* | ||
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ). | ||
*/ | ||
|
||
namespace PagarmeApiSDKLib; | ||
|
||
/** | ||
* Interface for defining the behavior of Authentication. | ||
*/ | ||
interface BasicAuthCredentials | ||
{ | ||
/** | ||
* String value for basicAuthUserName. | ||
*/ | ||
public function getBasicAuthUserName(): string; | ||
|
||
/** | ||
* String value for basicAuthPassword. | ||
*/ | ||
public function getBasicAuthPassword(): string; | ||
|
||
/** | ||
* Checks if provided credentials match with existing ones. | ||
* | ||
* @param string $basicAuthUserName The username to use with basic authentication | ||
* @param string $basicAuthPassword The password to use with basic authentication | ||
*/ | ||
public function equals(string $basicAuthUserName, string $basicAuthPassword): bool; | ||
} |
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
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
Oops, something went wrong.