starlette的json web令牌中间件

starlette-jwt的Python项目详细描述


#starlette jwt
pythonic starlette api框架的jwt中间件

\starlette jwt

[![PYPI](https://img.shields.io/pypi/v/starlette_jwt.svg)(https://pypi.org/project/starlette-jwt)[![特拉维斯](https://img.shields.io/travis/amitripshtos/starlette jwt.svg)(https://travis-ci.org/amitripshtos/starlette-jwt)[![codecov](https://codecov.io/gh/amitripshtos/starlette jwt/branch/master/graph/badge.svg)(https://codecov.io/gh/amitripshtos/starlette jwt)




通过[pipenv]安装(https://pipenv.readthedocs.io/en/latest/)。

``````
$pipenv install starlette jwt
`````

starlette.middleware.authentication导入authenticationmiddleware
强制处理程序与身份验证一起使用。

同时,允许匿名用户访问路由。

默认行为是`@anonymous允许',因此代码是显式的。

``python
来自starlette。身份验证导入需要

def my_handler(请求):
@app.route('/noauth')
@requires('authenticated')
异步定义主页(请求):
返回jsonresponse({'payload':request.session})
````


并非所有处理程序都必须具有身份验证
``python
@app.route('/noauth')
异步定义主页(请求):
返回jsonresponse({'payload':none})
````

中间件:
``python
app.add``u中间件(authenticationmiddleware,backend=jwtauthenticationbackend(secret`u key='my secret key'))
`````

*前缀*

backend=jwtauthenticationbackend(secret庘key='secret',prefix='bearer')
```

*用户名字段*

jwt令牌负载中的用户名字段:
```python
;示例:将用户名字段更改为“user”
app.add庘中间件(authenticationmiddleware,backend=jwtauthenticationbackend(secret庘key='secret',用户名“field=”用户“)
```

要安装开发依赖项:

```
pipenv install--dev
````

要运行测试:

`````
pipenv shell
pytest
````

此项目使用[codecov](https://codecov.io/gh/amitripshtos/starlette-jwt)对所有请求执行代码覆盖。要在本地运行测试并输出代码覆盖率报告,运行:

````
pipenv-shell
py test--cov=starlette-test/
`````

`在pypi(mainetiners)上部署新版本的pypi(mainetineiners)
``` bash

python3.7 setup.py sdist
pysn3.7 setup.py sdist
wine upload——存储库网址:https://pypi.org/legacy/dist/*
>
```````>
```
` ````````>
`Starlette项目-https://github.com/encode/starlette
*APISTAR JWT项目-https://github.com/audiolion/APISTAR-JWT

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

推荐PyPI第三方库


热门话题
Java性能为什么响应时间会随着时间的推移而增加?   java如何在Eclipse中忽略特定异常   java如何在安卓中通过显示安卓获得屏幕截图   java如何访问struts if标记的test属性中的属性   java新线程不使用JFrame   java我应该检查一个文本字段是否有文本,然后清理它还是直接清理它?   数组在java中每隔三个整数打印一行   java如何在querydsl中加入外键   从src/main/resources读取java会产生NullPointerException   java h2db按字段排序   java如何使用Tomcat7在Spring中提供的JNDI数据源?   java更新整数不起作用为什么?   java Orika通用集合自定义映射   在java中使用csvreader类读取csv文件时出现opencsv反斜杠问题   java SonarQube中同一项目的多个视图   如何在Java中使用“start with”变量查找文件   java如何在活动之间传递整数?   清除Android应用程序缓存的java反射方法   java无法从领事处注销服务(Spring boot app)