jazzband / django-oauth-toolkit

OAuth2 goodies for the Djangonauts!
https://django-oauth-toolkit.readthedocs.io
Other
3.13k stars 792 forks source link

{ "error": "invalid_grant", "error_description": "Invalid credentials given." } #1393

Closed PunkFleet closed 7 months ago

PunkFleet commented 8 months ago

I following this:https://github.com/jazzband/django-oauth-toolkit/blob/master/docs/getting_started.rst I have a very confusing problem. I am able to log in through a python manage.py createsuper created superuser, but not through a user created from the dashboard, even though the superuser option is checked. and i will got

Bad Request: /o/token/
[31/Jan/2024 03:33:31] "POST /o/token/ HTTP/1.1" 400 77

Am I overlooking something?

image image image image
ianmubangizi commented 7 months ago

@Birddle is the Model username field value the email?

The default validator uses the Model field username if am correct as seen here.

class OAuth2Validator(RequestValidator):
    ...
    def validate_user(self, username, password, client, request, *args, **kwargs):
        """
        Check username and password correspond to a valid and active User
        """
        # Passing the optional HttpRequest adds compatibility for backends
        # which depend on its presence. Create one with attributes likely
        # to be used.
        http_request = HttpRequest()
        http_request.path = request.uri
        http_request.method = request.http_method
        getattr(http_request, request.http_method).update(dict(request.decoded_body))
        http_request.META = request.headers
        u = authenticate(http_request, username=username, password=password)
        if u is not None and u.is_active:
            request.user = u
            return True
        return False