{"comment":{"created_at":"2011-10-19T06:57:31Z","body":"好的，用api_clients更直观","updated_at":"2011-10-19T06:57:31Z","url":"https://api.github.com/repos/saberma/shopqi/issues/comments/2452649","id":2452649,"user":{"avatar_url":"https://secure.gravatar.com/avatar/871c4ba6d25169779cee977e04b2f0c3?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"871c4ba6d25169779cee977e04b2f0c3","url":"https://api.github.com/users/saberma","id":15178,"login":"saberma"}},"action":"created","issue":{"number":184,"created_at":"2011-09-30T13:55:16Z","pull_request":{"diff_url":null,"patch_url":null,"html_url":null},"body":"在后台管理（/admin/api）中可以增加api授权，用于私有程序的访问\r\n\r\n授权机制基于oauth2协议，服务端实现使用 https://github.com/songkick/oauth2-provider ，非gem，代码放在lib/oauth2中；之前实现主题授权时已经对现有的插件进行试用，这个使用是最方便的\r\n客户端实现可先用浏览器测试，直接输入 api 的url地址(https://api_key:password@foo.myshopqi.com/admin/orders.json)\r\n\r\n实现此功能时，要将api授权记录保持至applications表中，此表归属于shop记录；表字段有api_key,password,shared_secret，字段值都为32位随机字符；用户的私有程序可通过地址\r\nhttps://483d797f39ddc77675924c2b62184680:5ec483f14ed790add61b43873323e75e@foo.myshopqi.com/admin/orders.xml\r\n获取订单记录，其中 \r\n483d797f39ddc77675924c2b62184680 为 api_key，\r\n5ec483f14ed790add61b43873323e75e 为 password，shared_secret暂时用不到（在后面开发app时才需要使用，以生成url地址中的signature，及后台生成访问商店的password）\r\n\r\n结合 #185 的issue， api请求过来时，控制器将通过请求参数 api_key, password 判断请求是否合法，具体参考\r\nhttps://github.com/songkick/oauth2-provider\r\n中的 Using password credentials 一节\r\n也可参考 https://github.com/saberma/shopqi/blob/master/app/controllers/admin/shops_controller.rb#L25 ，其中的\r\nauthorization = OAuth2::Provider.access_token(nil, [], request) 就是要换为 Using password credentials 一节中所说的内容\r\n\r\n刚开始会有不少疑惑的地方，随时联系","comments":4,"title":"用户可以新增应用api授权","updated_at":"2011-10-19T06:57:31Z","url":"https://api.github.com/repos/saberma/shopqi/issues/184","id":1785836,"assignee":{"avatar_url":"https://secure.gravatar.com/avatar/9d438bc8e2498ccb87754c9e41674ccd?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"9d438bc8e2498ccb87754c9e41674ccd","url":"https://api.github.com/users/liwh","id":292829,"login":"liwh"},"milestone":{"number":7,"created_at":"2011-09-25T03:02:25Z","due_on":"2011-10-09T07:00:00Z","title":"0.0.6","creator":{"avatar_url":"https://secure.gravatar.com/avatar/871c4ba6d25169779cee977e04b2f0c3?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"871c4ba6d25169779cee977e04b2f0c3","url":"https://api.github.com/users/saberma","id":15178,"login":"saberma"},"url":"https://api.github.com/repos/saberma/shopqi/milestones/7","open_issues":5,"closed_issues":5,"description":"1. 官网后台管理支持上传主题模板 [saberma]\r\n2. 商品、订单等资源支持api访问 [liwh]\r\n3. 用户可以管理api授权 [liwh]","state":"open"},"closed_at":null,"user":{"avatar_url":"https://secure.gravatar.com/avatar/871c4ba6d25169779cee977e04b2f0c3?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"871c4ba6d25169779cee977e04b2f0c3","url":"https://api.github.com/users/saberma","id":15178,"login":"saberma"},"html_url":"https://github.com/saberma/shopqi/issues/184","labels":[{"name":"功能","url":"https://api.github.com/repos/saberma/shopqi/labels/%E5%8A%9F%E8%83%BD","color":"0b02e1"},{"name":"应用","url":"https://api.github.com/repos/saberma/shopqi/labels/%E5%BA%94%E7%94%A8","color":"02d7e1"}],"state":"open"},"legacy":{"issue_id":1785836,"comment_id":2452649}}