feat: add api auth
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
from apiflask import APIBlueprint
|
||||
|
||||
from app.api.v1.api import api
|
||||
from app.api.v1.auth import auth
|
||||
|
||||
|
||||
def create_v1():
|
||||
bp_v1 = APIBlueprint('v1', __name__)
|
||||
bp_v1.register_blueprint(api, url_prefix='/api')
|
||||
bp_v1.register_blueprint(auth, url_prefix='/auth')
|
||||
return bp_v1
|
||||
|
||||
|
||||
|
22
app/api/v1/auth.py
Normal file
22
app/api/v1/auth.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from apiflask import APIBlueprint
|
||||
|
||||
from app import rpc
|
||||
from app.api.v1.schema.auth import WechatLoginIn, WechatLoginOut, RefreshTokenIn, RefreshTokenOut
|
||||
|
||||
auth = APIBlueprint('auth', __name__)
|
||||
|
||||
|
||||
@auth.post('/wechat_login')
|
||||
@auth.input(WechatLoginIn)
|
||||
@auth.output(WechatLoginOut)
|
||||
def wechat_login(data):
|
||||
result = rpc.admin.wechat_login(data['code'])
|
||||
return result
|
||||
|
||||
|
||||
@auth.get('/refresh_token')
|
||||
@auth.input(RefreshTokenIn, location='query')
|
||||
@auth.output(RefreshTokenOut)
|
||||
def refresh_token(data):
|
||||
result = rpc.admin.refresh_token(data['refresh_token'])
|
||||
return result
|
20
app/api/v1/schema/auth.py
Normal file
20
app/api/v1/schema/auth.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from apiflask import Schema
|
||||
from apiflask.fields import String
|
||||
|
||||
|
||||
class WechatLoginIn(Schema):
|
||||
code = String(required=True)
|
||||
|
||||
|
||||
class WechatLoginOut(Schema):
|
||||
access_token = String()
|
||||
refresh_token = String()
|
||||
|
||||
|
||||
class RefreshTokenIn(Schema):
|
||||
refresh_token = String(required=True)
|
||||
|
||||
|
||||
class RefreshTokenOut(Schema):
|
||||
access_token = String()
|
||||
refresh_token = String()
|
Reference in New Issue
Block a user