Skip to content

Instantly share code, notes, and snippets.

@mapyo
Created November 1, 2014 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mapyo/b12b0cb651d02b76f5e9 to your computer and use it in GitHub Desktop.
Save mapyo/b12b0cb651d02b76f5e9 to your computer and use it in GitHub Desktop.
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
Copy link
Author

mapyo commented Nov 1, 2014

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

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