From df54e5c12ac837d885e0d4e57dd82e0f936f512a Mon Sep 17 00:00:00 2001 From: im-adithya Date: Tue, 11 Jun 2024 19:17:52 +0530 Subject: [PATCH 1/4] chore: check identifier during re-auth --- alby/alby_oauth_service.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/alby/alby_oauth_service.go b/alby/alby_oauth_service.go index 970e235c5..82f3acc54 100644 --- a/alby/alby_oauth_service.go +++ b/alby/alby_oauth_service.go @@ -72,24 +72,27 @@ func (svc *albyOAuthService) CallbackHandler(ctx context.Context, code string) e } svc.saveToken(token) + me, err := svc.GetMe(ctx) + if err != nil { + svc.logger.WithError(err).Error("Failed to fetch user me") + // remove token so user can retry + svc.config.SetUpdate(accessTokenKey, me.Identifier, "") + return err + } + existingUserIdentifier, err := svc.GetUserIdentifier() if err != nil { svc.logger.WithError(err).Error("Failed to get alby user identifier") return err } - // setup Alby account on first time login + // save the user's alby account ID on first time login if existingUserIdentifier == "" { - // fetch and save the user's alby account ID. This cannot be changed. - me, err := svc.GetMe(ctx) - if err != nil { - svc.logger.WithError(err).Error("Failed to fetch user me") - // remove token so user can retry - svc.config.SetUpdate(accessTokenKey, me.Identifier, "") - return err - } - svc.config.SetUpdate(userIdentifierKey, me.Identifier, "") + } else { + if existingUserIdentifier != me.Identifier { + return errors.New("alby identifier does not match") + } } return nil From f19ce06f269aa36a7d097b4374a4757e34b8ec1d Mon Sep 17 00:00:00 2001 From: im-adithya Date: Wed, 12 Jun 2024 20:54:03 +0530 Subject: [PATCH 2/4] chore: remove wrong acc token and change message --- alby/alby_oauth_service.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/alby/alby_oauth_service.go b/alby/alby_oauth_service.go index 82f3acc54..c853b404c 100644 --- a/alby/alby_oauth_service.go +++ b/alby/alby_oauth_service.go @@ -91,7 +91,9 @@ func (svc *albyOAuthService) CallbackHandler(ctx context.Context, code string) e svc.config.SetUpdate(userIdentifierKey, me.Identifier, "") } else { if existingUserIdentifier != me.Identifier { - return errors.New("alby identifier does not match") + // remove token so user can retry with correct account + svc.config.SetUpdate(accessTokenKey, me.Identifier, "") + return errors.New("Alby Hub is connected to a different alby account. Please log out of your Alby Account at getalby.com and try again.") } } From 29d3e1627e5f526f6a94252595801cb49438afef Mon Sep 17 00:00:00 2001 From: im-adithya Date: Wed, 12 Jun 2024 20:58:53 +0530 Subject: [PATCH 3/4] chore: remove yoda condition --- alby/alby_oauth_service.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/alby/alby_oauth_service.go b/alby/alby_oauth_service.go index c853b404c..c3094ab02 100644 --- a/alby/alby_oauth_service.go +++ b/alby/alby_oauth_service.go @@ -89,12 +89,10 @@ func (svc *albyOAuthService) CallbackHandler(ctx context.Context, code string) e // save the user's alby account ID on first time login if existingUserIdentifier == "" { svc.config.SetUpdate(userIdentifierKey, me.Identifier, "") - } else { - if existingUserIdentifier != me.Identifier { - // remove token so user can retry with correct account - svc.config.SetUpdate(accessTokenKey, me.Identifier, "") - return errors.New("Alby Hub is connected to a different alby account. Please log out of your Alby Account at getalby.com and try again.") - } + } else if me.Identifier != existingUserIdentifier { + // remove token so user can retry with correct account + svc.config.SetUpdate(accessTokenKey, me.Identifier, "") + return errors.New("Alby Hub is connected to a different alby account. Please log out of your Alby Account at getalby.com and try again.") } return nil From 1adf8a7108077365665d2854d3621ce7c82103ce Mon Sep 17 00:00:00 2001 From: im-adithya Date: Wed, 12 Jun 2024 21:06:07 +0530 Subject: [PATCH 4/4] chore: set empty access token --- alby/alby_oauth_service.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alby/alby_oauth_service.go b/alby/alby_oauth_service.go index c3094ab02..75fa1679c 100644 --- a/alby/alby_oauth_service.go +++ b/alby/alby_oauth_service.go @@ -76,7 +76,7 @@ func (svc *albyOAuthService) CallbackHandler(ctx context.Context, code string) e if err != nil { svc.logger.WithError(err).Error("Failed to fetch user me") // remove token so user can retry - svc.config.SetUpdate(accessTokenKey, me.Identifier, "") + svc.config.SetUpdate(accessTokenKey, "", "") return err } @@ -91,7 +91,7 @@ func (svc *albyOAuthService) CallbackHandler(ctx context.Context, code string) e svc.config.SetUpdate(userIdentifierKey, me.Identifier, "") } else if me.Identifier != existingUserIdentifier { // remove token so user can retry with correct account - svc.config.SetUpdate(accessTokenKey, me.Identifier, "") + svc.config.SetUpdate(accessTokenKey, "", "") return errors.New("Alby Hub is connected to a different alby account. Please log out of your Alby Account at getalby.com and try again.") }