mirror of
https://github.com/henrybear327/Proton-API-Bridge.git
synced 2026-04-20 14:46:51 -04:00
Add authHandler and deAuthHandler to the ProtonDrive init function
This commit is contained in:
@@ -47,7 +47,7 @@ Log in methods
|
||||
Keyring decryption
|
||||
The password will be salted, and then used to decrypt the keyring. The salted password needs to be and can be cached, so the keyring can be re-decrypted when needed
|
||||
*/
|
||||
func Login(ctx context.Context, config *Config) (*proton.Manager, *proton.Client, *ProtonDriveCredential, *crypto.KeyRing, map[string]*crypto.KeyRing, []proton.Address, error) {
|
||||
func Login(ctx context.Context, config *Config, authHandler proton.AuthHandler, deAuthHandler proton.Handler) (*proton.Manager, *proton.Client, *ProtonDriveCredential, *crypto.KeyRing, map[string]*crypto.KeyRing, []proton.Address, error) {
|
||||
var c *proton.Client
|
||||
var auth proton.Auth
|
||||
var userKR *crypto.KeyRing
|
||||
@@ -59,8 +59,8 @@ func Login(ctx context.Context, config *Config) (*proton.Manager, *proton.Client
|
||||
|
||||
if config.UseReusableLogin {
|
||||
c = m.NewClient(config.ReusableCredential.UID, config.ReusableCredential.AccessToken, config.ReusableCredential.RefreshToken)
|
||||
|
||||
// TODO: register auth/deauth handler
|
||||
c.AddAuthHandler(authHandler)
|
||||
c.AddDeauthHandler(deAuthHandler)
|
||||
|
||||
err := cacheCredentialToFile(config)
|
||||
if err != nil {
|
||||
@@ -90,7 +90,8 @@ func Login(ctx context.Context, config *Config) (*proton.Manager, *proton.Client
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, nil, nil, err
|
||||
}
|
||||
// log.Printf("Available scopes %#v", auth.Scope)
|
||||
c.AddAuthHandler(authHandler)
|
||||
c.AddDeauthHandler(deAuthHandler)
|
||||
|
||||
if auth.TwoFA.Enabled&proton.HasTOTP != 0 {
|
||||
if config.FirstLoginCredential.TwoFA != "" {
|
||||
|
||||
4
drive.go
4
drive.go
@@ -31,9 +31,9 @@ func NewDefaultConfig() *common.Config {
|
||||
return common.NewConfigWithDefaultValues()
|
||||
}
|
||||
|
||||
func NewProtonDrive(ctx context.Context, config *common.Config) (*ProtonDrive, *common.ProtonDriveCredential, error) {
|
||||
func NewProtonDrive(ctx context.Context, config *common.Config, authHandler proton.AuthHandler, deAuthHandler proton.Handler) (*ProtonDrive, *common.ProtonDriveCredential, error) {
|
||||
/* Log in and logout */
|
||||
m, c, credentials, userKR, addrKRs, addrData, err := common.Login(ctx, config)
|
||||
m, c, credentials, userKR, addrKRs, addrData, err := common.Login(ctx, config, authHandler, deAuthHandler)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func setup(t *testing.T, replaceExistingDraft bool) (context.Context, context.Ca
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
protonDrive, auth, err := NewProtonDrive(ctx, config)
|
||||
protonDrive, auth, err := NewProtonDrive(ctx, config, func(auth proton.Auth) {}, func() {})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user