一个实现olin认证的简单flask扩展

Flask-OlinAuth的Python项目详细描述


flask olinauth实现olinapps auth。它自动提供 /olinauthlogin/olinauthlogout路由到应用程序, 处理使用olinapps对用户进行实际身份验证的过程。

在高水平上,Flask Olinauth为您的 这两个应用程序都在example.py中演示。

@auth_required

确保用户登录的简单函数装饰器 在显示视图之前。用户被重定向到登录门户,使用 正确的论点,如果不是。

current_user

一个很好的本地代理,用于获取当前用户的所有视图, 格式化为字典。

logout_user

将注销当前经过身份验证的用户,允许您 创建自己的注销视图。

Flask Olinauth深受Flask登录的启发, 以及采用的功能,以及获得的大量知识。

安装

使用以下命令之一安装扩展:

$ easy_install flask-olinauth

或者,如果您安装了pip(您应该安装):

$ pip install flask-olinauth

示例用法

from flask import Flask, url_for
from flask.ext.olinauth import OlinAuth, auth_required, current_user
app = Flask(__name__)

SECRET_KEY = "yeah, not actually a secret"
DEBUG = True

app.config.from_object(__name__)

oa = OlinAuth(app, 'localhost:5000')
#initial OlinAuth, with callback host of localhost:5000, for local server
oa.init_app(app, 'localhost:5000')


@app.route("/")
def index():
    if current_user:
        responseString = "Awesome index, guess what? %s is logged in. Sweet, right?" % current_user['id']
    else:
        responseString = "<html>It is kind of lonely here... No users are logged in. <a href=%s>Checkout my secret</a> </html>" % url_for('secret')
    return responseString


@app.route("/secret")
@auth_required
def secret():
    return "I wouldn't normally show you this, but since %s is logged in, here is the secret: 42" % current_user['id']


if __name__ == "__main__":
    app.run(debug=True)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java爬虫获取外部网站搜索结果   java Bluestack未连接到eclipse   java如何从ConstraintViolationException Hibernamte获取数据库字段名   HttpResponse HttpResponse=httpClient引发java运行时错误。执行(httpPost);   Jama中矩阵的java点积和叉积   java有什么方法可以唯一地识别可扩展设备吗?   java我需要用*来写我的名字,但我不断遇到一个错误,我对编码很陌生   java变量是在内部类中访问的。需要被宣布为最终决定。但我不想宣布最终结果   java如何缩短base64图像字符串,Android?   JavaSpringMVC:计划方法不自动触发   图形学习Java 2D API的好资源是什么?   如何在java中对方法进行排队   java JavaFX多行   java Selenium无法在[链接]上找到基于CSS元素的密码字段元素http://www.cartasi.it/gtwpages/index.jsp   Java中的equals()和hashCode()契约   软删除情况下的java Hibernate二级缓存   java为什么这段代码要两次调用这些方法?