![](/img/trans.png)
[英]Trying out OAuth2 via CURL - The grant type was not specified in the request
[英]OAuth2 The grant type was not specified
我按照以下步骤操作,但是在执行此操作时:
curl -u testclient:testpass http://localhost/token.php -d 'grant_type=client_credentials'
收到这个
{"error":"invalid_request,"error_description":"The grant type was not specified in the request"}
在这种情况下,我应如何在请求中放入“ grant_type”
这是两个文件server.php
$dsn = 'mysql:dbname=oauth2;host=localhost';
$username = 'root';
$password = '';
// error reporting (this is a demo, after all!)
ini_set('display_errors',1);error_reporting(E_ALL);
require_once('../src/OAuth2/Autoloader.php');
OAuth2\Autoloader::register();
$storage = new OAuth2\Storage\Pdo(array('dsn' => $dsn, 'username' => $username, 'password' => $password));
$server = new OAuth2\Server($storage);
$server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage)); // or any grant type you like!
token.php
require_once __DIR__.'/server.php';
// Handle a request for an OAuth2.0 Access Token and send the response to the client
$server->handleTokenRequest(OAuth2\Request::createFromGlobals())->send();
这是两个文件server.php
$dsn = 'mysql:dbname=oauth2;host=localhost';
$username = 'root';
$password = '';
// error reporting (this is a demo, after all!)
ini_set('display_errors',1);error_reporting(E_ALL);
require_once('../src/OAuth2/Autoloader.php');
OAuth2\Autoloader::register();
$storage = new OAuth2\Storage\Pdo(array('dsn' => $dsn, 'username' => $username, 'password' => $password));
$server = new OAuth2\Server($storage);
$server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage)); // or any grant type you like!
token.php
require_once __DIR__.'/server.php';
// Handle a request for an OAuth2.0 Access Token and send the response to the client
$server->handleTokenRequest(OAuth2\Request::createFromGlobals())->send();
尝试这个:
curl -u testclient:testpass http://localhost/token.php -d grant_type = client_credentials
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.