pallets-eco / flask-jwt

JWT (JSON Web Tokens) for Flask applications
MIT License
564 stars 178 forks source link

LDAP authentication #110

Closed diegovini-zz closed 7 years ago

diegovini-zz commented 7 years ago

Hi guys, I need to authenticate my users in Active Directory before they can use my REST API.

After beeing authenticated, I need to pass them the jwt.

Is it possible to do it using Flask-jwt? It not, any ideias how I can implement that?

Thx!

vimalloc commented 7 years ago

Perhaps consider using Flask-JWT-Extended (full disclosure, I'm the author of that extension). Instead of having a predefined endpoint that is POSTed to in order to login, you create your own endpoints and use the create_access_token(identity) function once you have handled authentication to generate the jwt.

You can see an example of what this might look like for you here: http://flask-jwt-extended.readthedocs.io/en/latest/basic_usage.html

If you want to continue using this extension, you will probably need to override whatever method is doing the authentication. There may be a decorator in the extension that does this, or you can subclass the extension changing that one method to suit your needs.

EDIT: Looks like you actually wouldn't need to subclass anything. You can do this by creating your own authenticate method and passing it to the JWT constructor. And example of that is here: https://pythonhosted.org/Flask-JWT/

Hope this helps.

diegovini-zz commented 7 years ago

Thanks for the answer!

It worked! =)

vimalloc commented 7 years ago

Glad that helped. If this is solved for you, would you mind closing the issue? Thanks!