oauth2 server php php
http://oauth.net/2/ html
Ref: http://bshaffer.github.io/oauth2-server-php-docs/cookbook/ mysql
curl -u testclient:testpass http://localhost/token.php -d 'grant_type=client_credentials'在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"} git
將單引號去掉便可。 github
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} redis
參考:https://github.com/bshaffer/oauth2-server-php/issues/160 sql
Q2: 數據庫
http://localhost/authorize.php?response_type=code&client_id=testclient&state=xyz在瀏覽器執行這個的時候,返回錯誤:
{"error":"invalid_client","error_description":"No client id supplied"}修改數據庫表oauth_clients 字段grant_type 的值爲authorization_code便可。
Q3: windows
curl -u testclient:testpass http://localhost/token.php -d grant_type=authorization_code&code=YOUR_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"}
成功!
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/