2 Commits

Author SHA1 Message Date
Snawoot
b7ac8a196d Merge pull request #10 from Snawoot/2fa
2FA support
2022-07-27 10:24:17 +03:00
Vladislav Yarmak
b187a9ad28 2fa support 2022-07-27 10:18:40 +03:00
3 changed files with 10 additions and 4 deletions

View File

@@ -64,6 +64,7 @@ windscribe-proxy -list-proxies
| Argument | Type | Description |
| -------- | ---- | ----------- |
| 2fa | String | 2FA code for login |
| auth-secret | String | client auth secret (default `952b4412f002315aa50751032fcaab03`) |
| bind-address | String | HTTP proxy listen address (default `127.0.0.1:28080`) |
| cafile | String | use custom CA certificate bundle file |

View File

@@ -60,6 +60,7 @@ type CLIArgs struct {
stateFile string
username string
password string
tfacode string
}
func parse_args() CLIArgs {
@@ -86,6 +87,7 @@ func parse_args() CLIArgs {
"Windscribe API client state")
flag.StringVar(&args.username, "username", "", "username for login")
flag.StringVar(&args.password, "password", "", "password for login")
flag.StringVar(&args.tfacode, "2fa", "", "2FA code for login")
flag.Parse()
if args.listLocations && args.listProxies {
arg_fail("list-locations and list-proxies flags are mutually exclusive")
@@ -191,7 +193,7 @@ func run() int {
state, err := loadState(args.stateFile)
if err != nil {
mainLogger.Warning("Failed to load client state: %v. Performing cold init...", err)
err = coldInit(wndc, args.username, args.password, args.timeout)
err = coldInit(wndc, args.username, args.password, args.tfacode, args.timeout)
if err != nil {
mainLogger.Critical("Cold init failed: %v", err)
return 9
@@ -371,9 +373,9 @@ func saveState(filename string, state *wndclient.WndClientState) error {
return err
}
func coldInit(wndc *wndclient.WndClient, username, password string, timeout time.Duration) error {
func coldInit(wndc *wndclient.WndClient, username, password, tfacode string, timeout time.Duration) error {
ctx, cl := context.WithTimeout(context.Background(), timeout)
err := wndc.Session(ctx, username, password)
err := wndc.Session(ctx, username, password, tfacode)
cl()
if err != nil {
return fmt.Errorf("Session call failed: %w", err)

View File

@@ -102,7 +102,7 @@ func NewWndClient(transport http.RoundTripper) (*WndClient, error) {
}, nil
}
func (c *WndClient) Session(ctx context.Context, username, password string) error {
func (c *WndClient) Session(ctx context.Context, username, password, tfacode string) error {
c.Mux.Lock()
defer c.Mux.Unlock()
@@ -114,6 +114,9 @@ func (c *WndClient) Session(ctx context.Context, username, password string) erro
"username": []string{username},
"password": []string{password},
}
if tfacode != "" {
input["2fa_code"] = []string{tfacode}
}
var output SessionResponse