2017 © Pedro Peláez
 

library pmobi-oauth2-php-client

Pmobi Oauth2 Client

image

contamobi/pmobi-oauth2-php-client

Pmobi Oauth2 Client

  • Wednesday, May 2, 2018
  • by joubertredrat
  • Repository
  • 1 Watchers
  • 1 Stars
  • 62 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 2 Versions
  • 343 % Grown

The README.md

pague.MOBI Oauth2 Middleware

This is GuzzleHttp Middleware for pague.MOBI Oauth2. Based on Guzzle OAuth 2.0 Subscriber., (*1)

Usage

With classes, (*2)

<?php

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use kamermans\OAuth2\OAuth2Middleware;
use Pmobi\Oauth2\GrantType\PmobiCredentials;

$authClient = new Client([
    "base_uri" => "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, (*3)

<?php

use GuzzleHttp\Client;
use Pmobi\Oauth2\Middleware as PmobiOauth2Middleware;

$authConfig = [
    "token_url" => "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, (*4)

<?php

use kamermans\OAuth2\OAuth2Middleware;
use kamermans\OAuth2\Persistence\FileTokenPersistence;

/* ... */

$tokenPersistence = new FileTokenPersistence("/tmp/access_token.json");

$oauth = new OAuth2Middleware($grantType);
$oauth->setTokenPersistence($tokenPersistence);

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

The Versions

02/05 2018

dev-master

9999999-dev

Pmobi Oauth2 Client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joubert RedRat

02/05 2018

0.1.0

0.1.0.0

Pmobi Oauth2 Client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joubert RedRat