Skip to content

Commit 14fd40c

Browse files
committed
v0.0.21
1 parent 57a475b commit 14fd40c

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<p align="center">
2828
<a href="https://github.com/amisadmin/fastapi_user_auth" target="_blank">源码</a>
2929
·
30-
<a href="http://demo.amis.work/admin" target="_blank">在线演示</a>
30+
<a href="http://user-auth.demo.amis.work/" target="_blank">在线演示</a>
3131
·
3232
<a href="http://docs.amis.work" target="_blank">文档</a>
3333
·
@@ -36,9 +36,8 @@
3636

3737
------
3838

39-
`FastAPI-User-Auth`是一个基于 [FastAPI-Amis-Admin](https://github.com/amisadmin/fastapi_amis_admin) 的应用插件,与`FastAPI-Amis-Admin`深度结合,为其提供用户认证与授权.
40-
41-
39+
`FastAPI-User-Auth`是一个基于 [FastAPI-Amis-Admin](https://github.com/amisadmin/fastapi_amis_admin)
40+
的应用插件,与`FastAPI-Amis-Admin`深度结合,为其提供用户认证与授权.
4241

4342
## 安装
4443

@@ -63,6 +62,7 @@ auth = site.auth
6362
# 挂载后台管理系统
6463
site.mount_app(app)
6564

65+
6666
# 创建初始化数据库表
6767
@app.on_event("startup")
6868
async def startup():
@@ -71,14 +71,17 @@ async def startup():
7171
await auth.create_role_user('admin')
7272
await auth.create_role_user('vip')
7373

74+
7475
# 要求: 用户必须登录
7576
@app.get("/auth/get_user")
7677
@auth.requires()
7778
def get_user(request: Request):
7879
return request.user
7980

81+
8082
if __name__ == '__main__':
8183
import uvicorn
84+
8285
uvicorn.run(app, debug=True)
8386

8487
```
@@ -194,13 +197,15 @@ auth.backend.attach_middleware(app)
194197
```python
195198
from fastapi_user_auth.auth.models import User
196199

197-
async def get_request_user(request: Request)->Optional[User]:
200+
201+
async def get_request_user(request: Request) -> Optional[User]:
198202
if await auth.requires('admin', response=False)(request):
199203
return request.user
200204
else:
201205
return None
202206

203207
```
208+
204209
## Token存储后端
205210

206211
`fastapi-user-auth` 支持多种token存储方式.默认为: `DbTokenStore`, 建议自定义修改为: `JwtTokenStore`
@@ -211,6 +216,7 @@ async def get_request_user(request: Request)->Optional[User]:
211216
from fastapi_user_auth.auth.backends.jwt import JwtTokenStore
212217
from sqlalchemy.ext.asyncio import create_async_engine
213218
from fastapi_amis_admin.utils.db import SqlalchemyAsyncClient
219+
214220
# 创建异步数据库引擎
215221
engine = create_async_engine(url='sqlite+aiosqlite:///admisadmin.db', future=True)
216222
# 使用`JwtTokenStore`创建auth对象
@@ -228,6 +234,7 @@ site = AuthAdminSite(settings=Settings(database_url_async='sqlite+aiosqlite:///a
228234
```python
229235
# 使用`DbTokenStore`创建auth对象
230236
from fastapi_user_auth.auth.backends.db import DbTokenStore
237+
231238
auth = Auth(db=SqlalchemyAsyncClient(engine),
232239
token_store=DbTokenStore(db=SqlalchemyAsyncClient(engine)))
233240
```
@@ -238,6 +245,7 @@ auth = Auth(db=SqlalchemyAsyncClient(engine),
238245
# 使用`RedisTokenStore`创建auth对象
239246
from fastapi_user_auth.auth.backends.redis import RedisTokenStore
240247
from aioredis import Redis
248+
241249
auth = Auth(db=SqlalchemyAsyncClient(engine),
242250
token_store=RedisTokenStore(redis=Redis.from_url('redis://localhost?db=0')))
243251
```
@@ -256,30 +264,26 @@ flowchart LR
256264
Role -. m:n .-> Perimission
257265
```
258266

259-
260-
261-
262267
## 界面预览
263268

264269
- Open `http://127.0.0.1:8000/admin/auth/form/login` in your browser:
265270

266-
![Login](https://raw.githubusercontent.com/amisadmin/fastapi_amis_admin_demo/master/upload/img/fastapi-user-auth-login.png)
271+
![Login](https://s2.loli.net/2022/03/20/SZy6sjaVlBT8gin.png)
267272

268273
- Open `http://127.0.0.1:8000/admin/` in your browser:
269274

270-
![Admin](https://raw.githubusercontent.com/amisadmin/fastapi_amis_admin_demo/master/upload/img/fastapi-user-auth-admin.png)
275+
![ModelAdmin](https://s2.loli.net/2022/03/20/ItgFYGUONm1jCz5.png)
271276

272277
- Open `http://127.0.0.1:8000/admin/docs` in your browser:
273278

274-
![Docs](https://raw.githubusercontent.com/amisadmin/fastapi_amis_admin_demo/master/upload/img/fastapi-user-auth-docs.png)
279+
![Docs](https://s2.loli.net/2022/03/20/1GcCiPdmXayxrbH.png)
275280

276281
## 未来计划
277282

278283
- [ ] bug修复,细节完善.
279284
- [ ] 完善用户教程文档.
280285
- [ ] 不断拓展与完善核心功能.
281286

282-
283287
## 许可协议
284288

285289
- `fastapi-amis-admin`基于`Apache2.0`开源免费使用,可以免费用于商业用途,但请在展示界面中明确显示关于FastAPI-Amis-Admin的版权信息.

fastapi_user_auth/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "0.0.20"
1+
__version__ = "0.0.21"
22
__url__ = "https://github.com/amisadmin/fastapi-user-auth"

fastapi_user_auth/auth/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ async def user_logout(request: Request, response: Response):
266266
try:
267267
await self.auth.backend.token_store.destroy_token(token=token_value)
268268
except Exception as e: # jwt
269-
return BaseApiOut(status=-1, msg=str(e))
269+
pass
270270
response.delete_cookie('Authorization')
271271
return RedirectResponse(url='/')
272272

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ classifiers = [
3636
"Programming Language :: Python :: 3.10",
3737
]
3838
dependencies = [
39-
"fastapi-amis-admin>=0.0.19",
39+
"fastapi-amis-admin>=0.0.20",
4040
"email-validator",
4141
"passlib",
4242
"bcrypt",

0 commit comments

Comments
 (0)