1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51:
<?php
namespace Baguette\Mastodon\Grant;
use Baguette\Mastodon\Service\AuthFactory;
use Baguette\Mastodon\Service\Scope;
use GuzzleHttp\ClientInterface as Client;
class PasswordCredential extends Grant
{
private $username;
private $password;
public function __construct($username, $password)
{
$this->username = $username;
$this->password = $password;
}
public function auth(Client $http, AuthFactory $factory, Scope $scope)
{
return $http->request('POST', static::getPathToOAuthToken($factory->client), [
'form_params' => [
'grant_type' => 'password',
'username' => $this->username,
'password' => $this->password,
'scope' => (string)$scope,
] + static::getFormParamsWithSecret($factory),
]);
}
}