Giter Site home page Giter Site logo

Comments (6)

lafrech avatar lafrech commented on May 17, 2024

Can you elaborate on your use case?

Since this is about REST APIs, I assume it is an authentication cookie, right?

Do you want to set it from the view function? From a custom authentication decorator?

from flask-smorest.

mekanix avatar mekanix commented on May 17, 2024

Yes, it's auth cookie. So, with flask_restplus this is the code I used: https://github.com/mekanix/backend-startkit/blob/master/application/api/auth.py#L21-L64. Something I tried to achieve with flask_rest_api is this: https://github.com/mekanix/backend-startkit/blob/feature/rest-api/application/api/auth.py#L24-L68. The problem is that frontend says length of response is wrong (I suppose I'm overwriting something).

from flask-smorest.

lafrech avatar lafrech commented on May 17, 2024

I don't see anything blocking you from setting a cookie from a decorator.

However, setting a cookie from a view function is currently impossible because by design of the response method, the view function can not return a flask Response object. This is discussed in #22.

IIUC, the return resp.get_json() in your code means you're returning only the json body of the response and not the cookies.

from flask-smorest.

mekanix avatar mekanix commented on May 17, 2024

Than decorator is the right place. :) Can you please post the code snippet to achieve it? The code I linked to is not the way I have to solve it, it just the closest I've got to setting the cookie, so feel free to just ignore it.

from flask-smorest.

lafrech avatar lafrech commented on May 17, 2024

I have no available snippet and no time for this right now.

You might find the conversation in #36 interesting, especially this comment.

from flask-smorest.

lafrech avatar lafrech commented on May 17, 2024

Closing this for now. Feel free to comment if you're still stuck on this.

from flask-smorest.

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.