Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tristan957 opened this issue Dec 28, 2023 · 4 comments
Open

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

tristan957 opened this issue Dec 28, 2023 · 4 comments

Comments

@tristan957
Copy link

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.

@tristan957
Copy link
Author

Or if there is a Proton CLI in the works, I will stop my efforts :). I really just want to be able to autocomplete email addresses in my terminal email client :).

@gschaer
Copy link

gschaer commented Nov 8, 2024

In an unofficial python client, they're setting the appversion as "Other" (https://github.com/opulentfox-29/protonmail-api-client/blob/15100c28c40e7c887d70296ae22a3762c19c059e/src/protonmail/constants.py#L17)

It allows you to login without CAPTCHA.

@major0
Copy link

major0 commented Jan 18, 2025

Or if there is a Proton CLI in the works, I will stop my efforts :). I really just want to be able to autocomplete email addresses in my terminal email client :).

I am actively working on a proton-cli tool as part of an effort to understand the API. Unfortunately I am running into a number of bugs/oddities in the released code.

I have a nagging suspicion that Proton is not using the publicly released version of go-proton-api as there are just a number of problems all around. Including, but not limited to:

Missing API calls:

Incompatibilities with recent versions of Go:

General bugs:

I have been trying to fix things and submit my patches, and the patches of others that I have found in other projects, such as https://github.com/henrybear327/go-proton-api, but it is sort of slow going. I am currently trying to solve #169. Assuming I don't continue running into these oddities, I am hopeful I will have a fully working model for the at least a ProtonDrive CLI which can easily be extended to work with the rest of the Proton API.

@major0
Copy link

major0 commented Jan 18, 2025

In an unofficial python client, they're setting the appversion as "Other" (https://github.com/opulentfox-29/protonmail-api-client/blob/15100c28c40e7c887d70296ae22a3762c19c059e/src/protonmail/constants.py#L17)

It allows you to login without CAPTCHA.

I wish I had found this tidbit sooner, I spent part of a day beating my head against the wall trying to come up with an AppVersion that wouldn't be rejected by the upstream server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants