diff --git a/lib/actions/google/drive/google_drive.d.ts b/lib/actions/google/drive/google_drive.d.ts index 7ca820f2..1c516ec6 100644 --- a/lib/actions/google/drive/google_drive.d.ts +++ b/lib/actions/google/drive/google_drive.d.ts @@ -26,7 +26,10 @@ export declare class GoogleDriveAction extends Hub.OAuthActionV2 { oauthHandleRedirect(urlParams: { [key: string]: string; }, redirectUri: string): Promise; - oauthFetchAccessToken(request: Hub.ActionRequest): Promise; + oauthFetchAccessToken(request: Hub.ActionRequest): Promise<{ + tokens: Credentials; + redirect: any; + }>; oauthCheck(request: Hub.ActionRequest): Promise; oauth2Client(redirectUri: string | undefined): OAuth2Client; sendData(filename: string, request: Hub.ActionRequest, drive: Drive): Promise>; diff --git a/lib/actions/google/drive/google_drive.js b/lib/actions/google/drive/google_drive.js index cf0a021c..b682f84c 100644 --- a/lib/actions/google/drive/google_drive.js +++ b/lib/actions/google/drive/google_drive.js @@ -260,7 +260,7 @@ class GoogleDriveAction extends Hub.OAuthActionV2 { }); const state = JSON.parse(plaintext); const tokens = await this.getAccessTokenCredentialsFromCode(state.redirecturi, state.code); - return JSON.stringify({ tokens, redirect: state.redirecturi }); + return { tokens, redirect: state.redirecturi }; } else { throw new Error("Request is missing state parameter."); diff --git a/lib/hub/oauth_action_v2.d.ts b/lib/hub/oauth_action_v2.d.ts index 3f649897..1b75023b 100644 --- a/lib/hub/oauth_action_v2.d.ts +++ b/lib/hub/oauth_action_v2.d.ts @@ -6,7 +6,7 @@ export declare abstract class OAuthActionV2 extends Action { abstract oauthHandleRedirect(urlParams: { [key: string]: string; }, redirectUri: string): Promise; - abstract oauthFetchAccessToken(request: ActionRequest): Promise; + abstract oauthFetchAccessToken(request: ActionRequest): Promise; asJson(router: RouteBuilder, request: ActionRequest): any; } export declare function isOauthActionV2(action: Action): boolean; diff --git a/lib/server/server.js b/lib/server/server.js index 220ee48c..1f55eb71 100644 --- a/lib/server/server.js +++ b/lib/server/server.js @@ -184,9 +184,9 @@ class Server { const request = Hub.ActionRequest.fromRequest(req); const action = await Hub.findAction(req.params.actionId, { lookerVersion: request.lookerVersion }); if ((0, hub_1.isOauthActionV2)(action)) { - const jsonPayload = await action.oauthFetchAccessToken(request); + const payload = await action.oauthFetchAccessToken(request); res.type("json"); - res.send(jsonPayload); + res.send(JSON.stringify(payload)); } else { res.statusCode = 404; diff --git a/src/actions/google/drive/google_drive.ts b/src/actions/google/drive/google_drive.ts index 385b6c86..75e7e0af 100644 --- a/src/actions/google/drive/google_drive.ts +++ b/src/actions/google/drive/google_drive.ts @@ -302,7 +302,7 @@ export class GoogleDriveAction extends Hub.OAuthActionV2 { const state = JSON.parse(plaintext) const tokens = await this.getAccessTokenCredentialsFromCode(state.redirecturi, state.code) - return JSON.stringify({tokens, redirect: state.redirecturi}) + return {tokens, redirect: state.redirecturi} } else { throw new Error("Request is missing state parameter.") } diff --git a/src/actions/google/drive/test_google_drive.ts b/src/actions/google/drive/test_google_drive.ts index fd6337ed..1f240c22 100644 --- a/src/actions/google/drive/test_google_drive.ts +++ b/src/actions/google/drive/test_google_drive.ts @@ -409,7 +409,7 @@ describe(`${action.constructor.name} unit tests`, () => { state: "eyJjb2RlIjoiY29kZSIsInJlZGlyZWN0dXJpIjoicmVkaXJlY3QifQ"} request.webhookId = "testId" const tokenPayload = action.oauthFetchAccessToken(request) - chai.expect(tokenPayload).to.eventually.equal(`{"tokens":{"tokens":"token"},"redirect":"redirect"}`) + chai.expect(tokenPayload).to.eventually.deep.equal({tokens: {tokens: "token"}, redirect: "redirect"}) .and.notify(stubAccessToken.restore) .and.notify(done) }) diff --git a/src/hub/oauth_action_v2.ts b/src/hub/oauth_action_v2.ts index a4d284f5..1d91058d 100644 --- a/src/hub/oauth_action_v2.ts +++ b/src/hub/oauth_action_v2.ts @@ -5,7 +5,7 @@ export abstract class OAuthActionV2 extends Action { abstract oauthCheck(request: ActionRequest): Promise abstract oauthUrl(redirectUri: string, encryptedState: string): Promise abstract oauthHandleRedirect(urlParams: { [key: string]: string }, redirectUri: string): Promise - abstract oauthFetchAccessToken(request: ActionRequest): Promise + abstract oauthFetchAccessToken(request: ActionRequest): Promise asJson(router: RouteBuilder, request: ActionRequest): any { const json = super.asJson(router, request) diff --git a/src/server/server.ts b/src/server/server.ts index 6294ffac..c9e9fd3f 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -202,9 +202,9 @@ export default class Server implements Hub.RouteBuilder { const action = await Hub.findAction(req.params.actionId, { lookerVersion: request.lookerVersion }) if (isOauthActionV2(action)) { - const jsonPayload = await (action as OAuthActionV2).oauthFetchAccessToken(request) + const payload = await (action as OAuthActionV2).oauthFetchAccessToken(request) res.type("json") - res.send(jsonPayload) + res.send(JSON.stringify(payload)) } else { res.statusCode = 404 }