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
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