Skip to content

Commit

Permalink
fix: delete access token when creating backup to migrate node (#1040)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz authored Jan 30, 2025
1 parent a23e24d commit 82e4a16
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
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

0 comments on commit 82e4a16

Please sign in to comment.