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

fix: delete access token when creating backup to migrate node #1040

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions alby/alby_oauth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ func NewAlbyOAuthService(db *gorm.DB, cfg config.Config, keys keys.Keys, eventPu
return albyOAuthSvc
}

func (svc *albyOAuthService) RemoveOAuthAccessToken() error {
err := svc.cfg.SetUpdate(accessTokenKey, "", "")
if err != nil {
logger.Logger.WithError(err).Error("failed to remove access token")
}
return err
}

func (svc *albyOAuthService) CallbackHandler(ctx context.Context, code string, lnClient lnclient.LNClient) error {
token, err := svc.oauthConf.Exchange(ctx, code)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions alby/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type AlbyOAuthService interface {
UnlinkAccount(ctx context.Context) error
RequestAutoChannel(ctx context.Context, lnClient lnclient.LNClient, isPublic bool) (*AutoChannelResponse, error)
GetVssAuthToken(ctx context.Context, nodeIdentifier string) (string, error)
RemoveOAuthAccessToken() error
}

type AlbyBalanceResponse struct {
Expand Down
8 changes: 8 additions & 0 deletions api/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ func (api *api) CreateBackup(unlockPassword string, w io.Writer) error {
// Stop the app to ensure no new requests are processed.
api.svc.StopApp()

// Remove the OAuth access token from the DB to ensure the user
// has to re-auth with the correct OAuth client when they restore the backup
err = api.albyOAuthSvc.RemoveOAuthAccessToken()
if err != nil {
logger.Logger.WithError(err).Error("Failed to remove oauth access token")
return errors.New("failed to remove oauth access token")
}

// Closing the database leaves the service in an inconsistent state,
// but that should not be a problem since the app is not expected
// to be used after its data is exported.
Expand Down
Loading