OAuth: nothing asks the user to sign in again when a token is rejected or can't be refreshed

Open
#656 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
ios, swift

Research direction

Start with IMAPError.authenticationFailed in the IMAP module and trace where it stops, then read AccountManager.checkAndRenewExpirations() and the AccountManager.error path for failed refreshes. The account model, the mailbox list and the OAuthButton in account settings are the places a 'needs sign-in' state would surface. Done means a rejected or non-refreshable token marks the account, shows one tap to sign in, and skips mail operations until then, while network errors do not. The design choice of where that state lives needs maintainer input first.

Written by the indexing model from the issue text.

Description

Summary

When a server rejects an OAuth token, or a refresh fails because the refresh token is no longer valid, the app has no way to tell the user to sign in again.

(Found by reading the code.)

Details

  • IMAPError.authenticationFailed (added by the work for #535) is thrown, but nothing above the IMAP module looks for it.
  • A failed refresh in AccountManager.checkAndRenewExpirations() sets AccountManager.error = .authorization(error). #619 covers that these errors are never shown.
  • The account isn't marked as needing sign-in, so every later mail operation tries again with the same credential.
  • OAuthButton in the account settings is the only place to sign in again, and the user has to know to go there.

Expected behavior

  • An account whose credential was rejected is marked as needing sign-in.
  • The user is told, and one tap leads to the sign-in screen.
  • Mail operations for that account are skipped until then, not retried with a credential known to be bad.
  • A temporary failure (no network, server outage) does none of this.

Suggested fix

Record a "needs sign-in" state on the account when a refresh fails with invalid_grant, or when a server rejects a token that was just refreshed. Show it in the mailbox list and in account settings, and clear it on the next successful sign-in.

References

  • RFC 6749, section 5.2, invalid_grant: "The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."
  • Google, OAuth 2.0 for installed apps, on invalid_grant: "Authenticate the user again and ask for user consent to obtain new tokens."
  • RFC 5530, section 3, AUTHENTICATIONFAILED: "there's no point in trying the same login/password again later".
  • Related: #605, #619.

In thunderbird-android

Links are pinned to ac1f0e8.

Dominant language
Swift
Stars
1.3k
Forks
51
Avg merge
1d 7h
Merged PRs (30d)
33

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from thunderbird/thunderbird-ios

All issues in thunderbird/thunderbird-ios

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.