mirror of
https://github.com/fumiama/tienyik.git
synced 2026-06-10 10:00:23 +08:00
feat: add more apis & cmd tyaliv
This commit is contained in:
@@ -94,11 +94,11 @@ type RequestLogin struct {
|
||||
ChallengeID string `form:"challengeId"`
|
||||
DeviceCode string `form:"deviceCode"`
|
||||
DeviceName string `form:"deviceName"`
|
||||
DeviceType string `form:"deviceType"`
|
||||
DeviceType uint64 `form:"deviceType"`
|
||||
DeviceModel string `form:"deviceModel"`
|
||||
AppVersion string `form:"appVersion"`
|
||||
SysVersion string `form:"sysVersion"`
|
||||
ClientVersion string `form:"clientVersion"`
|
||||
ClientVersion uint64 `form:"clientVersion"`
|
||||
}
|
||||
|
||||
type ResponseLogin struct {
|
||||
@@ -135,6 +135,8 @@ type ResponseLogin struct {
|
||||
func (r *ResponseLogin) SetClient(cli *hcli.Client) {
|
||||
cli.Tenantid = strconv.FormatInt(r.TenantID, 10)
|
||||
cli.Usereid = r.UserEid
|
||||
cli.SetSecretKey(r.SecretKey)
|
||||
cli.SetTimestamp(r.Timestamp)
|
||||
}
|
||||
|
||||
func Login(tya *tienyik.AES, cli *hcli.Client, r *RequestLogin) (*ResponseLogin, error) {
|
||||
@@ -148,3 +150,10 @@ func Login(tya *tienyik.AES, cli *hcli.Client, r *RequestLogin) (*ResponseLogin,
|
||||
defer resp.Body.Close()
|
||||
return hson.Unmarshal[*ResponseLogin](tya, resp.Body)
|
||||
}
|
||||
|
||||
func Logout(tya *tienyik.AES, cli *hcli.Client) error {
|
||||
_, err := cli.Post(
|
||||
textio.API(), "", nil,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3,9 +3,12 @@ package auth
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/fumiama/tienyik"
|
||||
"github.com/fumiama/tienyik/api/cdserv"
|
||||
"github.com/fumiama/tienyik/hcli"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -36,3 +39,39 @@ func TestNegotiationEncKey(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogin(t *testing.T) {
|
||||
cli := hcli.NewClient()
|
||||
sd, err := cdserv.GetServData()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("get serv data:", sd)
|
||||
x, err := GenChallengeData(nil, cli)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sd.SetClient(cli)
|
||||
rsp, err := Login(nil, cli, &RequestLogin{
|
||||
UserAccount: os.Getenv("TYUSR"),
|
||||
Password: tienyik.ChallengePassword(os.Getenv("TYPWD"), x.ChallengeCode),
|
||||
SHA256Password: tienyik.ChallengeSHA256Password(os.Getenv("TYPWD"), x.ChallengeCode),
|
||||
ChallengeID: x.ChallengeID,
|
||||
DeviceCode: cli.Devicecode,
|
||||
DeviceName: tienyik.DeviceNameEdge,
|
||||
DeviceType: cli.Devicetype,
|
||||
DeviceModel: tienyik.DeviceModelMacOS,
|
||||
AppVersion: tienyik.AppVersion,
|
||||
SysVersion: tienyik.DeviceModelMacOS,
|
||||
ClientVersion: cli.Version,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(rsp)
|
||||
rsp.SetClient(cli)
|
||||
err = Logout(nil, cli)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user