OwO-Network / DeepLX

Powerful Free DeepL API, No Token Required
https://ssa.sx/deeplx
MIT License
6.28k stars 507 forks source link

v2/translate 接口的 Authorization 头和官方不一致 #104

Closed tisfeng closed 5 months ago

tisfeng commented 5 months ago

这个 issue https://github.com/OwO-Network/DeepLX/issues/99 实现了 DeepLX 接口替换官方接口,方便在各种翻译软件中使用。

今天我在使用 Raycast-Easydict 测试 自定义 DeepL 地址 时遇到问题,如果部署 DeepLX 时设置了 Authorization,DeepLX 的请求格式是 Bearer $token,而 DeepL 官方接口 格式是 DeepL-Auth-Key $token,从而导致认证失败。

希望能够兼容官方的 Authorization 头,实现完美替换官方接口。

missuo commented 5 months ago

请注意 authkeytoken 在 DeepLX 中不是一个东西!

在 DeepLX 中 authkey 是当免费的 API 用到 IP 被封之后,才会透过 authkey 使用官方的付费 API。所以 authkey 在大部分情况下不是必须的参数。

Bearer 中的 token 可以理解为 accesstoken 仅仅只是为了保护您公开的 API 不被滥用。

所以,在你没有设置 accesstoken 的情况下,可以直接无视 Authorization,请求 /v2/* 相关的 API。

missuo commented 5 months ago

当然,我可以将 Authorization 用来验证 accesstoken,但是在这种情况下,会丢弃掉 authkey 的传递,如果频繁使用出现 429 之后,您将无法继续使用翻译服务。

我不确定用户更想要的是在和官方一致的 Authorization 中传递 authkey 还是 accesstoken

tisfeng commented 5 months ago

请注意 authkey 和 token 在 DeepLX 中不是一个东西!

我明白这一点,我部署服务时设置的是 token,我的 authkey 已经被官方封掉了。。。我觉得,大部分需要 DeepLX 服务的用户应该都是没办法通过正规渠道获取官方 authkey 😥

missuo commented 5 months ago

请注意 authkey 和 token 在 DeepLX 中不是一个东西!

我明白这一点,我部署服务时设置的是 token,我的 authkey 已经被官方封掉了。。。我觉得,大部分需要 DeepLX 服务的用户应该都是没办法通过正规渠道获取官方 authkey 😥

OK,晚些时候我改下代码,支持对 accesstoken 的验证。

tisfeng commented 5 months ago

我不确定用户更想要的是在和官方一致的 Authorization 中传递 authkey 还是 accesstoken。

如果是考虑到这一点,那我觉得可以通过判断 Authorization 的值来决定,因为官方的 key 都是以 :fx 结尾。

另外,也可以在 DeepLX 部署文档中说明一下这一点,提示用户不要将 token 设置的和官方 auth_key 格式一样,避免问题。

missuo commented 5 months ago

Fixed in https://github.com/OwO-Network/DeepLX/commit/e15e63b79706f0ce1edb47213a7cc54e90ccdaa1

Compatible with requests using JSON and form data in https://github.com/OwO-Network/DeepLX/commit/90d4d44fc07ed0bc31cad90a98fd208bc2db0980

tisfeng commented 5 months ago

Great ❤️