Closed Bug 1597933 Opened 6 years ago Closed 6 years ago

clean up OAuth2 code

Categories

(Thunderbird :: General, task)

task
Not set
normal

Tracking

(thunderbird_esr68 fixed)

RESOLVED FIXED
Thunderbird 72.0
Tracking Status
thunderbird_esr68 --- fixed

People

(Reporter: mkmelin, Assigned: mkmelin)

References

Details

Attachments

(4 files)

There is some dead code to remove and other things that could be modernized in the OAuth2 code to make it less confusing.

Status: NEW → ASSIGNED

From bug 1592407 comment 31. We don't need the hash, since we don't do the implicit flow now, which was the only thing that could use id.

Attachment #9110213 - Flags: review?(philipp)

Constants are overrated... all they do is make you jump back and forwards in code, when what you really want to do is verify it's correct as per the rfc.

Attachment #9110214 - Flags: review?(philipp)
Attachment #9110215 - Flags: review?(philipp)
Attachment #9110212 - Flags: review?(philipp) → review+
Comment on attachment 9110213 [details] [diff] [review] bug1597933_oauth_parse_params.patch Review of attachment 9110213 [details] [diff] [review]: ----------------------------------------------------------------- ::: mailnews/base/util/OAuth2.jsm @@ +173,5 @@ > > + // @see RFC 6749 section 4.1.2: Authorization Response > + onAuthorizationReceived(aURL) { > + this.log.info("OAuth2 authorization received: url=" + aURL); > + let params = new URLSearchParams(aURL.split("?", 2)[1]); Would it make sense to use new URL() on `aURL` and then use `.search.substr(1)` ?
Attachment #9110213 - Flags: review?(philipp) → review+
Comment on attachment 9110214 [details] [diff] [review] bug1597933_oauth_grant.patch Review of attachment 9110214 [details] [diff] [review]: ----------------------------------------------------------------- ::: mailnews/base/util/OAuth2.jsm @@ +172,5 @@ > onAuthorizationReceived(aURL) { > this.log.info("OAuth2 authorization received: url=" + aURL); > let params = new URLSearchParams(aURL.split("?", 2)[1]); > if (params.has("code")) { > + this.requestAccessToken(params.get("code"), false); I find boolean args hard to read and you always have to remember the function signature. I'm not overly opposed though, so I'm going to r+ @@ +198,3 @@ > ]; > > + if (!aRefresh) { Can you switch around these blocks as per eslint no-negated-condition? @@ +202,2 @@ > params.push(["code", aCode]); > params.push(["redirect_uri", this.completionURI]); If you like you could also pass multiple args to one params.push call.
Attachment #9110214 - Flags: review?(philipp) → review+

(In reply to Philipp Kewisch [:Fallen] [:📆] from comment #5)

Would it make sense to use new URL() on aURL and then use .search.substr(1) ?

That was the original suggestion, but it's still just looking at a string, so I didn't really see too much point in it.

Comment on attachment 9110215 [details] [diff] [review] bug1597933_oauth_urlparams.patch Review of attachment 9110215 [details] [diff] [review]: ----------------------------------------------------------------- ::: mailnews/base/util/OAuth2.jsm @@ +64,5 @@ > requestAuthorization() { > + let params = new URLSearchParams(); > + params.append("response_type", "code"); > + params.append("client_id", this.consumerKey); > + params.append("redirect_uri", this.completionURI); You can shorten this to passing an object to the constructor of URLSearchParams. @@ +73,5 @@ > } > > + for (let [name, value] of this.extraAuthParams) { > + params.append(name, value); > + } Together with the object approach you could do: let params = new URLSearchParams({ response_type: "code", client_id: this.consumerKey, redirect_uri: this.completionURI, ...this.extraAuthParams });
Attachment #9110215 - Flags: review?(philipp) → review+

Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/4c34261831ce
clean up OAuth2 code: remove responseType which is always "code". r=Fallen
https://hg.mozilla.org/comm-central/rev/ff646df74684
improve OAuth2 params parsing. r=Fallen
https://hg.mozilla.org/comm-central/rev/9b0f8cb7ffc1
don't pass string constants to determine OAuth refresh token or not. r=Fallen
https://hg.mozilla.org/comm-central/rev/42ac954abcd0
use fetch + URLSearchParms instead of Http.jsm to request OAuth2 access token. r=Fallen
https://hg.mozilla.org/comm-central/rev/f962ffd01192
Use URLSearchParams for setting params for OAuth2 authorization request. r=Fallen

Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → Thunderbird 72.0

Looks like you broke
TEST-UNEXPECTED-FAIL | comm/mail/components/enterprisepolicies/tests/browser/browser_policy_extensions.js | Uncaught exception - at chrome://mochitests/content/browser/comm/mail/components/enterprisepolicies/tests/browser/browser_policy_extensions.js:23 - TypeError: disableBtn is null

Status: RESOLVED → REOPENED
Flags: needinfo?(mkmelin+mozilla)
Resolution: FIXED → ---

Sorry, my mistake, that was already broken in the Daily run.

Status: REOPENED → RESOLVED
Closed: 6 years ago6 years ago
Flags: needinfo?(mkmelin+mozilla)
Resolution: --- → FIXED
Attachment #9110212 - Flags: approval-comm-esr68+
Attachment #9110213 - Flags: approval-comm-esr68+
Attachment #9110214 - Flags: approval-comm-esr68+
Attachment #9110215 - Flags: approval-comm-esr68+

(In reply to Pulsebot from comment #9)

https://hg.mozilla.org/comm-central/rev/42ac954abcd0
use fetch + URLSearchParms instead of Http.jsm to request OAuth2 access token. r=Fallen

This patch wasn't attached and reviewed. Looks like it was just forgotten. I'm going to uplift it anyway because it's fine.

Regressions: 1612717
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: