Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Resource Owner Password Credentials Grant を Guzzle3を使って書いたサンプルです。
<?php
require 'vendor/autoload.php';
use Guzzle\Http\Client;
use CommerceGuys\Guzzle\Plugin\Oauth2\GrantType\PasswordCredentials;
$settings = parse_ini_file('config/settings.ini');
# Resource Owner Password Credentials Grant
$oauth2Client = new Client($settings['base_url'] . '/oauth/token');
$config = array(
'username' => $settings['username'],
'password' => $settings['password'],
'client_id' => $settings['client_id'],
'client_secret' => $settings['client_secret'],
// 'client_id' => null, # null でもよい
// 'client_secret' => null, # null でもよい
'scope' => $settings['scope'], // Optional.
);
$grantType = new PasswordCredentials($oauth2Client, $config);
$tokenData = $grantType->getTokenData();
var_dump($tokenData['access_token']);
@mapyo

This comment has been minimized.

Copy link
Owner Author

@mapyo mapyo commented Nov 1, 2014

$settingsのところはよしなに各自書き換えてください。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment