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

This commit is contained in:
Roland 2025-01-30 14:59:17 +07:00 committed by GitHub
parent a23e24ddd9
commit 82e4a162fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 0 deletions

View file

@ -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 {

View file

@ -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 {

View file

@ -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.