mirror of
https://github.com/Snawoot/windscribe-proxy.git
synced 2026-04-03 12:48:13 +00:00
wndclient: user registration WIP
This commit is contained in:
5
main.go
5
main.go
@@ -17,5 +17,10 @@ func main() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = wndc.Users(context.TODO())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("wndc=%#v\n", wndc)
|
||||
}
|
||||
|
||||
@@ -13,3 +13,21 @@ type RegisterTokenResponse struct {
|
||||
TokenTime int64 `json:"time"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type UsersRequest struct {
|
||||
ClientAuthHash string `json:"client_auth_hash"`
|
||||
SessionType int `json:"session_type_id"`
|
||||
Time int64 `json:"time,string"`
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
type UsersResponse struct {
|
||||
Data *struct {
|
||||
UserID string `json:"user_id"`
|
||||
SessionAuthHash string `json:"session_auth_hash"`
|
||||
Status int `json:"status"`
|
||||
IsPremium int `json:"is_premium"`
|
||||
LocationRevision int `json:"loc_rev"`
|
||||
LocationHash string `json:"loc_hash"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ func (c *WndClient) RegisterToken(ctx context.Context) error {
|
||||
clientAuthHash, authTime := MakeAuthHash(c.Settings.ClientAuthSecret)
|
||||
input := RegisterTokenRequest{
|
||||
ClientAuthHash: clientAuthHash,
|
||||
Time: authTime,
|
||||
Time: authTime,
|
||||
}
|
||||
|
||||
var output RegisterTokenResponse
|
||||
@@ -135,6 +135,38 @@ func (c *WndClient) RegisterToken(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *WndClient) Users(ctx context.Context) error {
|
||||
c.Mux.Lock()
|
||||
defer c.Mux.Unlock()
|
||||
|
||||
clientAuthHash, authTime := MakeAuthHash(c.Settings.ClientAuthSecret)
|
||||
input := UsersRequest{
|
||||
ClientAuthHash: clientAuthHash,
|
||||
Time: authTime,
|
||||
SessionType: SESSION_TYPE_EXT,
|
||||
Token: c.Token,
|
||||
}
|
||||
|
||||
var output UsersResponse
|
||||
|
||||
err := c.postJSON(ctx, c.Settings.Endpoints.Users, input, &output)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if output.Data == nil {
|
||||
return ErrNoDataInResponse
|
||||
}
|
||||
|
||||
c.UserID = output.Data.UserID
|
||||
c.SessionAuthHash = output.Data.SessionAuthHash
|
||||
c.Status = output.Data.Status
|
||||
c.IsPremium = output.Data.IsPremium != 0
|
||||
c.LocationRevision = output.Data.LocationRevision
|
||||
c.LocationHash = output.Data.LocationHash
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *WndClient) postJSON(ctx context.Context, endpoint string, input, output interface{}) error {
|
||||
var reqBuf bytes.Buffer
|
||||
reqEncoder := json.NewEncoder(&reqBuf)
|
||||
@@ -162,7 +194,7 @@ func (c *WndClient) postJSON(ctx context.Context, endpoint string, input, output
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
||||
return fmt.Errorf("bad http status: %s, headers: %#v", resp.Status, resp.Header)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user