这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/actions/google/drive/google_drive.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ class GoogleDriveAction extends Hub.OAuthActionV2 {
}
}
async oauthFetchAccessToken(request) {
if (request.params.state) {
if (request.fetchTokenState) {
const actionCrypto = new Hub.ActionCrypto();
const plaintext = await actionCrypto.decrypt(request.params.state).catch((err) => {
winston.error("Encryption not correctly configured" + err);
const plaintext = await actionCrypto.decrypt(request.fetchTokenState).catch((err) => {
winston.error("Encryption not correctly configured", { error: err });
throw err;
});
const state = JSON.parse(plaintext);
Expand Down
2 changes: 2 additions & 0 deletions lib/api_types/data_webhook_payload.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface DataWebhookPayload {
form_params: {
[key: string]: string;
} | null;
/** Encrypted data used by /actions/:actionId/oauth_token route */
state: string | null;
}
export interface RequestDataWebhookPayload {
}
1 change: 1 addition & 0 deletions lib/hub/action_request.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export declare class ActionRequest {
formParams: ParamMap;
params: ParamMap;
scheduledPlan?: ActionScheduledPlan;
fetchTokenState?: string;
type: ActionType;
actionId?: string;
instanceId?: string;
Expand Down
3 changes: 3 additions & 0 deletions lib/hub/action_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class ActionRequest {
if (json.form_params) {
request.formParams = json.form_params;
}
if (json.state) {
request.fetchTokenState = json.state;
}
return request;
}
empty() {
Expand Down
1 change: 1 addition & 0 deletions lib/hub/action_token.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export declare class ActionToken {
tokens: any;
redirect: any;
constructor(tokens: any, redirect: any);
asJson(): any;
}
6 changes: 6 additions & 0 deletions lib/hub/action_token.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ class ActionToken {
this.tokens = tokens;
this.redirect = redirect;
}
asJson() {
return {
tokens: this.tokens,
redirect: this.redirect,
};
}
}
exports.ActionToken = ActionToken;
2 changes: 1 addition & 1 deletion lib/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class Server {
if ((0, hub_1.isOauthActionV2)(action)) {
const payload = await action.oauthFetchAccessToken(request);
res.type("json");
res.send(JSON.stringify(payload));
res.send(JSON.stringify(payload.asJson()));
}
else {
res.statusCode = 404;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "looker-action-hub",
"version": "1.5.26",
"version": "1.5.27",
"description": "",
"main": "lib/index",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/actions/google/drive/google_drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ export class GoogleDriveAction extends Hub.OAuthActionV2 {
}

async oauthFetchAccessToken(request: Hub.ActionRequest) {
if (request.params.state) {
if (request.fetchTokenState) {
const actionCrypto = new Hub.ActionCrypto()
const plaintext = await actionCrypto.decrypt(request.params.state).catch((err: string) => {
winston.error("Encryption not correctly configured" + err)
const plaintext = await actionCrypto.decrypt(request.fetchTokenState).catch((err: string) => {
winston.error("Encryption not correctly configured", { error: err })
throw err
})
const state = JSON.parse(plaintext)
Expand Down
3 changes: 1 addition & 2 deletions src/actions/google/drive/test_google_drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,7 @@ describe(`${action.constructor.name} unit tests`, () => {
const stubAccessToken = sinon.stub(action as any, "getAccessTokenCredentialsFromCode")
.resolves({tokens: "token"})
const request = new Hub.ActionRequest()
request.params = {
state: "eyJjb2RlIjoiY29kZSIsInJlZGlyZWN0dXJpIjoicmVkaXJlY3QifQ"}
request.fetchTokenState = "eyJjb2RlIjoiY29kZSIsInJlZGlyZWN0dXJpIjoicmVkaXJlY3QifQ"
request.webhookId = "testId"
const tokenPayload = action.oauthFetchAccessToken(request)
chai.expect(tokenPayload).to.eventually.deep.equal({tokens: {tokens: "token"}, redirect: "redirect"})
Expand Down
2 changes: 2 additions & 0 deletions src/api_types/data_webhook_payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface DataWebhookPayload {
data: {[key: string]: string} | null
/** Form parameters associated with the payload. */
form_params: {[key: string]: string} | null
/** Encrypted data used by /actions/:actionId/oauth_token route */
state: string | null
}

export interface RequestDataWebhookPayload {
Expand Down
5 changes: 5 additions & 0 deletions src/hub/action_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,18 @@ export class ActionRequest {
request.formParams = json.form_params
}

if (json.state) {
request.fetchTokenState = json.state
}

return request
}

attachment?: ActionAttachment
formParams: ParamMap = {}
params: ParamMap = {}
scheduledPlan?: ActionScheduledPlan
fetchTokenState?: string
type!: ActionType
actionId?: string
instanceId?: string
Expand Down
7 changes: 7 additions & 0 deletions src/hub/action_token.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
export class ActionToken {
constructor(public tokens: any, public redirect: any) {}

asJson(): any {
return {
tokens: this.tokens,
redirect: this.redirect,
}
}
}
2 changes: 1 addition & 1 deletion src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export default class Server implements Hub.RouteBuilder {
if (isOauthActionV2(action)) {
const payload = await (action as OAuthActionV2).oauthFetchAccessToken(request)
res.type("json")
res.send(JSON.stringify(payload))
res.send(JSON.stringify(payload.asJson()))
} else {
res.statusCode = 404
}
Expand Down
19 changes: 19 additions & 0 deletions test/test_action_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ import {mockReq} from "sinon-express-mock"
import { ActionRequest } from "../src/hub"

describe("ActionRequest", () => {
it("fromRequest correctly parses state from body", () => {
const req = mockReq({
headers: {
"user-agent": "LookerOutgoingWebhook/7.3.0",
"x-looker-webhook-id": "123",
"x-looker-instance": "instanceId1",
},
body: {
state: "someEncryptedStateString",
},
})

// @ts-ignore
req.header = (name: string): string | string[] | undefined => req.headers[name]

const result = ActionRequest.fromRequest(req)
chai.expect(result.fetchTokenState).to.equal("someEncryptedStateString")
})

it("fromRequest", () => {

const req = mockReq({
Expand Down