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 Android Espresso如何检查字符串是否缩写   java jar从cmd写入文件,但不能双击   Grails中的java onetomany映射|我可以在复合键中使用生成的值吗?   java HttpsURLConnection在尝试添加Cookie时已连接   java在Netbeans中不能有同名的包和类   如何在格式化字段自动更改无效输入(Swing)Java时触发事件   用户输入后java JTextArea未更新   java试图用新字符替换字符串中的特定字符   java类加载器在Linux上显示错误路径   java mySQL远程数据库未连接   java如果接口需要MyObject对象,如何返回错误对象?   java无法解析在MainActivity之外调用安卓类时的符号   java如何将应用程序文件正确添加到appium所需的功能?   Java中浮点数组的数据对齐算法