Skip to content

Instantly share code, notes, and snippets.

@BrunoBernardino
Created October 20, 2017 12:27
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/b3ccaadd12c570a9dc6542f51fce4bec to your computer and use it in GitHub Desktop.
Save BrunoBernardino/b3ccaadd12c570a9dc6542f51fce4bec to your computer and use it in GitHub Desktop.
Webtask for oauth2-access-token.
module.exports = function(context, request, response) {
if (request.method !== 'POST') {
response.writeHead(400, { 'Content-Type': 'text/html' });
return response.end('Must be POST request');
}
if (context.body && context.body.grant_type !== 'authorization_code') {
response.writeHead(400, { 'Content-Type': 'text/html' });
return response.end('grant_type must be "authorization_code"');
}
if (context.body && context.body.client_id !== '1234') {
response.writeHead(400, { 'Content-Type': 'text/html' });
return response.end('Invalid client_id parameter');
}
if (context.body && context.body.client_secret !== 'asdf') {
response.writeHead(400, { 'Content-Type': 'text/html' });
return response.end('Invalid client_secret parameter');
}
if (context.body && context.body.code !== 'one_time_code') {
response.writeHead(400, { 'Content-Type': 'text/html' });
return response.end('Invalid code parameter');
}
response.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8' });
return response.end('{"access_token": "a_token", "refresh_token": "a_refresh_token", "something_custom": "alright!"}');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment