Created
June 24, 2022 03:38
-
-
Save ensean/7dadf99852b3faf3c3d5c925e9194813 to your computer and use it in GitHub Desktop.
demo auth js for cf workshop in Shenzhen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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