Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/contamobi/pmobi-oauth2-php-client


https://github.com/contamobi/pmobi-oauth2-php-client

guzzlehttp middleware oauth2-client php71

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

### pague.MOBI Oauth2 Middleware

This is GuzzleHttp Middleware for pague.MOBI Oauth2. Based on [Guzzle OAuth 2.0 Subscriber](https://github.com/kamermans/guzzle-oauth2-subscriber).

##### Usage

With classes
```php
"https://anything.p.mobi/oauth2/token",
]);

$authConfig = [
"client_id" => "your-client-id",
"client_secret" => "your-client-secret",
"username" => "your-username",
"password" => "your-password",
];

$grantType = new PmobiCredentials($authClient, $authConfig);
$oauth = new OAuth2Middleware($grantType);
$stack = HandlerStack::create();
$stack->push($oauth);

$client = new Client([
'handler' => $stack,
'auth' => 'oauth',
]);

$response = $client->request(
'get',
'https://anything.p.mobi/anywhere',
[
'headers' => [
'Content-Type' => 'application/json',
],
]
);

var_dump($response->getBody()->getContents());
```

With Pmobi Middleware
```php
"https://anything.p.mobi/oauth2/token",
"client_id" => "your-client-id",
"client_secret" => "your-client-secret",
"username" => "your-username",
"password" => "your-password",
];

// Optional
$authConfig["token_filepath"] = "/tmp/access_token.json";

$stack = PmobiOauth2Middleware::createFromConfig($reauthConfig);

$client = new Client([
'handler' => $stack,
'auth' => 'oauth',
]);

$response = $client->request(
'get',
'https://anything.p.mobi/anywhere',
[
'headers' => [
'Content-Type' => 'application/json',
],
]
);

var_dump($response->getBody()->getContents());
```

Token persistence
```php
setTokenPersistence($tokenPersistence);

```

More information about persistence in [https://github.com/kamermans/guzzle-oauth2-subscriber#access-token-persistence](https://github.com/kamermans/guzzle-oauth2-subscriber#access-token-persistence).