Code Monkey home page Code Monkey logo

Comments (4)

pennersr avatar pennersr commented on June 21, 2024 1

This part from the docs is important:

As calling this endpoint results in a user facing redirect (302), this call is only available in a browser, and must be called in a synchronous (non-XHR) manner.

You are using fetch -- just use a regular form POST (as in done in the demo code link above).

from django-allauth.

Andrioden avatar Andrioden commented on June 21, 2024

Bonus question: Why do i need to send X-CSRFToken?

"X-CSRFToken": Cookies.get("csrftoken"),

Without django logs Forbidden (CSRF token missing.): /_allauth/browser/v1/auth/provider/redirect. I would image allauth could take care of all that?

from django-allauth.

joonhyungshin avatar joonhyungshin commented on June 21, 2024

You do not need to send X-CSRFToken to pass the CSRF protection. Instead, you could attach the token to the request body.

login: async function() {
    await fetch("_allauth/browser/v1/auth/provider/redirect", {
        method: "POST",
        headers: {
            "Content-Type": "application/x-www-form-urlencoded"
        },
        body: new URLSearchParams({
            provider: this.type,
            callback_url: "/account/logged-in/",
            process: "login",
            csrfmiddlewaretoken: Cookies.get("csrftoken")
        })
    })
}

Since Discord disallows that header, try this option. I think it should work.

See for example, the demo code.

from django-allauth.

Andrioden avatar Andrioden commented on June 21, 2024

This part from the docs is important:

As calling this endpoint results in a user facing redirect (302), this call is only available in a browser, and must be called in a synchronous (non-XHR) manner.

You are using fetch -- just use a regular form POST (as in done in the demo code link above).

Thank you, the postForm worked. Yeah sorry, I read that documentation, but i didnt understand what non-XHR manner meant and didnt think to check it up.

from django-allauth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.