st4lk / django-rest-social-auth

OAuth signin with django rest framework
MIT License
519 stars 122 forks source link

Why does STATE_PARAMETER is always False ? #135

Closed onekiloparsec closed 3 years ago

onekiloparsec commented 3 years ago

Hi. I am having troubles to make a GitHub OAuth2 workflow working. I always get the same error: social_core.exceptions.AuthFailed: Authentication failed: The code passed is incorrect or expired.

I am not sure it is related, but I noticed that STATE_PARAMETER (although being set as True for GitHub), is always set to False by this library. Why ? And what the comment is actually implying ? I couldn't find any documentation about it.

        # skip checking state by setting following params to False
        # it is responsibility of front-end to check state
        # TODO: maybe create an additional resource, where front-end will
        # store the state before making a call to oauth provider
        # so server can save it in session and consequently check it before
        # sending request to acquire access token.
        # In case of token authentication we need a way to store an anonymous
        # session to do it.
        self.request.backend.REDIRECT_STATE = False
        self.request.backend.STATE_PARAMETER = False

My workflow is the following:

Thanks!

onekiloparsec commented 3 years ago

My mistake, I forgot to update the client secret in my .env file after playing around.

Indeed, it is the frontend responsability of checking state consistency, I understand that.

What strucked me was that I wondered whether I should create an application in the oauth2_provider Django admin, for GitHub, and with what kind of parameters etc. The similar library of yours drf-social-auth2 requires to create such app before going further.