-
-
Notifications
You must be signed in to change notification settings - Fork 679
appstore: Fix/invalid auth code #394
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
base: main
Are you sure you want to change the base?
Conversation
|
hi, could you tell how can I use this tool? ✦3 ❯ ./ipatool auth login -e axxxxxx@xxxxxmail.com -p xxxxxxxxx --verbose
[4] 18822
zsh: command not found: 8c
ipatool on fix/invalid-auth-code [?] via 🐹 v1.24.1
✦4 ❯ 8:05AM INF enter 2FA code:
[4] + suspended (tty input) ./ipatool auth login -e axxxxxx@xxxxxmail.com -p xxxxxxxxxbut the process was already terminated before I had a chance to enter the 2FA code. |
you need to escape like wrap your email in double quotes it looks like "youremail@mail.com" and also you need to request a 2fa code from the official apple site when you login and use that 2fa code when you're trying to login |
thanks for your help, I login successfully |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances error handling for App Store login failures related to two-factor authentication (2FA), addressing issues #392 and #387 where users received unhelpful "something went wrong" error messages when 2FA codes were invalid or expired.
Key Changes:
- Introduces a new
ErrInvalidAuthCodeerror to specifically identify invalid or expired 2FA codes - Adds the
FailureTypeInvalidAuthCodeconstant ("5005") to recognize this error condition from Apple's API - Improves generic error messages by including the failure type for easier debugging
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/appstore/constants.go | Adds the FailureTypeInvalidAuthCode constant ("5005") to identify invalid auth code responses from Apple's API |
| pkg/appstore/appstore_login.go | Introduces ErrInvalidAuthCode error and enhances parseLoginResponse logic to detect and return this error for three scenarios: explicit "5005" failure type, invalid credentials with auth code, and bad login message with auth code; also improves generic error messages to include failure type |
| pkg/appstore/appstore_login_test.go | Adds comprehensive test coverage for invalid auth code scenarios and verifies that error messages now include the failure type for debugging |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| retry = true | ||
| } else if res.Data.FailureType == FailureTypeInvalidAuthCode { | ||
| err = ErrInvalidAuthCode | ||
| } else if res.Data.FailureType == FailureTypeInvalidCredentials && authCode != "" { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic handles the case where Apple's API returns FailureTypeInvalidCredentials ("-5000") when an auth code is provided. Consider adding a code comment explaining why "-5000" (typically indicating invalid username/password) is treated as an invalid auth code error when an auth code is present. This would help future maintainers understand that Apple's API can return "-5000" for both invalid credentials and invalid 2FA codes depending on context.
| } else if res.Data.FailureType == FailureTypeInvalidCredentials && authCode != "" { | |
| } else if res.Data.FailureType == FailureTypeInvalidCredentials && authCode != "" { | |
| // Apple's API may return FailureTypeInvalidCredentials ("-5000") both for invalid | |
| // username/password and invalid 2FA codes. When an auth code is present, treat this | |
| // response as an invalid/expired 2FA code to reflect the actual error context. |
| When("store API returns 5005 failure type (invalid auth code)", func() { | ||
| BeforeEach(func() { | ||
| mockClient.EXPECT(). | ||
| Send(gomock.Any()). | ||
| Return(http.Result[loginResult]{ | ||
| Data: loginResult{ | ||
| FailureType: FailureTypeInvalidAuthCode, | ||
| }, | ||
| }, nil) | ||
| }) | ||
|
|
||
| It("returns ErrInvalidAuthCode error", func() { | ||
| _, err := as.Login(LoginInput{ | ||
| Password: testPassword, | ||
| AuthCode: "123456", | ||
| }) | ||
| Expect(err).To(Equal(ErrInvalidAuthCode)) | ||
| }) | ||
| }) | ||
|
|
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage for the scenario where FailureTypeInvalidCredentials is returned with an auth code provided (lines 139-140 of appstore_login.go). This test case would verify the behavior when Apple's API returns "-5000" with an auth code present.
This pull request improves error handling for App Store login, specifically around two-factor authentication (2FA) codes. It introduces a new error for invalid or expired 2FA codes, enhances the logic for parsing login responses, and adds comprehensive test coverage for these scenarios.
Error handling improvements:
ErrInvalidAuthCodeto represent invalid or expired 2FA codes inappstore_login.go.ErrInvalidAuthCodefor various failure types and customer messages related to invalid 2FA codes.FailureTypeInvalidAuthCodeconstant ("5005") to identify invalid auth code errors from the API.Test coverage enhancements:
fixing #392 and #387
need to reference @pradeepvizz for suggesting one request a 2FA code on the website and then utilizing that through the
auth-codeparameter.