【问题标题】:Laravel 5.1 oAuth 2 server 'invalid scope' errorLaravel 5.1 oAuth 2 服务器“无效范围”错误
【发布时间】:2015-11-03 03:31:39
【问题描述】:

我的 API 使用 oauth2-server-laravel。我想为使用我的 API(Android、Windows、IOS 和 Web)的客户端应用程序提供范围。因此我实现了以下方式。

我的表数据如下

oauth_clients

+------------+---------+---------+-------------- --------+----------+
|编号|秘密|姓名 | created_at |更新了 |
+-----------+---------+---------+----- -+------------+
| 123456789 |秘密1 |网站 | 2015-08-10 00:00:00 | 2015-08-10 00:00:00 |
| 234567890 |秘密2 | win_app | 2015-08-10 00:00:00 | 2015-08-10 00:00:00 |
+-----------+---------+---------+----- --+------------+

oauth_scopes 表格

+--------+--------------------------------+---------------- -----+----------+
|编号 |描述 | created_at |更新了 |
+--------+--------------------------------+-------- --+------------------------+
|范围1 |访客级别访问 | 2015-08-10 00:00:00 | 2015-08-10 00:00:00 |
|范围2 |管理员级别访问 | 2015-08-10 00:00:00 | 2015-08-10 00:00:00 |
+--------+--------------------------------+-------- --+----------+

oauth_client_scopes

+----+-----------+----------+------ ---+----------+
|编号 |客户 ID | scope_id | created_at |更新了 |
+----+------------+----------+---------- +---------------------+
| 1 | 234567890 |范围2 | 2015-08-10 00:00:00 | 2015-08-10 00:00:00 |
| 2 | 123456789 |范围1 | 2015-08-10 00:00:00 | 2015-08-10 00:00:00 |
+----+------------+----------+---------- +------------------+

我的routes.php

Route::group(['middleware' => 'oauth:scope2','prefix' => 'api/v1'], function () {
           Route::GET('categoriesWithOffers', 'api\v1\CategoriesController@categoriesWithOffers');  
});

和我的 oauth2.php 设置如下

'grant_types' => [
    'client_credentials' => [
        'class' => '\League\OAuth2\Server\Grant\ClientCredentialsGrant',
        'access_token_ttl' => 3600
    ],
],
'token_type' => 'League\OAuth2\Server\TokenType\Bearer',
'state_param' => false,
'scope_param' => false,
'scope_delimiter' => ',',
'default_scope' => null,
'limit_clients_to_grants' => false,
'limit_clients_to_scopes' => false,
'limit_scopes_to_grants' => false,
'http_headers_only' => false,

我要求以下方式

http://domain.com/api/v1/categoriesWithOffers?access token=Jo7lAqE2uD3KbyLQWlrmukzyHJOQBHZ1QFsuBKUt&scope=scope1

它给了我这个错误

{ “错误”:“无效范围”, "error_description": "请求的范围无效、未知或格式错误。检查 \"scope2\" 范围。" }

当我将当前请求令牌和范围添加到 oauth_access_token_scopes 表工作正常。但我需要定义这个问题的 bigining 中提到的范围。

任何帮助将不胜感激!

【问题讨论】:

  • 我也试过 'limit_clients_to_scopes' => true 和 'default_scope' => 'scope2',

标签: php oauth-2.0 laravel-5 restful-authentication


【解决方案1】:

在请求获取访问令牌时使用范围

/token?grant_type=client_credentials&client_id=234567890&client_secret=123456789&scope=scope1

使用此网址,您将获得访问令牌,然后您可以在您的网址上使用它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-19
    相关资源
    最近更新 更多