Resource Owner Password Credentials Grant を Guzzle3を使って書いたサンプルです。
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
<?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']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$settings
のところはよしなに各自書き換えてください。