【问题标题】:Invalid credentials raises exception on auth mutation无效的凭据引发身份验证突变异常
【发布时间】:2019-11-24 15:26:27
【问题描述】:

我在我的 django 项目中使用了 graphene-django 和 django-graphql-jwt。当我设置无效凭据时,服务器会引发“无效凭据”异常。

无效凭据是否应该在服务器上引发异常?当我用错误的数据测试 tokenAuth 突变时,Django 服务器会引发异常。

Django 服务器日志:

  File "/Users/cgf/.local/share/virtualenvs/testdjangoauthbackend-183R1gMP/lib/python3.7/site-packages/promise/promise.py", line 487, in _resolve_from_executor
    executor(resolve, reject)
  File "/Users/cgf/.local/share/virtualenvs/testdjangoauthbackend-183R1gMP/lib/python3.7/site-packages/promise/promise.py", line 754, in executor
    return resolve(f(*args, **kwargs))
  File "/Users/cgf/.local/share/virtualenvs/testdjangoauthbackend-183R1gMP/lib/python3.7/site-packages/graphql/execution/middleware.py", line 75, in make_it_promise
    return next(*args, **kwargs)
  File "/Users/cgf/.local/share/virtualenvs/testdjangoauthbackend-183R1gMP/lib/python3.7/site-packages/graphql_jwt/decorators.py", line 106, in wrapper
    result = f(cls, root, info, **kwargs)
  File "/Users/cgf/.local/share/virtualenvs/testdjangoauthbackend-183R1gMP/lib/python3.7/site-packages/graphql_jwt/decorators.py", line 89, in wrapper
    _('Please, enter valid credentials'))
graphql.error.located_error.GraphQLLocatedError: Please, enter valid credentials

【问题讨论】:

    标签: python django graphql graphene-django


    【解决方案1】:

    我也经历过同样的事情。实际上,他们是故意显示堆栈跟踪的。我想,这个问题很快就会得到解决。详情请查看this thread

    【讨论】:

      【解决方案2】:

      django-graphql-auth 扩展了 django-graphql-jwt 以添加更多功能,例如注册、电子邮件验证...

      其中一个优点是它返回一个标准输出,包含successerrors

      例如,它不会像在django-graphql-jwt 中针对无效凭据引发错误,而是返回:

      {
        "data": {
          "tokenAuth": {
            "success": false,
            "errors": {
              "nonFieldErrors": [
                {
                  "message": "Please, enter valid credentials.",
                  "code": "invalid_credentials"
                }
              ]
            },
            "token": null,
            "refreshToken": null,
            "unarchiving": false,
            "user": null
          }
        }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-12-20
        • 2014-10-15
        • 1970-01-01
        • 2020-04-10
        • 1970-01-01
        • 1970-01-01
        • 2022-06-11
        • 1970-01-01
        相关资源
        最近更新 更多