From b1680c1b810e6f2c616566f3d660501533cee684 Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 14 Feb 2020 08:58:02 -0700 Subject: [PATCH 1/3] auth: update ports and apis used Signed-off-by: andrew --- src/ThreadsConfig.ts | 11 ++++++----- src/index.ts | 21 ++++++++++++--------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/ThreadsConfig.ts b/src/ThreadsConfig.ts index ad831659b..6e73a92f0 100644 --- a/src/ThreadsConfig.ts +++ b/src/ThreadsConfig.ts @@ -13,14 +13,15 @@ export class ThreadsConfig extends Config { public token: string, public deviceId: string, public dev: boolean, - public apiScheme: string = 'https', - public api: string = 'cloud.textile.io', - public sessionPort: number = 8006, + public scheme: string = 'https', + public authApi: string = 'cloud.textile.io', + public authPort: number = 8006, + public threadsApi: string = 'api.textile.io', public threadsPort: number = 6007, public transport: grpc.TransportFactory = grpc.WebsocketTransport(), ) { super() - this.host = `${this.apiScheme}://${this.api}:${this.threadsPort}` + this.host = `${this.scheme}://${this.threadsApi}:${this.threadsPort}` } async start(sessionId?: string) { if (sessionId !== undefined) { @@ -30,7 +31,7 @@ export class ThreadsConfig extends Config { await this.refreshSession() } get sessionAPI(): string { - return `${this.apiScheme}://${this.api}:${this.sessionPort}` + return `${this.scheme}://${this.threadsApi}:${this.authPort}` } private async refreshSession() { if (this.dev) { diff --git a/src/index.ts b/src/index.ts index cd92e96b6..d85537771 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,9 +8,10 @@ export type APIConfig = { token: string deviceId: string dev?: boolean - apiScheme?: string - api?: string - sessionPort?: number + scheme?: string + authApi?: string + authPort?: number + threadsApi?: string threadsPort?: number } export class API { @@ -34,18 +35,20 @@ export class API { config.token, config.deviceId, true, - config.apiScheme !== (null || undefined) ? config.apiScheme : 'http', - config.api !== (null || undefined) ? config.api : '127.0.0.1', - config.sessionPort !== (null || undefined) ? config.sessionPort : 8006, + config.scheme !== (null || undefined) ? config.scheme : 'http', + config.authApi !== (null || undefined) ? config.authApi : '127.0.0.1', + config.authPort !== (null || undefined) ? config.authPort : 8006, + config.threadsApi !== (null || undefined) ? config.threadsApi : '127.0.0.1', config.threadsPort !== (null || undefined) ? config.threadsPort : 6007, ) : new ThreadsConfig( config.token, config.deviceId, false, - config.apiScheme !== (null || undefined) ? config.apiScheme : 'https', - config.api !== (null || undefined) ? config.api : 'cloud.textile.io', - config.sessionPort !== (null || undefined) ? config.sessionPort : 8006, + config.scheme !== (null || undefined) ? config.scheme : 'https', + config.authApi !== (null || undefined) ? config.authApi : 'cloud.textile.io', + config.authPort !== (null || undefined) ? config.authPort : 8006, + config.threadsApi !== (null || undefined) ? config.threadsApi : 'api.textile.io', config.threadsPort !== (null || undefined) ? config.threadsPort : 6007, ) } From b126b140016305e2e5eb37fb4f59d2425ecc7e7b Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 14 Feb 2020 09:00:10 -0700 Subject: [PATCH 2/3] readme: update app token > project token Signed-off-by: andrew --- README.md | 8 ++++---- examples/browser/localThreadsDaemon.html | 2 +- src/index.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7ba4253d0..4f918cb97 100644 --- a/README.md +++ b/README.md @@ -26,18 +26,18 @@ Join us on our [public Slack channel](https://slack.textile.io/) for news, discu ## Usage -`js-textile` provides access to Textile APIs in apps based on an App Token. For details on getting an app token, see [textileio/textile](https://github.com/textileio/textile) or join the [Textile Slack](https://slack.textile.io). +`js-textile` provides access to Textile APIs in apps based on a Project Token. For details on getting an app token, see [textileio/textile](https://github.com/textileio/textile) or join the [Textile Slack](https://slack.textile.io). ### Threads APIs Textile provides remote threads APIs your app can use. -- token: an app token from your textile project +- token: a project token from your textile project - deviceId: a unique ID (uuid) for this user in your app ```js let api = new textile.API({ - token: '', + token: '', deviceId: '' }) @@ -51,7 +51,7 @@ Requires you run the Threads daemon (`threadsd`) on localhost. See [instructions ```js let api = new textile.API({ - token: '', + token: '', deviceId: '', dev: true }) diff --git a/examples/browser/localThreadsDaemon.html b/examples/browser/localThreadsDaemon.html index 9a0a32841..c1f847479 100644 --- a/examples/browser/localThreadsDaemon.html +++ b/examples/browser/localThreadsDaemon.html @@ -45,7 +45,7 @@ (async function () { window.api = new textile.API({ - token: '', + token: '', deviceId: '', dev: true }) diff --git a/src/index.ts b/src/index.ts index d85537771..ddab8eb0d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,7 +37,7 @@ export class API { true, config.scheme !== (null || undefined) ? config.scheme : 'http', config.authApi !== (null || undefined) ? config.authApi : '127.0.0.1', - config.authPort !== (null || undefined) ? config.authPort : 8006, + config.authPort !== (null || undefined) ? config.authPort : 443, config.threadsApi !== (null || undefined) ? config.threadsApi : '127.0.0.1', config.threadsPort !== (null || undefined) ? config.threadsPort : 6007, ) @@ -47,7 +47,7 @@ export class API { false, config.scheme !== (null || undefined) ? config.scheme : 'https', config.authApi !== (null || undefined) ? config.authApi : 'cloud.textile.io', - config.authPort !== (null || undefined) ? config.authPort : 8006, + config.authPort !== (null || undefined) ? config.authPort : 443, config.threadsApi !== (null || undefined) ? config.threadsApi : 'api.textile.io', config.threadsPort !== (null || undefined) ? config.threadsPort : 6007, ) From 399e52fabc1c8feb496a4372471229c2305a534a Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 14 Feb 2020 09:02:06 -0700 Subject: [PATCH 3/3] auth: fix default on localhost Signed-off-by: andrew --- src/ThreadsConfig.ts | 2 +- src/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ThreadsConfig.ts b/src/ThreadsConfig.ts index 6e73a92f0..8a467d18c 100644 --- a/src/ThreadsConfig.ts +++ b/src/ThreadsConfig.ts @@ -15,7 +15,7 @@ export class ThreadsConfig extends Config { public dev: boolean, public scheme: string = 'https', public authApi: string = 'cloud.textile.io', - public authPort: number = 8006, + public authPort: number = 443, public threadsApi: string = 'api.textile.io', public threadsPort: number = 6007, public transport: grpc.TransportFactory = grpc.WebsocketTransport(), diff --git a/src/index.ts b/src/index.ts index ddab8eb0d..901fed177 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,7 +37,7 @@ export class API { true, config.scheme !== (null || undefined) ? config.scheme : 'http', config.authApi !== (null || undefined) ? config.authApi : '127.0.0.1', - config.authPort !== (null || undefined) ? config.authPort : 443, + config.authPort !== (null || undefined) ? config.authPort : 8006, config.threadsApi !== (null || undefined) ? config.threadsApi : '127.0.0.1', config.threadsPort !== (null || undefined) ? config.threadsPort : 6007, )