aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Wilkins <35748010+samwilkins333@users.noreply.github.com>2019-10-09 05:38:16 -0400
committerSam Wilkins <35748010+samwilkins333@users.noreply.github.com>2019-10-09 05:38:16 -0400
commit0d1d884ae24c74cc92b3be7a429873bde3d4370c (patch)
treecc119ceeca28ffb05d7f73d3a6e02da68adddd4e
parent11892eadbbafcbfb64966bc7a3975d5260b9399f (diff)
clean up and extensibility for authentication manager
-rw-r--r--src/client/apis/AuthenticationManager.tsx42
-rw-r--r--src/client/apis/google_docs/GooglePhotosClientUtils.ts8
2 files changed, 26 insertions, 24 deletions
diff --git a/src/client/apis/AuthenticationManager.tsx b/src/client/apis/AuthenticationManager.tsx
index 75a50d8f9..7d8d4f534 100644
--- a/src/client/apis/AuthenticationManager.tsx
+++ b/src/client/apis/AuthenticationManager.tsx
@@ -6,6 +6,8 @@ import { Opt } from "../../new_fields/Doc";
import { Identified } from "../Network";
import { RouteStore } from "../../server/RouteStore";
+const AuthenticationUrl = "https://accounts.google.com/o/oauth2/v2/auth";
+
@observer
export default class AuthenticationManager extends React.Component<{}> {
public static Instance: AuthenticationManager;
@@ -30,24 +32,30 @@ export default class AuthenticationManager extends React.Component<{}> {
runInAction(() => this.clickedState = value);
}
- public executeFullRoutine = async (authenticationLink: string) => {
- this.authenticationLink = authenticationLink;
- this.isOpen = true;
- return new Promise<string>(async resolve => {
- const disposer = reaction(
- () => this.authenticationCode,
- authenticationCode => {
- if (authenticationCode) {
- Identified.PostToServer(RouteStore.writeGooglePhotosAccessToken, { authenticationCode }).then(token => {
- this.isOpen = false;
- this.hasBeenClicked = false;
- resolve(token);
- disposer();
- });
+ 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: {}) {
diff --git a/src/client/apis/google_docs/GooglePhotosClientUtils.ts b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
index dd1492f51..8e88040db 100644
--- a/src/client/apis/google_docs/GooglePhotosClientUtils.ts
+++ b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
@@ -19,14 +19,8 @@ import { List } from "../../../new_fields/List";
export namespace GooglePhotos {
- const AuthenticationUrl = "https://accounts.google.com/o/oauth2/v2/auth";
-
const endpoint = async () => {
- let response = await Identified.FetchFromServer(RouteStore.readGooglePhotosAccessToken);
- if (new RegExp(AuthenticationUrl).test(response)) {
- response = await AuthenticationManager.Instance.executeFullRoutine(response);
- }
- return new Photos(response);
+ return new Photos(await AuthenticationManager.Instance.executeFullRoutine("GooglePhotos"));
};
export enum MediaType {