【问题标题】:Django OAuth Toolkit setup issueDjango OAuth 工具包设置问题
【发布时间】:2014-04-02 19:42:43
【问题描述】:

我正在关注 https://django-oauth-toolkit.readthedocs.org/en/0.7.0/rest-framework/getting_started.html 来设置带有 rest 框架的 Django OAuth Toolkit。

与第 4 步一样:https://django-oauth-toolkit.readthedocs.org/en/0.7.0/rest-framework/getting_started.html#step-4-get-your-token-and-use-your-api

它说要获得令牌,我们需要像这样卷曲:

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”

打电话有什么问题吗?

【问题讨论】:

  • 尝试用双引号或单引号将您的 url 括起来,因为它包含许多不符合不带引号的 shell args 的字母。
  • 我注意到您的 client_id 和 client_secret 中还有一个 at 符号和列。我认为 curl 解析器无法区分 client 和 client_secret 那里。

标签: django oauth oauth-2.0 django-rest-framework


【解决方案1】:

我遇到了与 OP 相同的问题,这是唯一对我有用的解决方案:

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 找到了这个解决方案。那里有一个很好的解释。

【讨论】:

    【解决方案2】:

    问题在于注册申请过程中生成的“client id”和“client secret”(http://django-oauth-toolkit.readthedocs.org/en/0.7.0/rest-framework/getting_started.html#step-3-register-an-application)

    “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/
    

    【讨论】:

      【解决方案3】:

      您可以将 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/
      

      【讨论】:

        猜你喜欢
        • 2016-09-29
        • 1970-01-01
        • 2020-06-26
        • 2015-01-19
        • 2017-04-01
        • 2019-04-16
        • 2018-08-08
        • 1970-01-01
        • 2018-04-28
        相关资源
        最近更新 更多