Skip to content

Instantly share code, notes, and snippets.

View BrunoBernardino's full-sized avatar

Bruno Bernardino BrunoBernardino

View GitHub Profile
@BrunoBernardino
BrunoBernardino / breakVisualCaptcha.js
Created August 15, 2013 20:06
This is code based off of https://gist.github.com/ipeychev/6234050, refactored to be possible to make multiple attempts in one execution. 100 attempts are equivalent to 500 post requests (every "attempt" tries to post 5 images). I'm actually getting < 5-7% successful break attempt rates, but it's still unnacceptable and I'll use this code to che…
// This code has a break rate of < 10%. It's still unnacceptable, though.
var request = require( 'request' ).defaults( { jar: true } ),
q = require( 'q' );
var URI = 'http://demo.visualcaptcha.net/';
// Make a post
var makePost = function makePost( imgHash, partialURL, tryNumber ) {
var deferred = q.defer(),
@BrunoBernardino
BrunoBernardino / keybase.md
Last active August 22, 2018 08:05
keybase.md

Keybase proof

I hereby claim:

  • I am brunobernardino on github.
  • I am brunobernardino (https://keybase.io/brunobernardino) on keybase.
  • I have a public key ASCV1iwLOfJXJPpHapEKwT9wF5v5hjoWwTG4KXAr35uC5go

To claim this, I am signing this object:

@BrunoBernardino
BrunoBernardino / code.js
Created December 3, 2016 14:05
AWS Lambda Redirect code
'use strict';
const finish = (cb, url) => {
console.log('Sending to', url);
cb(null, {url: url});
}
exports.handler = (event, context, callback) => {
const defaultURL = 'http://example.com';
@BrunoBernardino
BrunoBernardino / api-header.js
Last active November 13, 2017 17:37
Webtask for api-header auth.
module.exports = function(context, cb) {
if (!context.headers['x-api-key']) {
return cb(401, 'Unauthorized');
}
cb(null, {
authenticated: true,
user: 'user',
});
};
@BrunoBernardino
BrunoBernardino / api-query.js
Created October 17, 2017 09:24
Webtask for api-query auth
module.exports = function(context, cb) {
if (!context.query.apiKey) {
return cb(401, 'Unauthorized');
}
cb(null, {
authenticated: true,
user: 'Zapier',
});
};
@BrunoBernardino
BrunoBernardino / session.js
Last active November 13, 2017 17:37
Webtask for session auth.
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();
@BrunoBernardino
BrunoBernardino / oauth2-test.js
Created October 20, 2017 10:27
Webtask for oauth2-test.
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 / oauth2-authorize.js
Created October 20, 2017 10:39
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"');
}
@BrunoBernardino
BrunoBernardino / oauth2-refresh-token.js
Created October 20, 2017 12:22
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"');
}
@BrunoBernardino
BrunoBernardino / oauth2-access-token.js
Created October 20, 2017 12:27
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"');
}