PedroBern / django-graphql-auth

Django registration and authentication with GraphQL.

Home Page:https://django-graphql-auth.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mutation register errors "Please, enter valid credentials"

louistwiice opened this issue · comments

Prerequisites

  • Is it a bug?
  • Is it a new feature?
  • Is it a a question?
  • Can you reproduce the problem?
  • Are you running the latest version?
  • Did you check for similar issues?
  • Did you perform a cursory search?

For more information, see the CONTRIBUTING guide.

Description

Hi,

I am using django-graphql-auth. I have followed quickstart guide on https://django-graphql-auth.readthedocs.io/en/latest/quickstart/. I have only imlemented the registration of a user. But it seems like I can't create one. I receive a message "Please, enter valid credentials"

Steps to Reproduce

If we need to reproduce and you don't provide steps for it, it will be closed. Alternatively, you can link a repo with the code to run your issue.

settings.py file

`
INSTALLED_APPS = [

'graphene_django',
'graphql_auth',
'graphql_jwt.refresh_token.apps.RefreshTokenConfig',
'django_filters',

'core',
'user_management',

]
AUTH_USER_MODEL = "core.Users"
GRAPHENE = {
"SCHEMA": "config.schema.schema",
'MIDDLEWARE': [
'graphql_jwt.middleware.JSONWebTokenMiddleware',
],
}
AUTHENTICATION_BACKENDS = [
"graphql_jwt.backends.JSONWebTokenBackend",
"graphql_auth.backends.GraphQLAuthBackend",
]
GRAPHQL_JWT = {
"JWT_VERIFY_EXPIRATION": True,
'JWT_LONG_RUNNING_REFRESH_TOKEN': True,
"JWT_ALLOW_ANY_CLASSES": [
"graphql_auth.mutations.Register",
],
}
`

my usermanagement apps

mutations file
`
import graphene
from graphql_auth import mutations

class AuthMutation(graphene.ObjectType):
register = mutations.Register.Field()

class Mutation(AuthMutation, graphene.ObjectType):
pass
`

queries file
`
from graphql_auth.schema import UserQuery, MeQuery
from .schema import *
import graphene

class Query(UserQuery, MeQuery, graphene.ObjectType):
pass
`

schema file
#Nothing in

In my config project

my schema file
`from core.models import *
from graphene_django import DjangoObjectType
import graphene
from usermanagement.queries import Query as auth_query
from usermanagement.mutations import Mutation as auth_mutation

class Query(auth_query, graphene.ObjectType):
pass

class Mutation(auth_mutation,graphene.ObjectType):
pass

schema = graphene.Schema(query= Query, mutation=Mutation)`

Expected behavior

The query
mutation { register( email: "new_user@email.com", username: "new_user", password1: "supersecretpassword", password2: "supersecretpassword", ) { success, errors, token, refreshToken } }
The Response
{ "data": { "register": { "success": true, "errors": null, "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6Im5ld191c2VyMjIiLCJleHAiOjE1ODAxMzUyMTQsIm9yaWdJYXQiOjE1ODAxMzQ5MTR9.lzMjYo_1LO-TMDotySi1VHoC5yLyKr5PWC2l-hdzQ20", "refreshToken": "8db1c55b8dbc1f4a24eabe6f5d44dc091a8ca0f7" } } }

Actual behavior

The query

mutation {
register(
email: "new_user@email.com",
username: "new_user",
password1: "supersecretpassword",
password2: "supersecretpassword",
) {
success,
errors,
token,
refreshToken
}
}

The Response

{
"errors": [
{
"message": "Please, enter valid credentials",
"locations": [
{
"line": 3,
"column": 3
}
],
"path": [
"register"
]
}
],
"data": {
"register": null
}
}

Requirements

aniso8601==7.0.0
asgiref==3.4.1
certifi==2021.5.30
cffi==1.14.6
charset-normalizer==2.0.6
coreapi==2.3.3
coreschema==0.0.4
cryptography==3.4.8
defusedxml==0.7.1
Django==3.2.7
django-filter==21.1
django-graphql-auth==0.3.16
django-graphql-jwt==0.3.0
django-templated-mail==1.1.1
djangorestframework==3.12.4
djangorestframework-simplejwt==4.8.0
djoser==2.1.0
graphene==2.1.9
graphene-django==2.15.0
graphql-core==2.3.2
graphql-relay==2.0.1
idna==3.2
importlib-metadata==1.7.0
itypes==1.2.0
Jinja2==3.0.1
MarkupSafe==2.0.1
oauthlib==3.1.1
promise==2.3
psycopg2-binary==2.9.1
pycparser==2.20
PyJWT==1.7.1
python3-openid==3.2.0
pytz==2021.1
requests==2.26.0
requests-oauthlib==1.3.0
Rx==1.6.1
singledispatch==3.7.0
six==1.16.0
social-auth-app-django==4.0.0
social-auth-core==4.1.0
sqlparse==0.4.2
text-unidecode==1.3
typing-extensions==3.10.0.2
uritemplate==3.0.1
urllib3==1.26.7
zipp==3.5.0

I have the exact same problem.

Same. Not sure what's going wrong here.

I have the exact issue.
After digging through the code, it seems that the flow is:

  • in a transaction:
    • the user is created
    • it tries to authenticate the current user and bypasses the graphql_auth.backends.GraphQLAuthBackend auth backend by using the _jwt_token_auth on the request
    • fails because there are no authentication backends to try
    • the whole transaction fails and no user is created

I fixed it by setting in my settings.py file

AUTHENTICATION_BACKENDS = [
    'graphql_auth.backends.GraphQLAuthBackend',
    'django.contrib.auth.backends.ModelBackend',  # important to have this as well.
]

Circling back, can confirm that the above missing config was the issue for me too.

Circling back, can confirm that the above missing config was the issue for me too.

I can also confirm that this solved my issue which was the same.

commented

Thanks vladcalin - adding 'django.contrib.auth.backends.ModelBackend' worked.

Hi Working with django graphql auth following the tutorial encountered the same problem, but im working with Django4.0, from the start django-graphql-auth throws a coupple of errors, first:

  • cannot import ugettext
  • cannot import ugettext_lazy
    these ones i've fixed using some answers from stackoverflows cuz django renamed the functions to:
    from django.utils.translation import gettext, gettext_lazy django.utils.translation.ugettext = gettext django.utils.translation.ugettext_lazy = gettext_lazy
  • the last error is about Signals requiring arguments, which no longer is supported in django4.
    patched graphql.signals using:
    user_registered = Signal() user_verified = Signal()

but now when i try to use the class from graphql_auth import mutations.Register to extend another one to pass an argument to register by default using an identification number, it throws:

graphql_jwt\decorators.py", line 90, in wrapper raise exceptions.JSONWebTokenError( graphql.error.located_error.GraphQLLocatedError: Please, enter valid credentials

Hi Working with django graphql auth following the tutorial encountered the same problem, but im working with Django4.0, from the start django-graphql-auth throws a coupple of errors, first:

  • cannot import ugettext
  • cannot import ugettext_lazy
    these ones i've fixed using some answers from stackoverflows cuz django renamed the functions to:
    from django.utils.translation import gettext, gettext_lazy django.utils.translation.ugettext = gettext django.utils.translation.ugettext_lazy = gettext_lazy
  • the last error is about Signals requiring arguments, which no longer is supported in django4.
    patched graphql.signals using:
    user_registered = Signal() user_verified = Signal()

but now when i try to use the class from graphql_auth import mutations.Register to extend another one to pass an argument to register by default using an identification number, it throws:

graphql_jwt\decorators.py", line 90, in wrapper raise exceptions.JSONWebTokenError( graphql.error.located_error.GraphQLLocatedError: Please, enter valid credentials

manage to fix the issue
adding to settings.py:
`GRAPHQL_AUTH ={
#....
"ALLOW_LOGIN_NOT_VERIFIED":False,

"REGISTER_MUTATION_FIELDS":{
    "email":"String",
    "username":"String",
    "first_name":"String",
    "last_name":"String",
    "custom_field_to_authenticate":"String"
    },

#...
`