aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/apis/AuthenticationManager.tsx90
-rw-r--r--src/client/apis/GoogleAuthenticationManager.scss3
-rw-r--r--src/client/apis/GoogleAuthenticationManager.tsx114
-rw-r--r--src/client/apis/google_docs/GooglePhotosClientUtils.ts7
-rw-r--r--src/client/util/SharingManager.tsx2
-rw-r--r--src/client/views/MainView.tsx4
-rw-r--r--src/server/RouteStore.ts4
-rw-r--r--src/server/index.ts4
8 files changed, 126 insertions, 102 deletions
diff --git a/src/client/apis/AuthenticationManager.tsx b/src/client/apis/AuthenticationManager.tsx
deleted file mode 100644
index d8f6b675b..000000000
--- a/src/client/apis/AuthenticationManager.tsx
+++ /dev/null
@@ -1,90 +0,0 @@
-import { observable, action, reaction, runInAction } from "mobx";
-import { observer } from "mobx-react";
-import * as React from "react";
-import MainViewModal from "../views/MainViewModal";
-import { Opt } from "../../new_fields/Doc";
-import { Identified } from "../Network";
-
-const AuthenticationUrl = "https://accounts.google.com/o/oauth2/v2/auth";
-const prompt = "Please paste the external authetication code here...";
-
-@observer
-export default class AuthenticationManager extends React.Component<{}> {
- public static Instance: AuthenticationManager;
- @observable private openState = false;
- private authenticationLink: Opt<string> = undefined;
- @observable private authenticationCode: Opt<string> = undefined;
- @observable private clickedState = false;
-
- private set isOpen(value: boolean) {
- runInAction(() => this.openState = value);
- }
-
- private set hasBeenClicked(value: boolean) {
- runInAction(() => this.clickedState = value);
- }
-
- public executeFullRoutine = async (service: string) => {
- let response = await Identified.FetchFromServer(`/read${service}AccessToken`);
- // if this is an authentication url, activate the UI to register the new access token
- if (new RegExp(AuthenticationUrl).test(response)) {
- this.isOpen = true;
- this.authenticationLink = response;
- return new Promise<string>(async resolve => {
- const disposer = reaction(
- () => this.authenticationCode,
- authenticationCode => {
- if (authenticationCode) {
- Identified.PostToServer(`/write${service}AccessToken`, { authenticationCode }).then(token => {
- this.isOpen = false;
- this.hasBeenClicked = false;
- resolve(token);
- disposer();
- });
- }
- }
- );
- });
- }
- // otherwise, we already have a valid, stored access token
- return response;
- }
-
- constructor(props: {}) {
- super(props);
- AuthenticationManager.Instance = this;
- }
-
- private handleClick = () => {
- window.open(this.authenticationLink);
- this.hasBeenClicked = true;
- }
-
- private handlePaste = action((e: React.ChangeEvent<HTMLInputElement>) => {
- this.authenticationCode = e.currentTarget.value;
- });
-
- private get renderPrompt() {
- return (
- <div style={{ display: "flex", flexDirection: "column" }}>
- <button onClick={this.handleClick}>Please click here to authorize a Google account...</button>
- {this.clickedState ? <input
- onChange={this.handlePaste}
- placeholder={prompt}
- style={{ marginTop: 15 }}
- /> : (null)}
- </div>
- );
- }
-
- render() {
- return (
- <MainViewModal
- isDisplayed={this.openState}
- interactive={true}
- contents={this.renderPrompt}
- />
- );
- }
-
-} \ No newline at end of file
diff --git a/src/client/apis/GoogleAuthenticationManager.scss b/src/client/apis/GoogleAuthenticationManager.scss
new file mode 100644
index 000000000..5efb3ab3b
--- /dev/null
+++ b/src/client/apis/GoogleAuthenticationManager.scss
@@ -0,0 +1,3 @@
+.paste-target {
+ padding: 5px;
+} \ No newline at end of file
diff --git a/src/client/apis/GoogleAuthenticationManager.tsx b/src/client/apis/GoogleAuthenticationManager.tsx
new file mode 100644
index 000000000..8e8bf8def
--- /dev/null
+++ b/src/client/apis/GoogleAuthenticationManager.tsx
@@ -0,0 +1,114 @@
+import { observable, action, reaction, runInAction } from "mobx";
+import { observer } from "mobx-react";
+import * as React from "react";
+import MainViewModal from "../views/MainViewModal";
+import { Opt } from "../../new_fields/Doc";
+import { Identified } from "../Network";
+import { RouteStore } from "../../server/RouteStore";
+import "./GoogleAuthenticationManager.scss";
+
+const AuthenticationUrl = "https://accounts.google.com/o/oauth2/v2/auth";
+const prompt = "Paste authorization code here...";
+
+@observer
+export default class GoogleAuthenticationManager extends React.Component<{}> {
+ public static Instance: GoogleAuthenticationManager;
+ @observable private openState = false;
+ private authenticationLink: Opt<string> = undefined;
+ @observable private authenticationCode: Opt<string> = undefined;
+ @observable private clickedState = false;
+ @observable private success: Opt<boolean> = undefined;
+ @observable private displayLauncher = true;
+
+ private set isOpen(value: boolean) {
+ runInAction(() => this.openState = value);
+ }
+
+ private set hasBeenClicked(value: boolean) {
+ runInAction(() => this.clickedState = value);
+ }
+
+ public fetchOrGenerateAccessToken = async () => {
+ let response = await Identified.FetchFromServer(RouteStore.readGoogleAccessToken);
+ // if this is an authentication url, activate the UI to register the new access token
+ if (new RegExp(AuthenticationUrl).test(response)) {
+ this.isOpen = true;
+ this.authenticationLink = response;
+ return new Promise<string>(async resolve => {
+ const disposer = reaction(
+ () => this.authenticationCode,
+ authenticationCode => {
+ if (authenticationCode) {
+ Identified.PostToServer(RouteStore.writeGoogleAccessToken, { authenticationCode }).then(
+ token => {
+ runInAction(() => this.success = true);
+ setTimeout(() => {
+ this.isOpen = false;
+ runInAction(() => this.displayLauncher = false);
+ setTimeout(() => {
+ runInAction(() => this.success = undefined);
+ runInAction(() => this.displayLauncher = true);
+ this.hasBeenClicked = false;
+ }, 500);
+ }, 1000);
+ disposer();
+ resolve(token);
+ },
+ () => {
+ this.hasBeenClicked = false;
+ runInAction(() => this.success = false);
+ }
+ );
+ }
+ }
+ );
+ });
+ }
+ // otherwise, we already have a valid, stored access token
+ return response;
+ }
+
+ constructor(props: {}) {
+ super(props);
+ GoogleAuthenticationManager.Instance = this;
+ }
+
+ private handleClick = () => {
+ window.open(this.authenticationLink);
+ setTimeout(() => this.hasBeenClicked = true, 500);
+ }
+
+ private handlePaste = action((e: React.ChangeEvent<HTMLInputElement>) => {
+ this.authenticationCode = e.currentTarget.value;
+ });
+
+ private get renderPrompt() {
+ return (
+ <div style={{ display: "flex", flexDirection: "column" }}>
+ {this.displayLauncher ? <button
+ className={"dispatch"}
+ onClick={this.handleClick}
+ style={{ marginBottom: 15 }}
+ >Authorize a Google account...</button> : (null)}
+ {this.clickedState ? <input
+ className={'paste-target'}
+ onChange={this.handlePaste}
+ placeholder={prompt}
+ /> : (null)}
+ </div>
+ );
+ }
+
+ render() {
+ return (
+ <MainViewModal
+ isDisplayed={this.openState}
+ interactive={true}
+ contents={this.renderPrompt}
+ overlayDisplayedOpacity={0.9}
+ dialogueBoxStyle={{ borderColor: this.success === undefined ? "black" : this.success ? "green" : "red" }}
+ />
+ );
+ }
+
+} \ No newline at end of file
diff --git a/src/client/apis/google_docs/GooglePhotosClientUtils.ts b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
index 8e88040db..e93fa6eb4 100644
--- a/src/client/apis/google_docs/GooglePhotosClientUtils.ts
+++ b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
@@ -14,14 +14,11 @@ import { NewMediaItemResult, MediaItem } from "../../../server/apis/google/Share
import { AssertionError } from "assert";
import { DocumentView } from "../../views/nodes/DocumentView";
import { Identified } from "../../Network";
-import AuthenticationManager from "../AuthenticationManager";
-import { List } from "../../../new_fields/List";
+import GoogleAuthenticationManager from "../GoogleAuthenticationManager";
export namespace GooglePhotos {
- const endpoint = async () => {
- return new Photos(await AuthenticationManager.Instance.executeFullRoutine("GooglePhotos"));
- };
+ const endpoint = async () => new Photos(await GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken());
export enum MediaType {
ALL_MEDIA = 'ALL_MEDIA',
diff --git a/src/client/util/SharingManager.tsx b/src/client/util/SharingManager.tsx
index 91c8c572d..1541cd6b2 100644
--- a/src/client/util/SharingManager.tsx
+++ b/src/client/util/SharingManager.tsx
@@ -218,7 +218,7 @@ export default class SharingManager extends React.Component<{}> {
if (!metadata) {
return SharingPermissions.None;
}
- return StrCast(metadata.permissions, SharingPermissions.None)!;
+ return StrCast(metadata.permissions, SharingPermissions.None);
}
private get sharingInterface() {
diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx
index 12578e5b8..ba4224875 100644
--- a/src/client/views/MainView.tsx
+++ b/src/client/views/MainView.tsx
@@ -39,7 +39,7 @@ import PDFMenu from './pdf/PDFMenu';
import { PreviewCursor } from './PreviewCursor';
import { FilterBox } from './search/FilterBox';
import { OverlayView } from './OverlayView';
-import AuthenticationManager from '../apis/AuthenticationManager';
+import GoogleAuthenticationManager from '../apis/GoogleAuthenticationManager';
@observer
export class MainView extends React.Component {
@@ -678,7 +678,7 @@ export class MainView extends React.Component {
<div id="main-div">
{this.dictationOverlay}
<SharingManager />
- <AuthenticationManager />
+ <GoogleAuthenticationManager />
<DocumentDecorations />
{this.mainContent}
<PreviewCursor />
diff --git a/src/server/RouteStore.ts b/src/server/RouteStore.ts
index b2a1af8d3..7426ffb39 100644
--- a/src/server/RouteStore.ts
+++ b/src/server/RouteStore.ts
@@ -34,8 +34,8 @@ export enum RouteStore {
// APIS
cognitiveServices = "/cognitiveservices",
googleDocs = "/googleDocs",
- readGooglePhotosAccessToken = "/readGooglePhotosAccessToken",
- writeGooglePhotosAccessToken = "/writeGooglePhotosAccessToken",
+ readGoogleAccessToken = "/readGoogleAccessToken",
+ writeGoogleAccessToken = "/writeGoogleAccessToken",
googlePhotosMediaUpload = "/googlePhotosMediaUpload",
googlePhotosMediaDownload = "/googlePhotosMediaDownload",
googleDocsGet = "/googleDocsGet"
diff --git a/src/server/index.ts b/src/server/index.ts
index 30513ef36..62938b9c7 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -946,7 +946,7 @@ app.post(RouteStore.googleDocs + "/:sector/:action", (req, res) => {
});
});
-app.get(RouteStore.readGooglePhotosAccessToken, async (req, res) => {
+app.get(RouteStore.readGoogleAccessToken, async (req, res) => {
const userId = req.header("userId")!;
const token = await Database.Auxiliary.GoogleAuthenticationToken.Fetch(userId);
const information = { credentialsPath, userId };
@@ -956,7 +956,7 @@ app.get(RouteStore.readGooglePhotosAccessToken, async (req, res) => {
GoogleApiServerUtils.RetrieveAccessToken(information).then(token => res.send(token));
});
-app.post(RouteStore.writeGooglePhotosAccessToken, async (req, res) => {
+app.post(RouteStore.writeGoogleAccessToken, async (req, res) => {
const userId = req.header("userId")!;
const information = { credentialsPath, userId };
const { token } = await GoogleApiServerUtils.ProcessClientSideCode(information, req.body.authenticationCode);