laravel - 具有授权码授予的 lucadegasperi oauth2-server 给出 invalid_client 错误

标签 laravel oauth-2.0

我正在使用来自::的oauth2-server

 https://github.com/lucadegasperi/oauth2-server-laravel 

我已经使用Auth Code Grant实现了::

 github.com/lucadegasperi/oauth2-server-laravel/wiki/Implementing-an-Authorization-Server-with-the-Auth-Code-Grant 

现在,由于我是 oauth2 的新手,我尝试使用以下方式访问数据:

localhost.com/oauth/authorize?response_type=code&client_id=client1id&redirect_uri=https://www.mysite.com

但是我得到了回应

{"error":"invalid_client","error_description":"Client authentication failed."}

编辑:
路线.php

  <?php
 Route::get('/', function()
 {
   return View::make('hello');
 });

Route::group(['prefix' => 'api/v1'], function()
{
    Route::resource('API', 'APIController');
});

Route::get('oauth/authorize', ['before' => 'check-authorization-params|auth', function() {
  View::make('oauth/authorization-form', Authorizer::getAuthCodeRequestParams());
}]);

Route::post('oauth/authorize', ['before' => 'csrf|check-authorization-params|auth', function() {
  $params['user_id'] = Auth::user()->id;
  $redirectUri = '';
  if (Input::get('approve') !== null) {
      $redirectUri = Authorizer::issueAuthCode('user', $params['user_id'], $params);
  }

  if (Input::get('deny') !== null) {
      $redirectUri = Authorizer::authCodeRequestDeniedRedirectUri();
  }

  return Redirect::to($redirectUri);
}]);

Route::post('oauth/access_token', function() {
return Response::json(Authorizer::issueAccessToken());
});

Controller /OAuthController.php

<?php

use Illuminate\Routing\Controller;
use LucaDegasperi\OAuth2Server\Authorizer;

class OAuthController extends Controller
{
protected $authorizer;

public function __construct(Authorizer $authorizer)
{
    $this->authorizer = $authorizer;

    $this->beforeFilter('auth', ['only' => ['getAuthorize', 'postAuthorize']]);
    $this->beforeFilter('csrf', ['only' => 'postAuthorize']);
    $this->beforeFilter('check-authorization-params', ['only' => ['getAuthorize', 'postAuthorize']]);
}

public function postAccessToken()
{
     return Response::json($this->authorizer->issueAccessToken());
}

public function getAuthorize()
{
    return View::make('authorization-form', $this->authorizer->getAuthCodeRequestParams());
}

public function postAuthorize()
{
    // get the user id
    $params['user_id'] = Auth::user()->id;

    $redirectUri = '';

    if (Input::get('approve') !== null) {
        $redirectUri = $this->authorizer->issueAuthCode('user', $params['user_id'], $params);
    }

    if (Input::get('deny') !== null) {
        $redirectUri = $this->authorizer->authCodeRequestDeniedRedirectUri();
    }

    return Redirect::to($redirectUri);
  }
}

oauth2-server-laravel\oauth2.php

'database' => 'default',

'grant_types' => [
    'authorization_code' => [
        'class' => '\League\OAuth2\Server\Grant\AuthCodeGrant',
        'access_token_ttl' => 3600,
        'auth_code_ttl'   => 3600
    ]
],

'token_type' => 'League\OAuth2\Server\TokenType\Bearer',

'state_param' => false,

'scope_param' => false,

'scope_delimiter' => ',',

'default_scope' => 'oauth_scopes' ,

'access_token_ttl' => 3600,

'limit_clients_to_grants' => false,

'limit_clients_to_scopes' => false,

'limit_scopes_to_grants' => false,

'http_headers_only' => false,
];

最佳答案

在对服务器代码进行一些挖掘后,我发现 check-authorization-params 路由过滤器会检查 redirect_uri 是否存在于 oauth_client_endpoints 中code> 表(该表与 oauth_clients 表内部联接)。

因此,您需要在 oauth_client_endpoints 中提供 redirect_uri 以及所需的 client_id

关于laravel - 具有授权码授予的 lucadegasperi oauth2-server 给出 invalid_client 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26504105/

相关文章:

java - 处理错误: InvalidRequestException,缺少授权类型

java - 将 tokenservice 添加到端点配置时出现 Spring OAuth Bean 异常

php - laravel 中合并三个表的连接查询

php - 是 Blade 模板的元保留名称吗?

php - 如何使用 Laravel Eloquent 将多条记录插入数据库

apache - 使用 Nginx、Apache、Envoy 或其他反向代理将相互 TLS 转换为 OAuth 客户端凭证

laravel - 使用 VueJS、axios 和 Laravel 上传文件

php - 为什么我的 laravel 5.2 会在数据库类中显示未定义的方法

java - google oauth2 如何获取服务帐户的私钥

oauth-2.0 - Actions on Google - 如何撤销帐户关联?