OAuth: token endpoint errors aren't decoded, and optional response fields are treated as required
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- swift
- Domain
- authentication, mobile
Research direction
Start with the token types TokenResponse and RefreshTokenResponse, then OAuthButton.getToken and AccountManager.renewExpiredToken, which the issue says share this path. Check how the HTTP status and error body are handled today, and note that the linked RealOAuth2TokenProvider.getToken in thunderbird-android is a reference for the intended behavior, not code in this repo. Done when an invalid_grant response yields a sign-in-again error without retries, optional expires_in and refresh_token decode, and non-Bearer token types are rejected.
Written by the indexing model from the issue text.
Description
Summary
The code that exchanges an authorization code and refreshes a token only understands a successful response of one exact shape. An error response, or a successful one without the optional fields, turns into a decoding failure.
(Found by reading the code, and confirmed by decoding sample responses.)
Details
- Errors.
{"error":"invalid_grant","error_description":"…"}doesn't decode asRefreshTokenResponse, so the caller sees aDecodingErrorand can't tell a revoked refresh token from a malformed reply. The HTTP status isn't checked. - Retries.
AccountManager.renewExpiredTokenretries every failure twice, including one that can never succeed. - Optional fields.
TokenResponsefails to decode withoutrefresh_tokenor withoutexpires_in. - Token type.
token_typeisn't read. A response with"token_type":"mac"is accepted and used as a bearer token.
Expected behavior
- An error response is decoded into an error that carries the server's
errorcode. invalid_grantis treated as "sign in again" and isn't retried. Network and server errors are treated as temporary.- A response without
expires_inorrefresh_tokenis accepted. - A token whose type isn't
Beareris rejected.
Suggested fix
Decode the error shape first, make expires_in and refresh_token optional, check token_type without regard to case, and retry only temporary failures. OAuthButton.getToken and AccountManager.renewExpiredToken can share this.
References
- RFC 6749, section 5.1: "expires_in RECOMMENDED. The lifetime in seconds of the access token." and "refresh_token OPTIONAL. The refresh token, which can be used to obtain new access tokens".
- 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." - RFC 6749, section 7.1: "The client MUST NOT use an access token if it does not understand the token type."
- RFC 6749, section 5.1: "The client MUST ignore unrecognized value names in the response."
In thunderbird-android
RealOAuth2TokenProvider.getTokenkeeps the stored state on network and server errors, and clears it and reports a sign-in failure on anything else.
Links are pinned to ac1f0e8.
- Dominant language
- Swift
- Stars
- 1.3k
- Forks
- 51
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 33
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from thunderbird/thunderbird-ios
-
Account: Authorization's description returns the stored credential, including the refresh tokenOpen
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
thunderbird/thunderbird-ios#666 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
thunderbird/thunderbird-ios#664 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
thunderbird/thunderbird-ios#658 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
thunderbird/thunderbird-ios#657 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
thunderbird/thunderbird-ios#647 ·
Maintainers usually reply within 1 day
All issues in thunderbird/thunderbird-ios
Similar issues
-
enhancement help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
heysidhant/appvanish#4 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
timfraedrich/OutRun#121 ·
-
deferred tooling
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
mauwii/pokerchipcase#157 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 78/100