Skip to content

Instantly share code, notes, and snippets.

@BrunoBernardino
Created October 20, 2017 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrunoBernardino/5be552af01242b7defed50c9e076fcdc to your computer and use it in GitHub Desktop.
Save BrunoBernardino/5be552af01242b7defed50c9e076fcdc to your computer and use it in GitHub Desktop.
Webtask for oauth2-authorize.
module.exports = function(context, request, response) {
if (request.method !== 'GET') {
response.writeHead(400, { 'Content-Type': 'text/html' });
return response.end('Must be GET request');
}
if (context.query.response_type !== 'code') {
response.writeHead(400, { 'Content-Type': 'text/html' });
return response.end('response_type must be "code"');
}
if (context.query.client_id !== '1234') {
response.writeHead(400, { 'Content-Type': 'text/html' });
return response.end('Invalid client_id parameter');
}
if (!context.query.redirect_uri) {
response.writeHead(400, { 'Content-Type': 'text/html' });
return response.end('Invalid redirect_uri parameter');
}
if (!context.query.state) {
response.writeHead(400, { 'Content-Type': 'text/html' });
return response.end('Invalid state parameter');
}
const redirectUrl = `${context.query.redirect_uri}?code=one_time_code&state=${request.query.state}`;
response.writeHead(302, { 'Location': redirectUrl });
return response.end();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment