mirror of
https://github.com/henrybear327/Proton-API-Bridge.git
synced 2026-04-30 11:12:37 -04:00
Add a new configuration option: UserAgent
This commit is contained in:
@@ -5,6 +5,7 @@ import "os"
|
||||
type Config struct {
|
||||
/* Constants */
|
||||
AppVersion string
|
||||
UserAgent string
|
||||
|
||||
/* Login */
|
||||
FirstLoginCredential *FirstLoginCredentialData
|
||||
@@ -37,6 +38,7 @@ type ReusableCredentialData struct {
|
||||
func NewConfigWithDefaultValues() *Config {
|
||||
return &Config{
|
||||
AppVersion: "",
|
||||
UserAgent: "",
|
||||
|
||||
FirstLoginCredential: &FirstLoginCredentialData{
|
||||
Username: "",
|
||||
@@ -62,6 +64,8 @@ func NewConfigWithDefaultValues() *Config {
|
||||
|
||||
func NewConfigForIntegrationTests() *Config {
|
||||
appVersion := os.Getenv("PROTON_API_BRIDGE_APP_VERSION")
|
||||
userAgent := os.Getenv("PROTON_API_BRIDGE_USER_AGENT")
|
||||
|
||||
username := os.Getenv("PROTON_API_BRIDGE_TEST_USERNAME")
|
||||
password := os.Getenv("PROTON_API_BRIDGE_TEST_PASSWORD")
|
||||
twoFA := os.Getenv("PROTON_API_BRIDGE_TEST_TWOFA")
|
||||
@@ -79,6 +83,7 @@ func NewConfigForIntegrationTests() *Config {
|
||||
|
||||
return &Config{
|
||||
AppVersion: appVersion,
|
||||
UserAgent: userAgent,
|
||||
|
||||
FirstLoginCredential: &FirstLoginCredentialData{
|
||||
Username: username,
|
||||
|
||||
@@ -4,10 +4,11 @@ import (
|
||||
"github.com/henrybear327/go-proton-api"
|
||||
)
|
||||
|
||||
func getProtonManager(appVersion string) *proton.Manager {
|
||||
func getProtonManager(appVersion string, userAgent string) *proton.Manager {
|
||||
/* Notes on API calls: if the app version is not specified, the api calls will be rejected. */
|
||||
options := []proton.Option{
|
||||
proton.WithAppVersion(appVersion),
|
||||
proton.WithUserAgent(userAgent),
|
||||
}
|
||||
m := proton.New(options...)
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ func Login(ctx context.Context, config *Config) (*proton.Manager, *proton.Client
|
||||
var addr []proton.Address
|
||||
|
||||
// get manager
|
||||
m := getProtonManager(config.AppVersion)
|
||||
m := getProtonManager(config.AppVersion, config.UserAgent)
|
||||
|
||||
if config.UseReusableLogin {
|
||||
c = m.NewClient(config.ReusableCredential.UID, config.ReusableCredential.AccessToken, config.ReusableCredential.RefreshToken)
|
||||
@@ -81,6 +81,7 @@ func Login(ctx context.Context, config *Config) (*proton.Manager, *proton.Client
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, nil, err
|
||||
}
|
||||
// log.Printf("Available scopes %#v", auth.Scope)
|
||||
|
||||
if auth.TwoFA.Enabled&proton.HasTOTP != 0 {
|
||||
if config.FirstLoginCredential.TwoFA != "" {
|
||||
|
||||
Reference in New Issue
Block a user