Skip to content

Instantly share code, notes, and snippets.

View arcseldon's full-sized avatar

Richard Seldon arcseldon

View GitHub Profile
@arcseldon
arcseldon / redirect-rule.js
Created December 5, 2016 11:32 — forked from nicosabena/redirect-rule.js
Redirect rule + webtask to do a reCaptcha after authentication
function (user, context, callback) {
// this rule requires the following configuration values:
// CAPTCHA_SECRET: a 32 bytes string that will be the shared secret between
// the rule and the webtask
// AUTH0_DOMAIN: your auth0 domain (e.g. account.auth0.com)
// CAPTCHA_REDIRECT: the URL for the webtask that will show and process CAPTCHA
// Put a specific client ID if you dont want CAPTCHA for every client
// if (context.clientID !== '[your client id]')
@arcseldon
arcseldon / getUser.js
Last active November 26, 2016 22:06
auth0 get users endpoint invocation server side (trusted server)
function getManagementApiToken() {
const cachedToken = cache.get('managementApi');
if (cachedToken) {
return Promise.resolve(cachedToken);
} else {
return request.post({
url: `https://${process.env.AUTH0_DOMAIN}/oauth/token`,
body: {
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET,
@arcseldon
arcseldon / changepassword.js
Created November 24, 2016 04:23
Custom DB change password
function changePassword(email, newPassword, callback) {
var request = require('request');
// DEBUG ONLY
console.log('@@@ changePassword - start @@@');
console.log('email: ' + email);
console.log('newPassword: ' + newPassword);
var IDP_ENDPOINT = configuration.ENDPOINT_LOCAL + "/api/v1/changepassword";
@arcseldon
arcseldon / contest-webtask.js
Created November 20, 2016 07:24 — forked from woloski/contest-webtask.js
Contest Signup Webtask
'use latest';
import express from 'express';
import { fromExpress } from 'webtask-tools';
import bodyParser from 'body-parser';
const app = express();
var jwt = require('express-jwt');
var jwtCheck = jwt({
import _ from 'lodash';
import fetch from 'node-fetch';
import delay from 'delay';
export async function pingServers(servers) {
let failedServers = {};
for (const url of servers) {
let failures = 0;
for (const i of _.range(3)) {
const response = await fetch(url);
@arcseldon
arcseldon / Option1.js
Created November 8, 2016 00:39 — forked from pushpabrol/Option1.js
How to use ldapjs within a custom database connection in Auth0
function login(email, password, callback) {
var ldap = require('ldapjs');
if (!global.ldapClient) {
// console.log('Global Client not found');
var client = ldap.createClient({
url: 'ldap://server:389',
idleTimeout: 30000
});
client.bind('uid=admin,ou=system', 'secret', function(err) {

Own version of com.auth0.SessionUtils with the following two methods overridden in custom impl.

     import org.springframework.beans.BeanUtils;
     ...
     
     
     public static Auth0User getAuth0User(final HttpServletRequest req) {
        System.out.println("GET AUTH0 USER");
        final MyAuth0User myAuth0User = (MyAuth0User) getSession(req).getAttribute(AUTH0_USER);
@arcseldon
arcseldon / .eslintrc
Created April 29, 2016 14:57 — forked from hendrikswan/.eslintrc
Packages and build config for Build Cross Platform React Native Apps with Exponent and Redux
{
"extends": "airbnb/base",
"plugins": [
"react"
],
"env": {
"node": true,
"jasmine": true,
},
"rules": {
@arcseldon
arcseldon / noLoginForConnectionType.js
Created March 15, 2016 08:28
Auth0 Rule sample - checking for connection type and login count.
function noLoginForConnectionType(user, context, callback) {
user.app_metadata = user.app_metadata || {};
console.log('connection: ' + context.connection);
if (context.connection === 'google-oauth2'){
var cnt = context.stats.loginsCount;
console.log('user login count: ' + cnt);
if (cnt <= 1) {
console.log('Setting loginDisabled');
user.app_metadata.loginDisabled = true;
auth0.users.updateAppMetadata(user.user_id, user.app_metadata)
@arcseldon
arcseldon / Auth0JWTSigner.scala
Created March 5, 2016 07:53
Provides a blueprint for how to create an Auth0 JSON Web Token (JWT)
// richard.seldon@auth0.com
// commons-codec-1.10.jar
// java-jwt-2.1.0.jar
// see docs here: https://auth0.com/docs/jwt
import java.security.SignatureException
import java.text.SimpleDateFormat