Adjustions for utilizing an external OAuth Hook (#945)

* 🚧 add oauth redirect env variable, add host to oauth state

* 🎨 format

* 🚧 reset changes

* 🚧 add hook

* 🚧 remove host from inital state
This commit is contained in:
Ben Hesseldieck 2020-09-11 12:15:06 +02:00 committed by GitHub
parent 5751a645aa
commit 279af6251b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 9 deletions

View file

@ -1176,7 +1176,7 @@ class App {
const csrfSecret = token.secretSync();
const state = {
token: token.create(csrfSecret),
cid: req.query.id
cid: req.query.id,
};
const stateEncodedStr = Buffer.from(JSON.stringify(state)).toString('base64') as string;
@ -1294,13 +1294,14 @@ class App {
};
delete oAuth2Parameters.clientSecret;
}
const redirectUri = `${WebhookHelpers.getWebhookBaseUrl()}${this.restEndpoint}/oauth2-credential/callback`;
await this.externalHooks.run('oauth2.callback', [oAuth2Parameters]);
const oAuthObj = new clientOAuth2(oAuth2Parameters);
const queryParameters = req.originalUrl.split('?').splice(1, 1).join('');
const oauthToken = await oAuthObj.code.getToken(`${redirectUri}?${queryParameters}`, options);
const oauthToken = await oAuthObj.code.getToken(`${oAuth2Parameters.redirectUri}?${queryParameters}`, options);
if (oauthToken === undefined) {
const errorResponse = new ResponseHelper.ResponseError('Unable to get access tokens!', undefined, 404);

View file

@ -1,9 +1,9 @@
<html>
<script>
(function messageParent() {
window.opener.postMessage('success', '*');
}());
</script>
<script>
(function messageParent() {
window.opener.postMessage('success', '*');
}());
</script>
Got connected. The window can be closed now.
Got connected. The window can be closed now.
</html>