@@ -22,8 +22,6 @@ type Auth0RuntimeEnvironment = RuntimeEnvironment<
22
22
}
23
23
> ;
24
24
25
- // https://dev-qyd2bk185i3mltdi.us.auth0.com/authorize?response_type=code&client_id=xEyiJiDYHQ6JQrOVBvhgXQxhi2KY4cC8&redirect_uri=${installationURL}/visitor-auth/response&state=${location}`
26
-
27
25
type Auth0RuntimeContext = RuntimeContext < Auth0RuntimeEnvironment > ;
28
26
const handleFetchEvent : FetchEventCallback < Auth0RuntimeContext > = async ( request , context ) => {
29
27
const { environment } = context ;
@@ -33,43 +31,27 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
33
31
base : new URL ( installationURL ) . pathname ,
34
32
} ) ;
35
33
router . get ( '/visitor-auth' , async ( request ) => {
36
- // eslint-disable-next-line no-console
37
- console . log ( 'redirecting bby' ) ;
38
34
logger . debug ( 'Got a request' ) ;
39
35
const location = request . query . location ;
40
36
const issuerBaseUrl = environment . spaceInstallation ?. configuration . issuer_base_url ;
41
37
const clientId = environment . spaceInstallation ?. configuration . client_id ;
42
38
43
- // return Response.json({ url_received: request.url, query: request.query });
44
- // return Response.json({ error: installationURL });
45
39
try {
46
40
return Response . redirect (
47
41
`${ issuerBaseUrl } /authorize?response_type=code&client_id=${ clientId } &redirect_uri=${ installationURL } /visitor-auth/response&state=${ location } `
48
42
) ;
49
43
} catch ( e ) {
50
44
return Response . json ( { error : e . stack } ) ;
51
45
}
52
- // return Response.redirect(`${installationURL}/visitor-auth/response`);
53
46
} ) ;
54
47
55
48
router . get ( '/visitor-auth/response' , async ( request ) => {
56
- // eslint-disable-next-line no-console
57
- console . log ( 'yaaay' ) ;
58
- // redirect to published content URL
59
49
if ( context . environment . spaceInstallation ?. space ) {
60
50
const space = await context . api . spaces . getSpaceById (
61
51
context . environment . spaceInstallation ?. space
62
52
) ;
63
- // eslint-disable-next-line no-console
64
- console . log ( 'space' , space ) ;
65
- // return Response.json({ url: request.url });
66
- // WORKS;
67
53
const obj = space . data ;
68
54
const privateKey = context . environment . spaceInstallation . configuration . private_key ;
69
- // eslint-disable-next-line no-console
70
- console . log ( 'space' , obj , privateKey ) ;
71
- // return Response.json({ error: privateKey });
72
- // return Response.redirect('https://www.google.in');
73
55
let token ;
74
56
try {
75
57
token = await sign (
@@ -79,7 +61,7 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
79
61
} catch ( e ) {
80
62
return Response . json ( { error : e . stack } ) ;
81
63
}
82
- // return Response.json({ query: request.query });
64
+
83
65
const issuerBaseUrl = environment . spaceInstallation ?. configuration . issuer_base_url ;
84
66
const clientId = environment . spaceInstallation ?. configuration . client_id ;
85
67
const clientSecret = environment . spaceInstallation ?. configuration . client_secret ;
@@ -91,9 +73,7 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
91
73
code : `${ request . query . code } ` ,
92
74
redirect_uri : `${ installationURL } /visitor-auth/response` ,
93
75
} ) ;
94
- // return Response.json({ searchParams });
95
76
const url = `${ issuerBaseUrl } /oauth/token/` ;
96
- // return Response.json({ url });
97
77
const resp : any = await fetch ( url , {
98
78
method : 'POST' ,
99
79
headers : { 'content-type' : 'application/x-www-form-urlencoded' } ,
@@ -106,7 +86,6 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
106
86
107
87
if ( 'access_token' in resp ) {
108
88
let url ;
109
- // return Response.json({ state: request.query.state });
110
89
if ( request . query . state ) {
111
90
url = `${ obj . urls ?. published } ${ request . query . state } /?jwt_token=${ token } ` ;
112
91
} else {
@@ -125,20 +104,8 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
125
104
Error : 'Either ClientId or ClientSecret is missing' ,
126
105
} ) ;
127
106
}
128
- // // return Response.redirect('https://www.google.no');
129
- // return Response.redirect(
130
- // obj.urls?.published && token
131
- // ? `${obj.urls?.published}/?jwt_token=${token}`
132
- // : 'https://www.google.dk'
133
- // );
134
107
}
135
- // eslint-disable-next-line no-console
136
- console . log ( 'noting here' ) ;
137
- // return Response.redirect('https://www.google.com');
138
108
} ) ;
139
- /**
140
- * Handle GitHub App webhook events
141
- */
142
109
143
110
let response ;
144
111
try {
@@ -164,18 +131,6 @@ export default createIntegration({
164
131
fetch : handleFetchEvent ,
165
132
events : {
166
133
space_installation_setup : async ( event , context ) => {
167
- // eslint-disable-next-line no-console
168
- console . log (
169
- 'received event' ,
170
- context . environment . integration . name ,
171
- event . installationId ,
172
- event . spaceId
173
- ) ;
174
- // eslint-disable-next-line no-console
175
- console . log (
176
- 'context.environment.installation?.configuration.private_key' ,
177
- context . environment . installation ?. configuration
178
- ) ;
179
134
if ( ! context . environment . spaceInstallation ?. configuration . private_key ) {
180
135
const res = await context . api . integrations . updateIntegrationSpaceInstallation (
181
136
context . environment . integration . name ,
@@ -184,16 +139,9 @@ export default createIntegration({
184
139
{
185
140
configuration : {
186
141
private_key : crypto . randomUUID ( ) ,
187
- // client_id:
188
- // context.environment.spaceInstallation?.configuration.client_id,
189
- // issuer_base_url:
190
- // context.environment.spaceInstallation?.configuration
191
- // .issuer_base_url,
192
142
} ,
193
143
}
194
144
) ;
195
- // eslint-disable-next-line no-console
196
- console . log ( 'recevied response' , res . data ) ;
197
145
}
198
146
} ,
199
147
} ,
0 commit comments