PHP OAuth2.0 Server 搭建,问题解决持续更新中...
2015-05-26 10:19
405 查看
[-]
Step-By-Step Walkthrough
使用 OAuth2-Server-php 在 Yii 框架上搭建 OAuth2 Server
oauth2 server php
http://oauth.net/2/
Ref: http://bshaffer.github.io/oauth2-server-php-docs/cookbook/
Q1:
C:\Users\Frank>curl -u testclient:testpass http://oauth2.dev/token.php -d 'grant_type=client_credentials'
{"error":"invalid_request","error_description":"The grant type was not specified in the request"}
将单引号去掉即可。
C:\Users\Frank>curl -u testclient:testpass http://oauth2.dev/token.php -d grant_type=client_credentials
{"access_token":"594732584f808259555411aba1f5fdcc45b99fb1","expires_in":3600,"token_type":"Bearer","scope":null}
参考:https://github.com/bshaffer/oauth2-server-php/issues/160
Q2:
修改数据库表oauth_clients 字段grant_type 的值为authorization_code即可。
Q3:
C:\Users\Frank>curl -u testclient:testpass http://oauth2.dev/token.php -d grant_type=authorization_code&code=10ad1afa9569c7796eea48dab6014b9ed2a01b50
{"error":"unsupported_grant_type","error_description":"Grant type \"authorization_code\" not supported"}'code' is not recognized as an internal or external comm
and,operable program or batch file.
原来是把server.php 里的$server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage)); 这句注释了,去掉注释依然返回错误:
C:\Users\Frank>curl -u testclient:testpass http://oauth2.dev/token.php -d granttype=authorization_code & code=10ad1afa9569c7796eea48dab6014b9ed2a01b50
{"error":"invalid_request","error_description":"Missing parameter: \"code\" isequired"}'code' is not recognized as an internal or external command,operable program or batch file.
修改参数-d为--data ,并把参数加双引号,
参考:http://www.ruanyifeng.com/blog/2011/09/curl.html
执行如下:
C:\Users\Frank>curl -u testclient:testpass http://oauth2.dev/token.php --data "grant_type=authorization_code&code=10ad1afa9569c7796eea48dab6014b9ed2a01b50"
{"error":"invalid_grant","error_description":"The authorization code has expired"}
code过期了,重新在浏览器获取一次后,执行如下:
C:\Users\Frank>curl -u testclient:testpass http://oauth2.dev/token.php --data "grant_type=authorization_code&code=45daf60218e025028ffa55564c2901d8195a4418"
{"access_token":"81e35b27e604f95676ff9cb3b2a42ac12bbc8d22","expires_in":3600,"token_type":"Bearer","scope":null,"refresh_token":"a7b20df01ce1980d0fd80ec87fc68c2313995de7"}
成功!
Ref:http://www.cnblogs.com/rereadyou/p/3448381.html
下一步:oauth2.0 client ,redis替换mysql
http://bshaffer.github.io/oauth2-server-php-docs/storage/redis/ https://github.com/nrk/predis/ http://www.cnblogs.com/weafer/archive/2011/09/21/2184059.html https://github.com/jasonlewis/oauth2-server-redis/
Step-By-Step Walkthrough
使用 OAuth2-Server-php 在 Yii 框架上搭建 OAuth2 Server
oauth2 server php
http://oauth.net/2/
Step-By-Step Walkthrough
Ref: http://bshaffer.github.io/oauth2-server-php-docs/cookbook/ Q1:
<code class="language-text" style="border: 0px; margin: 0px; padding: 0px;">curl -u testclient:testpass http://localhost/token.php -d 'grant_type=client_credentials'</code>在windows下执行这步的时候返回:
C:\Users\Frank>curl -u testclient:testpass http://oauth2.dev/token.php -d 'grant_type=client_credentials'
{"error":"invalid_request","error_description":"The grant type was not specified in the request"}
将单引号去掉即可。
C:\Users\Frank>curl -u testclient:testpass http://oauth2.dev/token.php -d grant_type=client_credentials
{"access_token":"594732584f808259555411aba1f5fdcc45b99fb1","expires_in":3600,"token_type":"Bearer","scope":null}
参考: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>返回错误如下:
C:\Users\Frank>curl -u testclient:testpass http://oauth2.dev/token.php -d grant_type=authorization_code&code=10ad1afa9569c7796eea48dab6014b9ed2a01b50
{"error":"unsupported_grant_type","error_description":"Grant type \"authorization_code\" not supported"}'code' is not recognized as an internal or external comm
and,operable program or batch file.
原来是把server.php 里的$server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage)); 这句注释了,去掉注释依然返回错误:
C:\Users\Frank>curl -u testclient:testpass http://oauth2.dev/token.php -d granttype=authorization_code & code=10ad1afa9569c7796eea48dab6014b9ed2a01b50
{"error":"invalid_request","error_description":"Missing parameter: \"code\" isequired"}'code' is not recognized as an internal or external command,operable program or batch file.
修改参数-d为--data ,并把参数加双引号,
参考:http://www.ruanyifeng.com/blog/2011/09/curl.html
执行如下:
C:\Users\Frank>curl -u testclient:testpass http://oauth2.dev/token.php --data "grant_type=authorization_code&code=10ad1afa9569c7796eea48dab6014b9ed2a01b50"
{"error":"invalid_grant","error_description":"The authorization code has expired"}
code过期了,重新在浏览器获取一次后,执行如下:
C:\Users\Frank>curl -u testclient:testpass http://oauth2.dev/token.php --data "grant_type=authorization_code&code=45daf60218e025028ffa55564c2901d8195a4418"
{"access_token":"81e35b27e604f95676ff9cb3b2a42ac12bbc8d22","expires_in":3600,"token_type":"Bearer","scope":null,"refresh_token":"a7b20df01ce1980d0fd80ec87fc68c2313995de7"}
成功!
使用
OAuth2-Server-php 在 Yii 框架上搭建 OAuth2 Server
Ref:http://www.cnblogs.com/rereadyou/p/3448381.html下一步:oauth2.0 client ,redis替换mysql
http://bshaffer.github.io/oauth2-server-php-docs/storage/redis/ https://github.com/nrk/predis/ http://www.cnblogs.com/weafer/archive/2011/09/21/2184059.html https://github.com/jasonlewis/oauth2-server-redis/
相关文章推荐
- window下eslipse搭建django遇到的问题以及解决方法积累(持续更新)
- Caffe搭建:常见问题解决办法和ubuntu使用中遇到问题解决方法(持续更新)
- Caffe搭建:常见问题解决办法和ubuntu使用中遇到问题解决方法(持续更新)
- Caffe搭建:常见问题解决办法和ubuntu使用中遇到问题(持续更新)
- Linux之一条命令解决常见问题(持续更新)
- 【问题解决】PHP 'Internal Server Error,500 error'
- apache 问题 You don't have permission to access /test.php on this server 解决方法
- php7注意事项及遇到的问题 持续更新....
- AS小问题解决方法汇总(持续更新)
- iOS开发Cocoapods安装过程中遇到问题解决[持续更新]
- JavaWeb项目 积累问题解决方案,持续更新中
- win10_x64更新错误解决: 安装一些更新时出现问题,但我们稍后会重试。如果持续出现这些问题,并且你想要搜索Web或联系支持人员以获取相关信息,以下信息可能会对你有帮助:
- “Windows + VirtualBox Ubuntu” 问题与解决笔记【持续更新】
- 64位win7手动搭建php开发环境Apache+MySQL+php及相关配置,问题解决方法
- 我的关于PHP开发中遇到的小问题集锦(持续更新...)
- 在Ubuntu环境中搭建OpenCV2411,并解决libgtk库更新问题
- java开发中遇到的问题及解决方法(持续更新)
- 【问题解决】远程服务器Ubuntu Server 14.04.1 LTS搭建LAMP环境
- 我遇到的CocoaPods的问题(也许后期会解决,持续更新)
- 我遇到的CocoaPods的问题(也许后期会解决,持续更新)