Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
vibhanshub committed Dec 19, 2023
1 parent d622da7 commit f4600be
Showing 1 changed file with 1 addition and 53 deletions.
54 changes: 1 addition & 53 deletions integrations/va-auth0/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ type Auth0RuntimeEnvironment = RuntimeEnvironment<
}
>;

// https://dev-qyd2bk185i3mltdi.us.auth0.com/authorize?response_type=code&client_id=xEyiJiDYHQ6JQrOVBvhgXQxhi2KY4cC8&redirect_uri=${installationURL}/visitor-auth/response&state=${location}`

type Auth0RuntimeContext = RuntimeContext<Auth0RuntimeEnvironment>;
const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request, context) => {
const { environment } = context;
Expand All @@ -33,43 +31,27 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
base: new URL(installationURL).pathname,
});
router.get('/visitor-auth', async (request) => {
// eslint-disable-next-line no-console
console.log('redirecting bby');
logger.debug('Got a request');
const location = request.query.location;
const issuerBaseUrl = environment.spaceInstallation?.configuration.issuer_base_url;
const clientId = environment.spaceInstallation?.configuration.client_id;

// return Response.json({ url_received: request.url, query: request.query });
// return Response.json({ error: installationURL });
try {
return Response.redirect(
`${issuerBaseUrl}/authorize?response_type=code&client_id=${clientId}&redirect_uri=${installationURL}/visitor-auth/response&state=${location}`
);
} catch (e) {
return Response.json({ error: e.stack });
}
// return Response.redirect(`${installationURL}/visitor-auth/response`);
});

router.get('/visitor-auth/response', async (request) => {
// eslint-disable-next-line no-console
console.log('yaaay');
// redirect to published content URL
if (context.environment.spaceInstallation?.space) {
const space = await context.api.spaces.getSpaceById(
context.environment.spaceInstallation?.space
);
// eslint-disable-next-line no-console
console.log('space', space);
// return Response.json({ url: request.url });
// WORKS;
const obj = space.data;
const privateKey = context.environment.spaceInstallation.configuration.private_key;
// eslint-disable-next-line no-console
console.log('space', obj, privateKey);
// return Response.json({ error: privateKey });
// return Response.redirect('https://www.google.in');
let token;
try {
token = await sign(
Expand All @@ -79,7 +61,7 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
} catch (e) {
return Response.json({ error: e.stack });
}
// return Response.json({ query: request.query });

const issuerBaseUrl = environment.spaceInstallation?.configuration.issuer_base_url;
const clientId = environment.spaceInstallation?.configuration.client_id;
const clientSecret = environment.spaceInstallation?.configuration.client_secret;
Expand All @@ -91,9 +73,7 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
code: `${request.query.code}`,
redirect_uri: `${installationURL}/visitor-auth/response`,
});
// return Response.json({ searchParams });
const url = `${issuerBaseUrl}/oauth/token/`;
// return Response.json({ url });
const resp: any = await fetch(url, {
method: 'POST',
headers: { 'content-type': 'application/x-www-form-urlencoded' },
Expand All @@ -106,7 +86,6 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request

if ('access_token' in resp) {
let url;
// return Response.json({ state: request.query.state });
if (request.query.state) {
url = `${obj.urls?.published}${request.query.state}/?jwt_token=${token}`;
} else {
Expand All @@ -125,20 +104,8 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
Error: 'Either ClientId or ClientSecret is missing',
});
}
// // return Response.redirect('https://www.google.no');
// return Response.redirect(
// obj.urls?.published && token
// ? `${obj.urls?.published}/?jwt_token=${token}`
// : 'https://www.google.dk'
// );
}
// eslint-disable-next-line no-console
console.log('noting here');
// return Response.redirect('https://www.google.com');
});
/**
* Handle GitHub App webhook events
*/

let response;
try {
Expand All @@ -164,18 +131,6 @@ export default createIntegration({
fetch: handleFetchEvent,
events: {
space_installation_setup: async (event, context) => {
// eslint-disable-next-line no-console
console.log(
'received event',
context.environment.integration.name,
event.installationId,
event.spaceId
);
// eslint-disable-next-line no-console
console.log(
'context.environment.installation?.configuration.private_key',
context.environment.installation?.configuration
);
if (!context.environment.spaceInstallation?.configuration.private_key) {
const res = await context.api.integrations.updateIntegrationSpaceInstallation(

Check failure on line 135 in integrations/va-auth0/src/index.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

'res' is assigned a value but never used
context.environment.integration.name,
Expand All @@ -184,16 +139,9 @@ export default createIntegration({
{
configuration: {
private_key: crypto.randomUUID(),
// client_id:
// context.environment.spaceInstallation?.configuration.client_id,
// issuer_base_url:
// context.environment.spaceInstallation?.configuration
// .issuer_base_url,
},
}
);
// eslint-disable-next-line no-console
console.log('recevied response', res.data);
}
},
},
Expand Down

0 comments on commit f4600be

Please sign in to comment.