我跟随https://django-oauth-toolkit.readthedocs.org/en/0.7.0/rest-framework/getting_started.html使用rest框架设置Django OAuth工具包。
它说要获取token,我们需要像这样做卷曲:
curl -X POST -d "grant_type=password&username=<user_name>&password=<password>" http://<client_id>:<client_secret>@localhost:8000/o/token/我对这个过程的实际curl请求如下所示(对于已经生成的client_id和client_secret)
curl -X POST -d "grant_type=password&username=test&password=test" http://mbqvonqO7sI1lrh87uDd.C1U..NbKTb@0=eCM8Fl::2O=!0ZjE5UCha0UW?Oie-XCVUn;3XtmjT2SbFpzDJeM@Bn3.vPS!KLoDqVz7L-3.FfjP9v6yYyu2ghxObnIdIWppu=J@RPxPOfU@Q7KPt7da.?Bg0o5kCt5tY:wamsF@127.0.0.1:8000/o/token/它没有返回任何响应,并给出错误"bash:!0: event not found“
打错电话了吗?
发布于 2014-03-04 15:20:59
问题是在注册应用程序(http://django-oauth-toolkit.readthedocs.org/en/0.7.0/rest-framework/getting_started.html#step-3-register-an-application)期间生成的“客户端id”和“客户端机密”。
"client id“和"client secret”包含特殊字符,不能以文档中提到的方式与curl请求一起使用。
我们可以像Almalki建议的那样使用它:
curl -X POST -d "client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=password&username=YOUR_USERNAME&password=YOUR_PASSWORD" http://localhost:8000/o/token/发布于 2014-03-04 03:48:48
您可以将client_id和client_secret设置为POST参数:
curl -X POST -d "client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=password&username=YOUR_USERNAME&password=YOUR_PASSWORD" http://localhost:8000/o/token/发布于 2015-01-06 10:03:13
我遇到了与操作员相同的问题,这是唯一对我有效的解决方案:
curl -X POST -d 'grant_type=password&username=<username>&password=<password>' --user '<client_id>:<client_secret>' 'http://localhost:8000/o/token/'我在Django OAuth Toolkit's Github issue #167找到了这个解决方案。这是一个很好的解释。
https://stackoverflow.com/questions/22118305
复制相似问题