Skip to content

Commit e504e1a

Browse files
committed
Wip
1 parent c564bb1 commit e504e1a

File tree

3 files changed

+32
-87
lines changed

3 files changed

+32
-87
lines changed

integrations/va-auth0/gitbook-manifest.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ script: ./src/index.tsx
1111
scopes:
1212
- space:metadata:read
1313
- space:visitor:auth
14+
- space:content:read
1415
organization: w45sBUBc1JWE1ktYkQfI
1516
summary: |
1617
# Overview

integrations/va-auth0/src/index.tsx

+9-65
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import { sign } from '@tsndr/cloudflare-worker-jwt';
22
import { Router } from 'itty-router';
33

4-
// import * as jwt from 'jsonwebtoken';
54
import { IntegrationInstallationConfiguration } from '@gitbook/api';
65
import {
76
createIntegration,
87
FetchEventCallback,
98
Logger,
109
RuntimeContext,
1110
RuntimeEnvironment,
12-
EventCallback,
1311
createComponent,
1412
} from '@gitbook/runtime';
1513

16-
// import type { GithubRuntimeContext } from '../../github/src/types';
17-
1814
const logger = Logger('auth0.visitor-auth');
1915

2016
type Auth0RuntimeEnvironment = RuntimeEnvironment<
@@ -58,8 +54,6 @@ const helloWorldBlock = createComponent<Auth0Props, Auth0State, Auth0Action, Aut
5854
action: async (element, action, context) => {
5955
switch (action.action) {
6056
case 'save.config':
61-
// eslint-disable-next-line no-console
62-
console.log('action save.config element.state.client_id', element.state.client_id);
6357
const { api, environment } = context;
6458
const spaceInstallation = environment.spaceInstallation;
6559

@@ -69,7 +63,8 @@ const helloWorldBlock = createComponent<Auth0Props, Auth0State, Auth0Action, Aut
6963
client_secret: element.state.client_secret,
7064
issuer_base_url: element.state.issuer_base_url,
7165
};
72-
66+
// eslint-disable-next-line no-console
67+
console.log('env.auth_token', environment.authToken);
7368
const res = await api.integrations.updateIntegrationSpaceInstallation(
7469
spaceInstallation.integration,
7570
spaceInstallation.installation,
@@ -80,8 +75,6 @@ const helloWorldBlock = createComponent<Auth0Props, Auth0State, Auth0Action, Aut
8075
},
8176
}
8277
);
83-
// eslint-disable-next-line no-console
84-
console.log('res', res);
8578
return element;
8679
}
8780
},
@@ -99,13 +92,10 @@ const helloWorldBlock = createComponent<Auth0Props, Auth0State, Auth0Action, Aut
9992
<button
10093
style="primary"
10194
disabled={false}
102-
label="Vibby"
103-
tooltip="Save configuration Vib"
95+
label="Vib"
96+
tooltip="Save configuration"
10497
onPress={{
10598
action: 'save.config',
106-
// client_id: element.dynamicState('client_id'),
107-
// client_secret: element.dynamicState('client_secret'),
108-
// issuer_base_url: element.dynamicState('issuer_base_url'),
10999
}}
110100
/>
111101
}
@@ -154,12 +144,16 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
154144
context.environment.spaceInstallation?.space
155145
);
156146
const obj = space.data;
147+
// eslint-disable-next-line no-console
148+
console.log('obj', obj);
157149
const privateKey = context.environment.spaceInstallation.configuration.private_key;
150+
const envPK = context.environment.signingSecret;
151+
console.log('privateKey envPK', envPK);
158152
let token;
159153
try {
160154
token = await sign(
161155
{ exp: Math.floor(Date.now() / 1000) + 2 * (60 * 60) },
162-
privateKey ? privateKey : ''
156+
envPK ? envPK : ''
163157
);
164158
} catch (e) {
165159
return Response.json({ error: e.stack });
@@ -230,53 +224,6 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
230224
}
231225
};
232226

233-
// const handleFetchVisitorAuth: EventCallback<
234-
// 'fetch_visitor_authentication',
235-
// Auth0RuntimeContext
236-
// > = async (event, context) => {
237-
// const { data: revision } = await context.api.spaces.getRevisionById(
238-
// event.spaceId,
239-
// event.revisionId
240-
// );
241-
// if (revision.git?.oid) {
242-
// const revisionStatus = revision.git.createdByGitBook ? 'exported' : 'imported';
243-
// logger.info(
244-
// `skipping Git Sync for space ${event.spaceId} revision ${revision.id} as it was already ${revisionStatus}`
245-
// );
246-
// return;
247-
// }
248-
249-
// const spaceInstallation = context.environment.spaceInstallation;
250-
// if (!spaceInstallation) {
251-
// logger.debug(`missing space installation, skipping`);
252-
// return;
253-
// }
254-
255-
// // await triggerExport(context, spaceInstallation);
256-
// };
257-
// const handleGitSyncCompleted: EventCallback<
258-
// 'space_gitsync_completed',
259-
// GithubRuntimeContext
260-
// > = async (event, context) => {
261-
// logger.info(
262-
// `Git Sync completed (${event.state}) for space ${event.spaceId} revision ${event.revisionId}, updating commit status`
263-
// );
264-
265-
// const spaceInstallation = context.environment.spaceInstallation;
266-
// if (!spaceInstallation) {
267-
// logger.debug(`missing space installation, skipping`);
268-
// return;
269-
// }
270-
271-
// await updateCommitWithPreviewLinks(
272-
// context,
273-
// spaceInstallation,
274-
// event.revisionId,
275-
// event.commitId,
276-
// event.state as GitSyncOperationState
277-
// );
278-
// };
279-
280227
export default createIntegration({
281228
fetch: handleFetchEvent,
282229
components: [helloWorldBlock],
@@ -294,12 +241,9 @@ export default createIntegration({
294241
} catch (e) {
295242
return Response.json({ error: e.stack });
296243
}
297-
298-
// await triggerExport(context, spaceInstallation);
299244
},
300245
events: {
301246
space_installation_setup: async (event, context) => {
302-
// check event status to be active
303247
if (!context.environment.spaceInstallation?.configuration.private_key) {
304248
const res = await context.api.integrations.updateIntegrationSpaceInstallation(
305249
context.environment.integration.name,

integrations/va-azure/src/index.tsx

+22-22
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const helloWorldBlock = createComponent<AzureProps, AzureState, Auth0Action, Azu
5454
switch (action.action) {
5555
case 'save.config':
5656
// eslint-disable-next-line no-console
57-
console.log('action save.config element.state.client_id', element.state.client_id);
57+
console.log('save.config');
5858
const { api, environment } = context;
5959
const spaceInstallation = environment.spaceInstallation;
6060

@@ -64,28 +64,30 @@ const helloWorldBlock = createComponent<AzureProps, AzureState, Auth0Action, Azu
6464
client_secret: element.state.client_secret,
6565
tenant_id: element.state.tenant_id,
6666
};
67-
68-
const res = await api.integrations.updateIntegrationSpaceInstallation(
69-
spaceInstallation.integration,
70-
spaceInstallation.installation,
71-
spaceInstallation.space,
72-
{
73-
configuration: {
74-
...configurationBody,
75-
},
76-
}
77-
);
78-
// eslint-disable-next-line no-console
79-
console.log('res', res);
67+
try {
68+
const res = await api.integrations.updateIntegrationSpaceInstallation(
69+
spaceInstallation.integration,
70+
spaceInstallation.installation,
71+
spaceInstallation.space,
72+
{
73+
configuration: {
74+
...configurationBody,
75+
},
76+
}
77+
);
78+
} catch (error) {
79+
// eslint-disable-next-line no-console
80+
console.log('error', error);
81+
}
8082
return element;
8183
}
8284
},
8385
render: async (element, context) => {
8486
const VACallbackURL = `${context.environment.spaceInstallation?.urls?.publicEndpoint}/visitor-auth/response`;
8587
return (
8688
<block>
87-
<textinput state="client_id" placeholder="Enter Client Id" />
88-
<textinput state="tenant_id" placeholder="Enter Issuer Base URL" />
89+
<textinput state="client_id" placeholder="Enter Client ID" />
90+
<textinput state="tenant_id" placeholder="Enter Tenant ID" />
8991
<textinput state="client_secret" placeholder="Enter Client Secret" />
9092
<input
9193
label=""
@@ -94,13 +96,10 @@ const helloWorldBlock = createComponent<AzureProps, AzureState, Auth0Action, Azu
9496
<button
9597
style="primary"
9698
disabled={false}
97-
label="Vibby"
98-
tooltip="Save configuration Vib"
99+
label="Save"
100+
tooltip="Save configuration"
99101
onPress={{
100102
action: 'save.config',
101-
// client_id: element.dynamicState('client_id'),
102-
// client_secret: element.dynamicState('client_secret'),
103-
// tenant_id: element.dynamicState('tenant_id'),
104103
}}
105104
/>
106105
}
@@ -113,7 +112,7 @@ const helloWorldBlock = createComponent<AzureProps, AzureState, Auth0Action, Azu
113112
</hint>
114113
) : null}
115114
<divider size="medium" />
116-
<text>Enter the following URL as an allowed callback URL in Auth0:</text>
115+
<text>Enter the following URL as an allowed callback URL in Azure:</text>
117116
<text>{VACallbackURL}</text>
118117
</block>
119118
);
@@ -150,6 +149,7 @@ const handleFetchEvent: FetchEventCallback<AzureRuntimeContext> = async (request
150149
);
151150
const obj = space.data;
152151
const privateKey = context.environment.spaceInstallation.configuration.private_key;
152+
const envPK = context.environment.signingSecret;
153153
let token;
154154
try {
155155
token = await sign(

0 commit comments

Comments
 (0)