Skip to content

Instantly share code, notes, and snippets.

@BrunoBernardino
Created October 20, 2017 12:22
Show Gist options
  • Save BrunoBernardino/2adb45d0f72d420f58da85139d6eea05 to your computer and use it in GitHub Desktop.
Save BrunoBernardino/2adb45d0f72d420f58da85139d6eea05 to your computer and use it in GitHub Desktop.
Webtask for oauth2-refresh-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 !== 'refresh_token') {
response.writeHead(400, { 'Content-Type': 'text/html' });
return response.end('grant_type must be "refresh_token"');
}
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.refresh_token !== 'a_refresh_token') {
response.writeHead(400, { 'Content-Type': 'text/html' });
return response.end('Invalid refresh_token parameter');
}
response.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8' });
return response.end('{"access_token": "a_new_token"}');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment