mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-23 00:47:31 +09:00
Bug 1597933 - don't pass string constants to determine OAuth refresh token or not.
This commit is contained in:
parent
b037870a86
commit
a8ac34b90b
1 changed files with 16 additions and 10 deletions
|
|
@ -29,9 +29,6 @@ function OAuth2(aBaseURI, aScope, aAppKey, aAppSecret) {
|
||||||
this.log = Log4Moz.getConfiguredLogger("TBOAuth");
|
this.log = Log4Moz.getConfiguredLogger("TBOAuth");
|
||||||
}
|
}
|
||||||
|
|
||||||
OAuth2.CODE_AUTHORIZATION = "authorization_code";
|
|
||||||
OAuth2.CODE_REFRESH = "refresh_token";
|
|
||||||
|
|
||||||
OAuth2.prototype = {
|
OAuth2.prototype = {
|
||||||
consumerKey: null,
|
consumerKey: null,
|
||||||
consumerSecret: null,
|
consumerSecret: null,
|
||||||
|
|
@ -53,7 +50,7 @@ OAuth2.prototype = {
|
||||||
if (!aRefresh && this.accessToken) {
|
if (!aRefresh && this.accessToken) {
|
||||||
aSuccess();
|
aSuccess();
|
||||||
} else if (this.refreshToken) {
|
} else if (this.refreshToken) {
|
||||||
this.requestAccessToken(this.refreshToken, OAuth2.CODE_REFRESH);
|
this.requestAccessToken(this.refreshToken, true);
|
||||||
} else {
|
} else {
|
||||||
if (!aWithUI) {
|
if (!aWithUI) {
|
||||||
aFailure('{ "error": "auth_noui" }');
|
aFailure('{ "error": "auth_noui" }');
|
||||||
|
|
@ -165,7 +162,7 @@ OAuth2.prototype = {
|
||||||
this.log.info("OAuth2 authorization received: url=" + aURL);
|
this.log.info("OAuth2 authorization received: url=" + aURL);
|
||||||
let params = new URLSearchParams(aURL.split("?", 2)[1]);
|
let params = new URLSearchParams(aURL.split("?", 2)[1]);
|
||||||
if (params.has("code")) {
|
if (params.has("code")) {
|
||||||
this.requestAccessToken(params.get("code"), OAuth2.CODE_AUTHORIZATION);
|
this.requestAccessToken(params.get("code"), false);
|
||||||
} else {
|
} else {
|
||||||
this.onAuthorizationFailed(null, aURL);
|
this.onAuthorizationFailed(null, aURL);
|
||||||
}
|
}
|
||||||
|
|
@ -175,18 +172,27 @@ OAuth2.prototype = {
|
||||||
this.connectFailureCallback(aData);
|
this.connectFailureCallback(aData);
|
||||||
},
|
},
|
||||||
|
|
||||||
requestAccessToken: function requestAccessToken(aCode, aType) {
|
/**
|
||||||
|
* Request a new access token, or refresh an existing one.
|
||||||
|
* @param {string} aCode - The token issued to the client.
|
||||||
|
* @param {boolean} aRefresh - Whether it's a refresh of a token or not.
|
||||||
|
*/
|
||||||
|
requestAccessToken(aCode, aRefresh) {
|
||||||
|
// @see RFC 6749 section 4.1.3. Access Token Request
|
||||||
|
// @see RFC 6749 section 6. Refreshing an Access Token
|
||||||
|
|
||||||
let params = [
|
let params = [
|
||||||
["client_id", this.consumerKey],
|
["client_id", this.consumerKey],
|
||||||
["client_secret", this.consumerSecret],
|
["client_secret", this.consumerSecret],
|
||||||
["grant_type", aType],
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if (aType == OAuth2.CODE_AUTHORIZATION) {
|
if (aRefresh) {
|
||||||
|
params.push(["grant_type", "refresh_token"]);
|
||||||
|
params.push(["refresh_token", aCode]);
|
||||||
|
} else {
|
||||||
|
params.push(["grant_type", "authorization_code"]);
|
||||||
params.push(["code", aCode]);
|
params.push(["code", aCode]);
|
||||||
params.push(["redirect_uri", this.completionURI]);
|
params.push(["redirect_uri", this.completionURI]);
|
||||||
} else if (aType == OAuth2.CODE_REFRESH) {
|
|
||||||
params.push(["refresh_token", aCode]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let options = {
|
let options = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue