简体   繁体   English

Flask 认证使用 LDAP

[英]Flask authentication using LDAP

I've searched an answer for this but have found nothing - maybe because it's so obvious.我已经为此搜索了答案,但一无所获——也许是因为它太明显了。 But I want to make sure.但我想确定。

What is the correct way to authenticate users using an LDAP server in a Flask web app?在 Flask web 应用程序中使用 LDAP 服务器对用户进行身份验证的正确方法是什么?

This link describes 4 authentication methods, so along the same lines, do I just need to write an LDAP auth decorator?此链接描述了 4 种身份验证方法,所以按照相同的思路,我是否只需要编写一个 LDAP 身份验证装饰器?

(The reason I'm asking is to see whether I can make a Flask clone of my Django app) (我问的原因是看看我是否可以制作 Flask 克隆我的 Django 应用程序)

Thanks for any help and suggestions.感谢您的任何帮助和建议。

Yes, you have to write your own decorator which checks the authentication.是的,您必须编写自己的装饰器来检查身份验证。

In this decorator you should call the wrapped function if a user is authenticated.在这个装饰器中,如果用户经过身份验证,您应该调用包装的 function。 If not you should return a default page reminding the user to login.如果不是,您应该返回一个默认页面,提醒用户登录。

It should be quite straightforward to write an ldap backend if you combined this snippet from django with this simple basic http auth example from flask. It should be quite straightforward to write an ldap backend if you combined this snippet from django with this simple basic http auth example from flask. Though you may be better off using the login extension if you want to do proper session management.尽管如果您想进行正确的 session 管理,最好使用登录扩展

I don't think you need a decorator, but it's a sensible thing to do, as it makes it easy to "tag" those routes that you want to require authentication.我认为您不需要装饰器,但这是明智之举,因为它可以轻松“标记”您想要要求身份验证的那些路由。

Otherwise you'll be adding a lot more code whenever you want to implement some sort of authentication for a route.否则,每当您想为路由实现某种身份验证时,您都将添加更多代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM