Skip to content

Commit 1292d37

Browse files
committed
[Add] ✨ Support Mutil AUTH_KEY #407 #416
1 parent e9c79dd commit 1292d37

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

cloudflare/worker.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const CUSTOM_OPTIONS = {
1111
APIKEY: '',
1212
Go_Proxy_BingAI_BLANK_API_KEY: false,
1313

14-
Go_Proxy_BingAI_AUTH_KEY: '',
14+
Go_Proxy_BingAI_AUTH_KEYS: '',
1515

1616
INFO: '',
1717
NIGHTLY: false,
@@ -426,7 +426,7 @@ export default {
426426
CUSTOM_OPTIONS.Go_Proxy_BingAI_BLANK_API_KEY = (env.Go_Proxy_BingAI_BLANK_API_KEY != '' && env.Go_Proxy_BingAI_BLANK_API_KEY != undefined &&env.Go_Proxy_BingAI_BLANK_API_KEY != null);
427427
CUSTOM_OPTIONS.INFO = env.INFO || '';
428428
CUSTOM_OPTIONS.NIGHTLY = (env.NIGHTLY != '' && env.NIGHTLY != undefined && env.NIGHTLY != null);
429-
CUSTOM_OPTIONS.Go_Proxy_BingAI_AUTH_KEY = env.Go_Proxy_BingAI_AUTH_KEY || '';
429+
CUSTOM_OPTIONS.Go_Proxy_BingAI_AUTH_KEYS = env.Go_Proxy_BingAI_AUTH_KEY.split(',') || '';
430430

431431
const currentUrl = new URL(request.url);
432432
if (WEB_CONFIG.WORKER_URL == '') {
@@ -438,7 +438,7 @@ export default {
438438
}
439439
if (currentUrl.pathname.startsWith('/sysconf')) {
440440
let isAuth = true;
441-
if (CUSTOM_OPTIONS.Go_Proxy_BingAI_AUTH_KEY.length !== 0) {
441+
if (CUSTOM_OPTIONS.Go_Proxy_BingAI_AUTH_KEYS.length !== 0) {
442442
const cookieStr = request.headers.get('Cookie') || '';
443443
let cookieObjects = {};
444444
cookieStr.split(';').forEach(item => {
@@ -450,7 +450,7 @@ export default {
450450
const val = arr.slice(1, arr.length+1).join('=').trim();
451451
cookieObjects[key] = val;
452452
})
453-
if (cookieObjects[AUTH_KEY_COOKIE_NAME] !== CUSTOM_OPTIONS.Go_Proxy_BingAI_AUTH_KEY) {
453+
if (CUSTOM_OPTIONS.Go_Proxy_BingAI_AUTH_KEYS.indexOf(cookieObjects[AUTH_KEY_COOKIE_NAME]) === -1) {
454454
isAuth = false;
455455
}
456456
}

common/api/v1/func.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ func init() {
3535

3636
func getCookie(reqCookie, convId, rid string) (cookie string, err error) {
3737
cookie = reqCookie
38-
if common.AUTH_KEY != "" {
39-
cookie += "; " + common.AUTH_KEY_COOKIE_NAME + "=" + common.AUTH_KEY
38+
if len(common.AUTH_KEYS) > 0 {
39+
cookie += "; " + common.AUTH_KEY_COOKIE_NAME + "=" + common.AUTH_KEYS[0]
4040
}
4141
c := request.NewRequest()
4242
res := c.SetUrl("http://localhost:"+common.PORT+"/chat?q=Bing+AI&showconv=1&FORM=hpcodx&ajaxhist=0&ajaxserp=0&cc=us").
@@ -65,8 +65,8 @@ func getCookie(reqCookie, convId, rid string) (cookie string, err error) {
6565
if len(common.USER_TOKEN_LIST) == 0 {
6666
cookie += "; _U=" + hex.NewHex(128)
6767
}
68-
if common.AUTH_KEY != "" {
69-
cookie += "; " + common.AUTH_KEY_COOKIE_NAME + "=" + common.AUTH_KEY
68+
if len(common.AUTH_KEYS) > 0 {
69+
cookie += "; " + common.AUTH_KEY_COOKIE_NAME + "=" + common.AUTH_KEYS[0]
7070
}
7171
return cookie, nil
7272
}

common/env.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var (
2121
USER_RwBf string
2222
USER_MUID string
2323
// 访问权限密钥,可选
24-
AUTH_KEY string
24+
AUTH_KEYS []string
2525
AUTH_KEY_COOKIE_NAME = "BingAI_Auth_Key"
2626

2727
BypassServer string
@@ -56,7 +56,7 @@ func initEnv() {
5656
// is debug
5757
IS_DEBUG_MODE = os.Getenv("Go_Proxy_BingAI_Debug") != ""
5858
// auth
59-
AUTH_KEY = os.Getenv("Go_Proxy_BingAI_AUTH_KEY")
59+
AUTH_KEYS = strings.Split(os.Getenv("Go_Proxy_BingAI_AUTH_KEY"), ",")
6060
// KievRPSSecAuth Cookie
6161
USER_KievRPSSecAuth = os.Getenv("USER_KievRPSSecAuth")
6262
// MUID Cookie

common/helper/helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ func UnauthorizedResult(w http.ResponseWriter) error {
4141

4242
func CheckAuth(r *http.Request) bool {
4343
isAuth := true
44-
if len(common.AUTH_KEY) > 0 {
44+
if len(common.AUTH_KEYS) > 0 {
4545
ckAuthKey, _ := r.Cookie(common.AUTH_KEY_COOKIE_NAME)
46-
isAuth = ckAuthKey != nil && len(ckAuthKey.Value) > 0 && common.AUTH_KEY == ckAuthKey.Value
46+
isAuth = ckAuthKey != nil && len(ckAuthKey.Value) > 0 && common.IsInArray(common.AUTH_KEYS, ckAuthKey.Value)
4747
}
4848
return isAuth
4949
}

0 commit comments

Comments
 (0)