@@ -17,6 +17,7 @@ import (
1717 "time"
1818
1919 "github.com/OpenListTeam/OpenList/v4/drivers/base"
20+ "github.com/OpenListTeam/OpenList/v4/pkg/cookie"
2021 "github.com/go-resty/resty/v2"
2122 "github.com/google/uuid"
2223 "golang.org/x/crypto/pbkdf2"
@@ -28,6 +29,9 @@ const (
2829 doubaoBizAuthClientID = "cli_a872ee858eae100e"
2930 doubaoBizAuthClientType = "Lark"
3031 doubaoBizAuthScope = "internal"
32+ doubaoBizAuthAid = "497858"
33+ doubaoBizAuthSDKSource = "web"
34+ doubaoBizAuthSDKVersion = "2.2.11-doubao.0"
3135)
3236
3337type Clock interface {
@@ -397,45 +401,45 @@ func shouldRefreshJWT(token string, aheadSeconds int64) bool {
397401 return payload .Exp <= time .Now ().Unix ()+ aheadSeconds
398402}
399403
400- type bizAuthResp struct {
401- BaseResp
402- Data struct {
403- AccessToken string `json:"access_token"`
404- AuthScheme string `json:"auth_scheme"`
405- ExpiresIn int64 `json:"expires_in"`
406- } `json:"data"`
407- }
408-
409- func (d * DoubaoNew ) tryFetchBizAuth (urlStr , dpop string ) (string , error ) {
404+ func (d * DoubaoNew ) fetchBizAuth (dpop string ) (string , error ) {
410405 client := base .RestyClient .Clone ()
411406 req := client .R ()
412- req .SetHeader ("accept" , "*/* " )
407+ req .SetHeader ("accept" , "application/json, text/javascript " )
413408 req .SetHeader ("origin" , DoubaoURL )
414409 req .SetHeader ("referer" , DoubaoURL + "/" )
415- req .SetHeader ("content-type" , "application/json" )
416- req .SetHeader ("cookie" , d .Cookie )
410+ req .SetHeader ("content-type" , "application/x-www-form-urlencoded" )
411+ if d .Cookie != "" {
412+ req .SetHeader ("cookie" , d .Cookie )
413+ if csrf := strings .TrimSpace (cookie .GetStr (d .Cookie , "passport_csrf_token" )); csrf != "" {
414+ req .SetHeader ("x-tt-passport-csrf-token" , csrf )
415+ }
416+ }
417417 if oldAuth := d .resolveAuthorization (); oldAuth != "" {
418418 req .SetHeader ("authorization" , oldAuth )
419419 }
420420 if dpop != "" {
421421 req .SetHeader ("dpop" , dpop )
422422 }
423- req .SetBody (base.Json {
424- "client_id" : doubaoBizAuthClientID ,
425- "client_type" : doubaoBizAuthClientType ,
426- "scope" : doubaoBizAuthScope ,
427- "d_pop" : dpop ,
428- })
429-
430- res , err := req .Post (urlStr )
423+ values := url.Values {}
424+ values .Set ("client_id" , doubaoBizAuthClientID )
425+ values .Set ("client_type" , doubaoBizAuthClientType )
426+ values .Set ("scope" , doubaoBizAuthScope )
427+ values .Set ("d_pop" , dpop )
428+ req .SetBody (values .Encode ())
429+ req .SetQueryParam ("aid" , doubaoBizAuthAid )
430+ req .SetQueryParam ("account_sdk_source" , doubaoBizAuthSDKSource )
431+ req .SetQueryParam ("sdk_version" , doubaoBizAuthSDKVersion )
432+
433+ res , err := req .Post (DoubaoURL + "/passport/user/biz_auth/" )
431434 if err != nil {
432435 return "" , err
433436 }
434437 var resp bizAuthResp
435438 if err = json .Unmarshal (res .Body (), & resp ); err != nil {
436439 return "" , err
437440 }
438- if resp .Code != 0 || strings .TrimSpace (resp .Data .AccessToken ) == "" {
441+ ok := (resp .Code == 0 || strings .EqualFold (strings .TrimSpace (resp .Message ), "success" )) && strings .TrimSpace (resp .Data .AccessToken ) != ""
442+ if ! ok {
439443 msg := resp .Msg
440444 if msg == "" {
441445 msg = resp .Message
@@ -449,22 +453,14 @@ func (d *DoubaoNew) tryFetchBizAuth(urlStr, dpop string) (string, error) {
449453}
450454
451455func (d * DoubaoNew ) refreshAuthorizationWithDPoP (dpop string ) (string , error ) {
452- endpoints := [] string {
453- "/passport/web/user/biz_auth/" ,
454- "/passport/web/user/anonymity_user_biz_auth/" ,
456+ token , err := d . fetchBizAuth ( dpop )
457+ if err == nil && token != "" {
458+ return token , nil
455459 }
456- var lastErr error
457- for _ , ep := range endpoints {
458- token , err := d .tryFetchBizAuth (DoubaoURL + ep , dpop )
459- if err == nil && token != "" {
460- return token , nil
461- }
462- lastErr = err
463- }
464- if lastErr == nil {
465- lastErr = errors .New ("biz auth refresh failed" )
460+ if err == nil {
461+ err = errors .New ("biz auth refresh failed" )
466462 }
467- return "" , lastErr
463+ return "" , err
468464}
469465
470466func (d * DoubaoNew ) resolveDPoPKeyPair () (* ecdsa.PrivateKey , error ) {
0 commit comments