diff --git a/.gitignore b/.gitignore index c7b5ece..380f3ba 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,5 @@ Thumbs.db* ~* platform -provider *.js *.d.ts \ No newline at end of file diff --git a/src/provider.ts b/src/provider.ts index 5b7f556..d369f51 100644 --- a/src/provider.ts +++ b/src/provider.ts @@ -9,10 +9,11 @@ export interface IOAuthOptions { redirectUri?: string; responseType?: string; state?: string; + excludeRedirectUri?: boolean } const DEFAULTS = { - redirectUri: 'http://localhost/callback' + redirectUri: 'http://localhost/callback' }; export class OAuthProvider implements IOauthProvider { @@ -30,25 +31,29 @@ export class OAuthProvider implements IOauthProvider { } parseResponseInUrl(url) { - const response = utils.parseQueryString(url); + const response = utils.parseQueryString(url); - if (!this.isValid(response)) { - const error = new Error(`Problem authenticating with ${this.name}`); + if (!this.isValid(response)) { + const error = new Error(`Problem authenticating with ${this.name}`); - Object.defineProperty(error, 'response', { value: response }); - throw error; - } + Object.defineProperty(error, 'response', { value: response }); + throw error; + } - return response; + return response; } dialogUrl() { - return this.optionsToDialogUrl(this.options); + return this.optionsToDialogUrl(this.options); } protected optionsToDialogUrl(options: any): string { utils.defaults(options, this.defaults) - let url = `${this.authUrl}?client_id=${options.clientId}&redirect_uri=${options.redirectUri}`; + let url = `${this.authUrl}?client_id=${options.clientId}`; + + if (!options.excludeRedirectUri) { + url += "&redirect_uri=" + options.redirectUri; + } if (options.appScope) { url += `&scope=${this.serializeAppScope(options.appScope)}`; @@ -66,7 +71,7 @@ export class OAuthProvider implements IOauthProvider { } protected serializeAppScope(scope) { - return typeof scope.join === 'function' ? scope.join(this.APP_SCOPE_DELIMITER) : scope; + return typeof scope.join === 'function' ? scope.join(this.APP_SCOPE_DELIMITER) : scope; } protected isValid(response) { diff --git a/src/provider/fitbit.ts b/src/provider/fitbit.ts new file mode 100644 index 0000000..11c939c --- /dev/null +++ b/src/provider/fitbit.ts @@ -0,0 +1,12 @@ +import { OAuthProvider, IOAuthOptions } from "../provider"; + +export class Fitbit extends OAuthProvider { + + constructor(options?: IOAuthOptions) { + super(options); + this.authUrl = 'https://www.fitbit.com/oauth2/authorize'; + this.defaults = { + responseType: 'code' + }; + } +} diff --git a/src/provider/polar.ts b/src/provider/polar.ts new file mode 100644 index 0000000..3e2fc93 --- /dev/null +++ b/src/provider/polar.ts @@ -0,0 +1,13 @@ +import { OAuthProvider, IOAuthOptions } from "../provider"; + +export class Polar extends OAuthProvider { + + constructor(options?: IOAuthOptions) { + super(options); + this.authUrl = 'https://flow.polar.com/oauth2/authorization'; + this.defaults = { + responseType: 'code', + excludeRedirectUri: true + }; + } +} diff --git a/src/provider/runkeeper.ts b/src/provider/runkeeper.ts new file mode 100644 index 0000000..bc20ba1 --- /dev/null +++ b/src/provider/runkeeper.ts @@ -0,0 +1,12 @@ +import { OAuthProvider, IOAuthOptions } from "../provider"; + +export class Runkeeper extends OAuthProvider { + + constructor(options?: IOAuthOptions) { + super(options); + this.authUrl = 'https://runkeeper.com/apps/authorize'; + this.defaults = { + responseType: 'code' + }; + } +}