flask-security icon indicating copy to clipboard operation
flask-security copied to clipboard

Manually authentication

Open apahomov opened this issue 13 years ago • 6 comments

Hi. I use Flask-Security and want to implement api authentication, but I can't login throw bultin views. For example I try(example in #30):

curl -X POST -H "Content-Type: application/json"  -d '{"email":"[email protected]", "password":"1234Qwer"}' localhost:5000/login

but got:

{
  "meta": {
    "code": 400
  }, 
  "response": {
    "errors": {
      "csrf_token": [
        "CSRF token missing"
      ]
    }
  }
}

I undestand, that I need csrf_token, but for api use it's not needed. Is there way to manually authenticate user or other way to do this? Thanks for the great app:)

apahomov avatar Jan 06 '13 21:01 apahomov

Fixed and released in 1.5.4. Which is now on pypi

mattupstate avatar Jan 07 '13 01:01 mattupstate

@mattupstate I'm still getting this error. I'm running 1.6.3, looking through the commit history it seems that this might have been reintroduces in this commit:

https://github.com/mattupstate/flask-security/commit/34b3bf9e8060c73b78fdfeef273e00efa3feb207#flask_security/forms.py

I'm not quite sure how to handle this now, thoughts?

I've done this and that seems to fix it but not sure if that was removed for a reason:

class Form(BaseForm):
    def __init__(self, *args, **kwargs):
        if current_app.testing:
            self.TIME_LIMIT = None
        csrf_enabled = request.json is None
        kwargs.setdefault('csrf_enabled', csrf_enabled)
        super(Form, self).__init__(*args, **kwargs)

jurre avatar May 17 '13 14:05 jurre

@jurre It was removed for security reasons. Accepting a login request from anywhere without the CSRF token is a little sketchy.

What type of client is this? Browser based? Mobile app?

mattupstate avatar May 21 '13 14:05 mattupstate

It will be a mobile app but I'm just testing with cURL for now

jurre avatar May 21 '13 14:05 jurre

I would recommend checking out these guidelines: https://developers.google.com/accounts/docs/MobileApps

mattupstate avatar May 21 '13 14:05 mattupstate

Thanks :)

jurre avatar May 21 '13 15:05 jurre