fix: accept numeric login identifiers
This commit is contained in:
@@ -238,15 +238,26 @@ type qrLoginData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type longPollData struct {
|
type longPollData struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
Desc string `json:"desc"`
|
Desc string `json:"desc"`
|
||||||
Location string `json:"location"`
|
Location string `json:"location"`
|
||||||
Psecurity string `json:"psecurity"`
|
Psecurity string `json:"psecurity"`
|
||||||
Nonce string `json:"nonce"`
|
Nonce stringOrNumber `json:"nonce"`
|
||||||
Ssecurity string `json:"ssecurity"`
|
Ssecurity string `json:"ssecurity"`
|
||||||
PassToken string `json:"passToken"`
|
PassToken string `json:"passToken"`
|
||||||
UserID string `json:"userId"`
|
UserID stringOrNumber `json:"userId"`
|
||||||
CUserID string `json:"cUserId"`
|
CUserID stringOrNumber `json:"cUserId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type stringOrNumber string
|
||||||
|
|
||||||
|
func (value *stringOrNumber) UnmarshalJSON(payload []byte) error {
|
||||||
|
decoded, err := decodeStringOrNumber(payload)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*value = stringOrNumber(decoded)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) Login(ctx context.Context) (AuthData, error) {
|
func (client *Client) Login(ctx context.Context) (AuthData, error) {
|
||||||
@@ -403,11 +414,11 @@ func (client *Client) completeQRLogin(ctx context.Context, loginData qrLoginData
|
|||||||
candidate.ServiceToken = ""
|
candidate.ServiceToken = ""
|
||||||
serviceTokenReceived := updateAuthDataFromCookies(&candidate, httpClient, response.Request.URL)
|
serviceTokenReceived := updateAuthDataFromCookies(&candidate, httpClient, response.Request.URL)
|
||||||
candidate.Psecurity = data.Psecurity
|
candidate.Psecurity = data.Psecurity
|
||||||
candidate.Nonce = data.Nonce
|
candidate.Nonce = string(data.Nonce)
|
||||||
candidate.Ssecurity = data.Ssecurity
|
candidate.Ssecurity = data.Ssecurity
|
||||||
candidate.PassToken = data.PassToken
|
candidate.PassToken = data.PassToken
|
||||||
candidate.UserID = data.UserID
|
candidate.UserID = string(data.UserID)
|
||||||
candidate.CUserID = data.CUserID
|
candidate.CUserID = string(data.CUserID)
|
||||||
if !serviceTokenReceived || !candidate.complete() {
|
if !serviceTokenReceived || !candidate.complete() {
|
||||||
return AuthData{}, &LoginError{Code: -1, Message: "登录回调认证信息不完整"}
|
return AuthData{}, &LoginError{Code: -1, Message: "登录回调认证信息不完整"}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,22 @@ func TestParseServiceResponse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseLongPollResponseAcceptsNumericIdentifiers(t *testing.T) {
|
||||||
|
var result longPollData
|
||||||
|
if err := parseServiceResponse([]byte(`&&&START&&&{"code":0,"nonce":1784441289426,"userId":123456789,"cUserId":987654321}`), &result); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if result.Nonce != "1784441289426" {
|
||||||
|
t.Fatalf("nonce = %q, want 1784441289426", result.Nonce)
|
||||||
|
}
|
||||||
|
if result.UserID != "123456789" {
|
||||||
|
t.Fatalf("userId = %q, want 123456789", result.UserID)
|
||||||
|
}
|
||||||
|
if result.CUserID != "987654321" {
|
||||||
|
t.Fatalf("cUserId = %q, want 987654321", result.CUserID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSaveAuthDataUses0600AndStableFields(t *testing.T) {
|
func TestSaveAuthDataUses0600AndStableFields(t *testing.T) {
|
||||||
directory := t.TempDir()
|
directory := t.TempDir()
|
||||||
client, err := NewClient(directory)
|
client, err := NewClient(directory)
|
||||||
|
|||||||
Reference in New Issue
Block a user