Skip to content

Instantly share code, notes, and snippets.

@ensean
Created June 24, 2022 03:38
Show Gist options
  • Save ensean/7dadf99852b3faf3c3d5c925e9194813 to your computer and use it in GitHub Desktop.
Save ensean/7dadf99852b3faf3c3d5c925e9194813 to your computer and use it in GitHub Desktop.
demo auth js for cf workshop in Shenzhen
//Response when token ts does not match.
var response403 = {
statusCode: 403,
statusDescription: 'Unauthorized',
headers: {
'cache-control': {
'value': 'max-age=1296000'
}
}
};
function is_valid_token(token, ts) {
if( token === 'cf_workshop' && ts === '20220624'){
return true;
}
else
{
return false;
}
};
function handler(event) {
// Get request info
var request = event.request;
// If no token, then generate HTTP 403 response.
if(!request.querystring.token || !request.querystring.ts) {
console.log("Error: No token or ts in the querystring");
return response403;
}
var token = request.querystring.token.value;
var ts = request.querystring.ts.value;
// If no token value, then generate HTTP 403 response.
if(!token || !ts){
return response403;
}
// invalid token, return 403 response
if (!is_valid_token(token, ts)){
return response403;
}
return request;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment