Flask-restful: User Authentication with Flask-Restful

Created on 18 Aug 2015  路  4Comments  路  Source: flask-restful/flask-restful

Can anyone provide examples/tutorials/code snippets on how they did user authentication with Flask-restful? Esp if they used any other Flask extension like flaks-login or flask-wtf. I would really appreciate some help in this. hope to hear from you soon.

question

Most helpful comment

this sample repo has auth code using the Flask-HTTPAuth package. I like the Flask-HTTPAuth package since its super simple. Flask-Login seemed to be tied to using sessions (OK if you render webpages with flask), but thats not great for a REST api which is supposed to be stateless.

Flask-RESTful isnt really something you would use with Flask-WTF since a REST api typically won't be serving up HTML forms.

All 4 comments

this sample repo has auth code using the Flask-HTTPAuth package. I like the Flask-HTTPAuth package since its super simple. Flask-Login seemed to be tied to using sessions (OK if you render webpages with flask), but thats not great for a REST api which is supposed to be stateless.

Flask-RESTful isnt really something you would use with Flask-WTF since a REST api typically won't be serving up HTML forms.

Thank you Josh. One quick question, if i have a restful api and want my front-end to communicate with it, then how we work with HTML forms? Will all the rendering be then done on the front-end? As in how would it be different compared to using Flask-WTF with Flask?

@ueg1990 You'd use something like JQuery (or raw JavaScript if you're into that) to submit GET/POST/etc requests to the end points.

You can have link this JavaScript up to a form by declaring the "onSubmit" attribute and supplying the function.

Of course, there's other ways of communicating with the end point: curl/httpie, requests, or anything else that can generate valid HTTP requests.

All my web frontend projects are done in Angular with Flask-RESTful as the backend. If you aren't using a single page app framework (such as angular), JQuery should work fine.

Also, httpie is magic awesome sauce.

Was this page helpful?
0 / 5 - 0 ratings