@@ -14,25 +14,32 @@ import (
1414 "scroll-tech/coordinator/internal/types"
1515)
1616
17+ type ClientHelper interface {
18+ GenLoginParam (string ) (* types.LoginParameter , error )
19+ OnError (isUnauth bool )
20+ }
21+
1722// Client wraps an http client with a preset host for coordinator API calls
1823type upClient struct {
1924 httpClient * http.Client
2025 baseURL string
2126 loginToken string
27+ helper ClientHelper
2228}
2329
2430// NewClient creates a new Client with the specified host
25- func newUpClient (cfg * config.UpStream ) * upClient {
31+ func newUpClient (cfg * config.UpStream , helper ClientHelper ) * upClient {
2632 return & upClient {
2733 httpClient : & http.Client {
2834 Timeout : time .Duration (cfg .ConnectionTimeoutSec ) * time .Second ,
2935 },
3036 baseURL : cfg .BaseUrl ,
37+ helper : helper ,
3138 }
3239}
3340
3441// FullLogin performs the complete login process: get challenge then login
35- func (c * upClient ) Login (ctx context.Context , param types. LoginParameter ) (* types.LoginSchema , error ) {
42+ func (c * upClient ) Login (ctx context.Context ) (* types.LoginSchema , error ) {
3643 // Step 1: Get challenge
3744 url := fmt .Sprintf ("%s/coordinator/v1/challenge" , c .baseURL )
3845
@@ -60,6 +67,11 @@ func (c *upClient) Login(ctx context.Context, param types.LoginParameter) (*type
6067 // Step 3: Use the token from challenge as Bearer token for login
6168 url = fmt .Sprintf ("%s/coordinator/v1/login" , c .baseURL )
6269
70+ param , err := c .helper .GenLoginParam (loginSchema .Token )
71+ if err != nil {
72+ return nil , fmt .Errorf ("failed to setup login parameter: %w" , err )
73+ }
74+
6375 jsonData , err := json .Marshal (param )
6476 if err != nil {
6577 return nil , fmt .Errorf ("failed to marshal login parameter: %w" , err )
0 commit comments