我到处搜索,但没有找到任何可以提供帮助的东西。
我是 oAuth 的新手。
我正在使用 https://github.com/lucadegasperi/oauth2-server-laravel 。
我正在构建 REST API 服务。 客户端
将是网站。我正在使用 Password Flow
进行身份验证。
个人理解,如有错误请指正
oauth_clients
表(id、 secret 、名称)。 客户
是网站,而不是登录网站的个人用户。我将使用 The Client
的 id 和 secret 以及个人用户的用户名和密码。
我正在按照上面页面上的说明进行操作。
我在 http://api.domain.com/oauth/access_token?grant_type=password&client_id=BCA545A934F5F4528DA3EE567E8E4&client_secret=5184B7C4E11ED3EEF99DA1A1DD9C3&username=email@email.com&scope=password=password=password 上使用
POST
方法scope1,scope2&state=123456789
这可以很好地验证客户端和用户,但这是问题所在。我不知道在哪里设置 scope
或 state
这是响应 {
“错误”:“无效范围”,
"error_description": "请求的范围无效、未知或格式错误。检查\"scope1\"范围。"
}
老实说,我不知道下一步是什么,即使我设置了 Scope 或 State 下一步是什么?
谢谢。
编辑
我在作用域表中添加了一条虚拟记录,并将该值添加到 to 作用域中,它起作用了。
我现在确实了解作用域,只是不知道为什么需要它。
我收到了带有访问 token 的响应。我现在真正理解了 oAuth 的概念。我已经实现了登录/访问 token 系统,但我可能会摆脱它并坚持使用 oAuth。 我试图使用 oAuth 向 REST API 服务验证网站,但它看起来不像那样做。
现在我的下一个问题是:有没有办法将访问 token 添加到 header 而不是作为 URL 参数?
最佳答案
发布 OAuth2 服务器 configuration (如果尚未完成)使用
php artisan config:publish lucadegasperi/oauth2-server-laravel
打开文件 app/config/packages/lucadegasperi/oauth2-server-laravel/oauth2.php
如果您不需要作用域,只需将一个名为 basic
的作用域添加到 oauth_scopes
表。
|--------------------------------------------------------------------------
| Default Scope
|--------------------------------------------------------------------------
|
| The default scope to use if not present in the query string
|
*/
'default_scope' => 'basic',
现在不需要在access_token请求中添加scope参数。
Q2:Is there a way to add the access token to the Header instead as a URL parameter?
是的。默认情况下,它会同时检查查询字符串和 http header 。
将以下选项更改为 true
以在作为查询字符串提供时阻止 access_token 验证
|--------------------------------------------------------------------------
| HTTP Header Only
|--------------------------------------------------------------------------
|
| This will tell the resource server where to check for the access_token.
| By default it checks both the query string and the http headers
|
*/
'http_headers_only' => false,
关于php - Laravel 和 oauth 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23883481/