两个地址
- 一步一步跟我学实现OAuth2.0 Server PHP (英:Step-By-Step Walkthrough)
- http://bshaffer.github.io/oauth2-server-php-docs/cookbook/
- CSDN debug 教学
- https://blog.csdn.net/u013339223/article/details/46004541
目录结构
my-oauth2-walkthrough
- oauth2-server-php
- .htaccess
- .user.ini
- 404.html
- authorize.php
- index.html
- resource.php
- server.php
- token.php
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传
运行
- Q1. 在windows下执行这步的时候返回:
执行 [C:\~]$ curl -u testclient:testpass http://www.my_oauth2.site/token.php -d 'grant_type=client_credentials'
返回 {"error":"invalid_request","error_description":"The grant type was not specified in the request"}
将单引号去掉即可。
参考:https://github.com/bshaffer/oauth2-server-php/issues/160
- Q2: 这个问题没有遇到
<code class="language-text" style="border: 0px; margin: 0px; padding: 0px;">http://localhost/authorize.php?response_type=code&client_id=testclient&state=xyz</code>
在浏览器执行这个的时候,返回错误:
{"error":"invalid_client","error_description":"No client id supplied"}
修改数据库表oauth_clients 字段grant_type 的值为authorization_code即可。
- Q3:
<code class="language-text" style="border: 0px; margin: 0px; padding: 0px;">curl -u testclient:testpass http://localhost/token.php -d grant_type=authorization_code&code=YOUR_CODE</code>
返回错误如下:
{"error":"invalid_request","error_description":"The grant type was not specified in the request"}'code' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
{"error":"invalid_request","error_description":"The grant type was not specified in the request"}'code' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
修改参数-d为–data ,并把参数加双引号,
参考:http://www.ruanyifeng.com/blog/2011/09/curl.html
执行如下:
curl -u testclient:testpass http://www.my_oauth2.site/token.php --data "grant_type=authorization_code&code=71686fdcca734275f0e954c2d3806b4d0bd0a613"
成功!
{"access_token":"4ea5032cbe11b26f216b4299c823245aec3ed79f","expires_in":3600,"token_type":"Bearer","scope":null,"refresh_token":"13835f586d575b091224b5e29b87f1804918a813"}
最后 附上源码
https://download.csdn.net/download/u013508912/23424281