mirror of
https://github.com/langbot-app/LangBot.git
synced 2025-11-25 11:29:39 +08:00
* Initial plan * feat: Add API key authentication system backend Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * feat: Add API key management UI in frontend sidebar Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * fix: Correct import paths in API controller groups Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * fix: Address code review feedback - add i18n and validation Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * refactor: Enable API key auth on existing endpoints instead of creating separate service API - Added USER_TOKEN_OR_API_KEY auth type that accepts both authentication methods - Removed separate /api/service/v1/models endpoints - Updated existing endpoints (models, bots, pipelines) to accept API keys - External services can now use API keys to access all existing LangBot APIs - Updated documentation to reflect unified API approach Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * docs: Add OpenAPI specification for API key authenticated endpoints Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * chore: rename openapi spec * perf: ui and i18n * fix: ui bug * chore: tidy docs * chore: fix linter errors --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> Co-authored-by: Junyan Qin <rockchinq@gmail.com>
44 lines
1.7 KiB
Python
44 lines
1.7 KiB
Python
import quart
|
|
|
|
from .. import group
|
|
|
|
|
|
@group.group_class('apikeys', '/api/v1/apikeys')
|
|
class ApiKeysRouterGroup(group.RouterGroup):
|
|
async def initialize(self) -> None:
|
|
@self.route('', methods=['GET', 'POST'])
|
|
async def _() -> str:
|
|
if quart.request.method == 'GET':
|
|
keys = await self.ap.apikey_service.get_api_keys()
|
|
return self.success(data={'keys': keys})
|
|
elif quart.request.method == 'POST':
|
|
json_data = await quart.request.json
|
|
name = json_data.get('name', '')
|
|
description = json_data.get('description', '')
|
|
|
|
if not name:
|
|
return self.http_status(400, -1, 'Name is required')
|
|
|
|
key = await self.ap.apikey_service.create_api_key(name, description)
|
|
return self.success(data={'key': key})
|
|
|
|
@self.route('/<int:key_id>', methods=['GET', 'PUT', 'DELETE'])
|
|
async def _(key_id: int) -> str:
|
|
if quart.request.method == 'GET':
|
|
key = await self.ap.apikey_service.get_api_key(key_id)
|
|
if key is None:
|
|
return self.http_status(404, -1, 'API key not found')
|
|
return self.success(data={'key': key})
|
|
|
|
elif quart.request.method == 'PUT':
|
|
json_data = await quart.request.json
|
|
name = json_data.get('name')
|
|
description = json_data.get('description')
|
|
|
|
await self.ap.apikey_service.update_api_key(key_id, name, description)
|
|
return self.success()
|
|
|
|
elif quart.request.method == 'DELETE':
|
|
await self.ap.apikey_service.delete_api_key(key_id)
|
|
return self.success()
|