欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

oauth 报错{"error":"invalid_client","error_description":"Client authentication failed."} 有大用

lucadegasperi oauth2-server with Auth Code Grant gives invalid_client error

I am using oauth2-server from::

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

I have implemented using Auth Code Grant::

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

Now as i am new to oauth2 i have tried to access to the data using::

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

but in response i have got

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

Edit:
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());
});

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,
];
shareimprove this question
 
  
could you please post code you have tried so far.justrohuOct 22 '14 at 11:44
  
@justrohu I have added the codes that i have used from the lucadegasperi's oauth2-server. There is error when validating the client and which client credientals are used for authorization?PaladiNOct 23 '14 at 11:44
  
Any luck with this issue ? I'm having same problem, all other Grat types work fine, except "authorization_code"PlaynoxJan 21 '15 at 22:55

1 Answer 正确答案

After doing some digging in the server codes I found that thecheck-authorization-paramsroute filter checks whether theredirect_uriis present in theoauth_client_endpointstable (the table is inner joined with theoauth_clientstable).

So you need to have theredirect_uripresent inoauth_client_endpointswith the desiredclient_id.

shareimprove this answer
 

来自 https://stackoverflow.com/questions/26504105/lucadegasperi-oauth2-server-with-auth-code-grant-gives-...



  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

lucadegasperi oauth2服务器认证代码授予给invalid_client误差

 

我用oauth2服务器::

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

我已经使用验证码批准实施::

 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服务器- 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,
];
分享改善这个问题
 
  
请邮政编码你有尝试过。justrohu10月22 14在11:44
  
“justrohu我已经添加了代码,我从lucadegasperi的oauth2服务器使用。有错误时,验证客户端和客户端credientals用于授权?圣骑士10月23日”在11 14:44
  
运气好的话,这个问题?我有同样的问题,所有其他内容类型做工精细,除了“authorization_code”playnox15年1月21日22:55

1回答 正确答案

做一些挖掘后的服务器代码,我发现check-authorization-params路由过滤检查是否_重定向URI是目前在oauth_client_endpoints表(表内加入了clients OAuth _表)。

所以你需要有redirect_uri目前在OAuth _ _端点客户端与期望client_id

分享提高这个答案
 

来自 https://stackoverflow.com/questions/26504105/lucadegasperi-oauth2-server-with-auth-code-grant-gives-...


普通分类: