Skip to content
This repository was archived by the owner on Feb 11, 2023. It is now read-only.

Rewrite default urls to ./index.html #61

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
19 changes: 19 additions & 0 deletions authn/github.index.js
Original file line number Diff line number Diff line change
@@ -23,6 +23,17 @@ function mainProcess(event, context, callback) {
config.AUTH_REQUEST.redirect_uri = event.Records[0].cf.config.test + config.CALLBACK_PATH;
config.TOKEN_REQUEST.redirect_uri = event.Records[0].cf.config.test + config.CALLBACK_PATH;
}

if (request.uri.endsWith('/')) {
var requestUrl = request.uri;

// Match url ending with '/' and replace with /index.html
var redirectUrl = requestUrl.replace(/\/$/, '\/index.html');

// Replace the received URI with the URI that includes the index page
request.uri = redirectUrl;
}

if (request.uri.startsWith(config.CALLBACK_PATH)) {
console.log("Callback from GitHub received");
/** Verify code is in querystring */
@@ -124,6 +135,14 @@ function mainProcess(event, context, callback) {
auth.isAuthorized(decoded, request, callback, unauthorized, internalServerError, config);
}
});
} else if ("user-agent" in headers
&& headers["user-agent"].length > 0
&& headers["user-agent"][0].value
&& headers["user-agent"][0].value.includes("Slackbot-LinkExpanding")) {
// Request from slackbot for link unfurl
// TODO only serve up partial page?
console.log("Authorizing Slackbot for link unfurl.");
auth.isAuthorized(null, request, callback, unauthorized, internalServerError, config);
} else {
console.log("Redirecting to GitHub.");
redirect(request, headers, callback);
38 changes: 38 additions & 0 deletions authn/openid.index.js
Original file line number Diff line number Diff line change
@@ -62,6 +62,36 @@ function mainProcess(event, context, callback) {
config.AUTH_REQUEST.redirect_uri = event.Records[0].cf.config.test + config.CALLBACK_PATH;
config.TOKEN_REQUEST.redirect_uri = event.Records[0].cf.config.test + config.CALLBACK_PATH;
}

const actualHost = headers['host'][0].value;
const expectedHost = new URL(config.AUTH_REQUEST.redirect_uri).host;

if (actualHost !== expectedHost) {
const response = {
"status": "308",
"statusDescription": "Found",
"body": "Redirecting to expected domain",
"headers": {
"location" : [{
"key": "Location",
"value": 'https://' + new URL(config.AUTH_REQUEST.redirect_uri).host + request.uri + '?' + request.querystring
}]
},
};
callback(null, response);
return;
}

if (request.uri.endsWith('/')) {
var requestUrl = request.uri;

// Match url ending with '/' and replace with /index.html
var redirectUrl = requestUrl.replace(/\/$/, '\/index.html');

// Replace the received URI with the URI that includes the index page
request.uri = redirectUrl;
}

if (request.uri.startsWith(config.CALLBACK_PATH)) {
console.log("Callback from OIDC provider received");

@@ -233,6 +263,14 @@ function mainProcess(event, context, callback) {
auth.isAuthorized(decoded, request, callback, unauthorized, internalServerError, config);
}
});
} else if ("user-agent" in headers
&& headers["user-agent"].length > 0
&& headers["user-agent"][0].value
&& headers["user-agent"][0].value.includes("Slackbot-LinkExpanding")) {
// Request from slackbot for link unfurl
// TODO only serve up partial page?
console.log("Authorizing Slackbot for link unfurl.");
auth.isAuthorized(null, request, callback, unauthorized, internalServerError, config);
} else {
console.log("Redirecting to OIDC provider.");
redirect(request, headers, callback);
19 changes: 19 additions & 0 deletions authn/pkce.index.js
Original file line number Diff line number Diff line change
@@ -63,6 +63,17 @@ function mainProcess(event, context, callback) {
config.AUTH_REQUEST.redirect_uri = event.Records[0].cf.config.test + config.CALLBACK_PATH;
config.TOKEN_REQUEST.redirect_uri = event.Records[0].cf.config.test + config.CALLBACK_PATH;
}

if (request.uri.endsWith('/')) {
var requestUrl = request.uri;

// Match url ending with '/' and replace with /index.html
var redirectUrl = requestUrl.replace(/\/$/, '\/index.html');

// Replace the received URI with the URI that includes the index page
request.uri = redirectUrl;
}

if (request.uri.startsWith(config.CALLBACK_PATH)) {
console.log("Callback from OIDC provider received");

@@ -239,6 +250,14 @@ function mainProcess(event, context, callback) {
auth.isAuthorized(decoded, request, callback, unauthorized, internalServerError, config);
}
});
} else if ("user-agent" in headers
&& headers["user-agent"].length > 0
&& headers["user-agent"][0].value
&& headers["user-agent"][0].value.includes("Slackbot-LinkExpanding")) {
// Request from slackbot for link unfurl
// TODO only serve up partial page?
console.log("Authorizing Slackbot for link unfurl.");
auth.isAuthorized(null, request, callback, unauthorized, internalServerError, config);
} else {
console.log("Redirecting to OIDC provider.");
redirect(request, headers, callback);