Skip to content

Commit

Permalink
Move common oAuthParams to OAuthBackend, make it a static getter (#96)
Browse files Browse the repository at this point in the history
- Usage was exclusively dependent on static properties and passed no parameters
- It seems that this value works much better as a default
  • Loading branch information
LeaVerou authored Jul 30, 2024
1 parent 07dea0e commit 1b2f5f8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
4 changes: 0 additions & 4 deletions backends/dropbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ export default class Dropbox extends OAuthBackend {
});
}

oAuthParams () {
return `&redirect_uri=${encodeURIComponent(this.constructor.authProvider)}&response_type=code`;
}

static userCall = ["users/get_current_account", "null", "POST"];
static userSchema = {
username: "email",
Expand Down
4 changes: 2 additions & 2 deletions backends/github/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export default class Github extends OAuthBackend {
this.updatePermissions({ read: true });
}

oAuthParams () {
return "&scope=user%20repo";
static get oAuthParams () {
return super.oAuthParams + "&scope=user%20repo";
}

static userSchema = {
Expand Down
4 changes: 2 additions & 2 deletions backends/google/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default class Google extends OAuthBackend {
avatar: ["picture", "photoURL"],
};

oAuthParams () {
return `&redirect_uri=${this.constructor.authProvider}&response_type=code&scope=${encodeURIComponent(this.constructor.scopes.join(" "))}`;
static get oAuthParams () {
return super.oAuthParams + `&scope=${ encodeURIComponent(this.scopes.join(" ")) }`;
}

static oAuth = "https://accounts.google.com/o/oauth2/auth";
Expand Down
6 changes: 3 additions & 3 deletions src/oauth-backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export default class OAuthBackend extends AuthBackend {
}

// Any extra params to be passed to the oAuth URL.
oAuthParams () {
return "";
static get oAuthParams () {
return `&redirect_uri=${ encodeURIComponent(this.authProvider) }&response_type=code`;
}

/**
Expand Down Expand Up @@ -238,7 +238,7 @@ export default class OAuthBackend extends AuthBackend {
backend: oAuthBackend.name
};

this.authPopup = open(`${this.constructor.oAuth}?client_id=${this.clientId}&state=${encodeURIComponent(JSON.stringify(state))}` + this.oAuthParams(),
this.authPopup = open(`${this.constructor.oAuth}?client_id=${this.clientId}&state=${encodeURIComponent(JSON.stringify(state))}` + this.constructor.oAuthParams,
"popup", `width=${popup.width},height=${popup.height},left=${popup.left},top=${popup.top}`);

if (!this.authPopup) {
Expand Down

0 comments on commit 1b2f5f8

Please sign in to comment.