Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added providers #70

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ Thumbs.db*
~*

platform
provider
*.js
*.d.ts
27 changes: 16 additions & 11 deletions src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)}`;
Expand All @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions src/provider/fitbit.ts
Original file line number Diff line number Diff line change
@@ -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'
};
}
}
13 changes: 13 additions & 0 deletions src/provider/polar.ts
Original file line number Diff line number Diff line change
@@ -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
};
}
}
12 changes: 12 additions & 0 deletions src/provider/runkeeper.ts
Original file line number Diff line number Diff line change
@@ -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'
};
}
}