go-proton-api
go-proton-api copied to clipboard
Where are the docs on how to use this library?
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:
- What should I put for the app version? Impersonating the web client seems stupid to me, but gets me past the first hurdle.
- 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.
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 :).
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.
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:
- #160
- #161
- #162
- #163
Incompatibilities with recent versions of Go:
- #168
General bugs:
- #169
- #167
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.
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.