Skip to content

Instantly share code, notes, and snippets.

View joshcanhelp's full-sized avatar
👋
Open to new connections!

Josh Cunningham joshcanhelp

👋
Open to new connections!
View GitHub Profile
@joshcanhelp
joshcanhelp / checkWordPressForUserAction.js
Last active November 14, 2022 23:20
Auth0 Action to check a WordPress migration endpoint for the existence of a user.
const axios = require("axios");
const customClaimNamespace = "https://wp/has_account";
exports.onExecutePostLogin = async (event, api) => {
const {
WP_API_CLIENT_ID,
WP_API_IDENTIFIER,
WP_API_BASE_URL,
WP_API_TOKEN,
@joshcanhelp
joshcanhelp / step-up-auth-action.js
Created December 7, 2021 18:58
Step-up authentication in Auth0 using Actions
exports.onExecutePostLogin = async (event, api) => {
const CLIENTS_NEEDING_MFA = [
"CLIENT_ID_NEEDING_MFA_1",
"CLIENT_ID_NEEDING_MFA_2"
];
if (!CLIENTS_NEEDING_MFA.includes(event.client.client_id)) {
return;
}
@joshcanhelp
joshcanhelp / convert-roam-daily-to-obsidian.js
Created October 18, 2021 23:56
Convert Roam daily exports to Obsidian default date format
const { opendir, writeFile, readFile } = require('fs/promises');
const uniqueMonth = [];
(async () => {
const dir = await opendir('./_in');
for await (const dirent of dir) {
const namePieces = dirent.name
.replace("st,", "")
.replace("nd,", "")
@joshcanhelp
joshcanhelp / keygen.js
Last active July 11, 2021 19:11
Generate a JWK-formatted private key in Node.js
const { generateKeyPair } = require('jose/util/generate_key_pair');
const { fromKeyLike } = require('jose/jwk/from_key_like');
(async () => {
const { privateKey } = await generateKeyPair('RS256');
const jwk = await fromKeyLike(privateKey);
console.log(JSON.stringify(jwk));
})();
// $ npm install jose
@joshcanhelp
joshcanhelp / checkWordPressForUser.js
Last active December 31, 2020 20:59
Check a WordPress migration endpoint for the existence of a user.
async function checkWordPressForUser(user, context, callback) {
if (!user.email) {
console.log("User does not have an email to use.");
return callback(null, user, context);
}
const customClaimNamespace = "https://custom-claim/has_wp_account";
const {
WP_API_CLIENT_ID,
WP_API_IDENTIFIER,
@joshcanhelp
joshcanhelp / docker-compose.yml
Last active October 10, 2023 20:18
Docker compose for Auth0 WordPress development
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
@joshcanhelp
joshcanhelp / .bashrc
Last active March 17, 2021 17:47
Easy ULP modification with Netlify
# ...
export AUTH0_API2_TOKEN="Your management API token goes here"
export AUTH0_API2_DOMAIN="Your tenant domain goes here"
# https://cli.netlify.com/
alias sync_ulp='netlify deploy --prod --dir . && curl --request PUT \
--data "@./index.html" \
--header "authorization: Bearer $AUTH0_API2_TOKEN" \
--url "https://$AUTH0_API2_DOMAIN/api/v2/branding/templates/universal-login" \
@joshcanhelp
joshcanhelp / delete_unused_files.sh
Created March 9, 2020 21:09
Deletes unused files
while IFS= read -r -d '' file
do
if grep -qr "$file" ../content/md
then echo "Keeping $file";
else rm "$file";
fi
done < <(find _images -type f -print0)
@joshcanhelp
joshcanhelp / wp-auth0-callback.php
Created November 1, 2019 22:28
Add another callback URL to the WP-Auth0 plugin
<?php
function namespace_add_auth0_callback_rewrite() {
add_rewrite_rule('^auth0/callback$', 'index.php?auth0=1', 'top');
}
add_action('init', 'namespace_add_auth0_callback_rewrite');
function namespace_add_auth0_callback_param( $params ) {
$params['redirect_uri'] = home_url( '/auth0/callback' );
return $params;
}
@joshcanhelp
joshcanhelp / wp-auth0-callback.php
Created November 1, 2019 22:28
Add another callback URL to the WP-Auth0 plugin
<?php
function namespace_add_auth0_callback_rewrite() {
add_rewrite_rule('^auth0/callback$', 'index.php?auth0=1', 'top');
}
add_action('init', 'namespace_add_auth0_callback_rewrite');
function namespace_add_auth0_callback_param( $params ) {
$params['redirect_uri'] = home_url( '/auth0/callback' );
return $params;
}