Skip to content

Instantly share code, notes, and snippets.

Avatar

Bruno Bernardino BrunoBernardino

View GitHub Profile
View an-intro.md

Hi!

If I've helped you, feel free to donate BTC or ETH to the addresses below, I appreciate it!

If you want to pay me via PayPal or GitHub Sponsors, you can use the buttons below.

PayPal logo

View blockstack.txt
Verifying my Blockstack ID is secured with the address 1FBJPttYvREtEcw7Vgd9gCZcRteERYuSma https://explorer.blockstack.org/address/1FBJPttYvREtEcw7Vgd9gCZcRteERYuSma
@BrunoBernardino
BrunoBernardino / recipe-create.js
Created Nov 13, 2017
Webtask for recipe-create.
View recipe-create.js
module.exports = function(context, cb) {
cb(null, {
"id":"1",
"createdAt":1471984289,
"name":"name 1",
"authorId":63,
"directions":"directions 1",
"style":"style 1"
});
};
@BrunoBernardino
BrunoBernardino / fields-input.js
Created Oct 24, 2017
Webtask for getting input fields.
View fields-input.js
module.exports = function(context, cb) {
cb(null, [
{
"key":"authorId",
"label":"Author",
"type":"number",
"required": true,
"helpText": "This is some help, yo!"
}
]);
@BrunoBernardino
BrunoBernardino / fields-output.js
Created Oct 24, 2017
Webtask for output fields.
View fields-output.js
module.exports = function(context, cb) {
cb(null, [
{
"key":"name",
"label":"Better Name",
"type":"string"
},
{
"key":"authorId",
"label":"Author",
@BrunoBernardino
BrunoBernardino / oauth2-access-token.js
Created Oct 20, 2017
Webtask for oauth2-access-token.
View oauth2-access-token.js
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"');
}
@BrunoBernardino
BrunoBernardino / oauth2-refresh-token.js
Created Oct 20, 2017
Webtask for oauth2-refresh-token.
View oauth2-refresh-token.js
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"');
}
@BrunoBernardino
BrunoBernardino / oauth2-authorize.js
Created Oct 20, 2017
Webtask for oauth2-authorize.
View oauth2-authorize.js
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"');
}
@BrunoBernardino
BrunoBernardino / oauth2-test.js
Created Oct 20, 2017
Webtask for oauth2-test.
View oauth2-test.js
module.exports = function(context, cb) {
if (!context.headers.authorization) {
return cb(403, 'Forbidden');
}
if (context.headers.authorization !== 'Bearer a_token' && context.headers.authorization !== 'Bearer a_new_token') {
return cb(401, 'Unauthorized');
}
cb(null, {
@BrunoBernardino
BrunoBernardino / session.js
Last active Nov 13, 2017
Webtask for session auth.
View session.js
module.exports = function(context, cb) {
if (context.body) {
if (!context.body.email || !context.body.pass) {
return cb(401, 'Unauthorized');
}
} else if (!context.headers['x-token']) {
return cb(403, 'Forbidden');
}
const now = new Date();
You can’t perform that action at this time.