【问题标题】:lucadegasperi oauth2-server with Auth Code Grant gives invalid_client error具有 Auth Code Grant 的 lucadegasperi oauth2-server 给出 invalid_client 错误
【发布时间】:2015-01-28 01:40:48
【问题描述】:

我正在使用来自:: 的 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."}

编辑:
Route.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());
});

控制器/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,
];

【问题讨论】:

  • 能否请您发布到目前为止您尝试过的代码。
  • @justrohu 我已经添加了我从 lucadegasperi 的 oauth2-server 使用的代码。验证客户端出现错误,使用哪些客户端凭证进行授权?
  • 这个问题好运吗?我遇到了同样的问题,所有其他 Grat 类型都可以正常工作,除了“authorization_code”

标签: laravel oauth-2.0


【解决方案1】:

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

因此,您需要将 redirect_uri 与所需的 client_id 一起存在于 oauth_client_endpoints 中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-13
    • 1970-01-01
    • 1970-01-01
    • 2014-07-09
    • 2021-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多