Skip to content

Where are the docs on how to use this library? #139

@tristan957

Description

@tristan957

I am trying to create a little command line client for getting my contact email addresses. Here is my code so far:

package main

import (
	"context"
	"fmt"
	"os"
	"os/signal"
	"syscall"

	"github.com/ProtonMail/go-proton-api"
	"golang.org/x/term"
)

func fatal(err error) {
	fmt.Fprintf(os.Stderr, "%v\n", err)
	os.Exit(1)
}

func main() {
	ctx := context.Background()

	// Create context that becomes done when various signals are received
	ctx, fn := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
	defer fn()

	// How da fuck do you get a valid app version...
	manager := proton.New(proton.WithAppVersion("[email protected]"), proton.WithDebug(true))
	defer manager.Close()

	client, auth, err := manager.NewClientWithLogin(ctx, "email", []byte("password"))
	if err != nil {
		fatal(err)
	}
	defer client.Close()

	if auth.TwoFA.Enabled&proton.HasTOTP != 0 {
		if term.IsTerminal(syscall.Stdin) {
			fmt.Print("TOTP: ")
		}

		code, err := term.ReadPassword(syscall.Stdin)
		if err != nil {
			fatal(err)
		}

		if err := client.Auth2FA(ctx, proton.Auth2FAReq{TwoFactorCode: string(code)}); err != nil {
			panic(err)
		}
	}

	contacts, err := client.GetAllContacts(ctx)
	if err != nil {
		fatal(err)
	}

	for _, contact := range contacts {
		fmt.Println(contact.Name)
	}
}

I have two questions:

  1. What should I put for the app version? Impersonating the web client seems stupid to me, but gets me past the first hurdle.
  2. This gets me to the CAPTCHA which I then need to complete. Is this avoidable? This program would be called tens of times a day. If I had to complete CAPTCHAs all day everyday, I would die. I am assuming I can complete it once, and get a token which I can then login with in subsequent program invocations. Is there an example of some go code which handles this flow?

The interface seems fairly easy to deal with except for the lacking documentation on completing the auth flow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions