Skip to content

Instantly share code, notes, and snippets.

View dcaponi's full-sized avatar

Dominick Caponi dcaponi

View GitHub Profile
@dcaponi
dcaponi / ol_auth.js
Created May 19, 2021 15:45
Automatically Run Authorization Step for OneLogin API Requests
var region = pm.variables.get("region");
var id = pm.variables.get("client_id");
var secret = pm.variables.get("client_secret");
var basicToken = btoa(`${id}:${secret}`);
const echoPostRequest = {
url: `https://api.${region}.onelogin.com/auth/oauth2/v2/token`,
method: 'POST',
header: {
"Content-Type": "application/json",
@dcaponi
dcaponi / onelogin_oidc.tf
Last active June 1, 2023 13:18
bootstraps your onelogin account with a user, role, and OIDC app
terraform {
required_providers {
onelogin = {
source = "onelogin/onelogin"
version = "0.1.6"
}
}
}
resource onelogin_oidc_apps my_app {
@dcaponi
dcaponi / pkce_token_step.js
Created January 1, 2021 20:09
second step in pkce flow to get an access token from our auth code
const PKCEAuthCodeSecondStep = ( code ) => {
let oidcURL = `${process.env.OIDC_IDP_URL}/token`;
let params = qs.stringify( {
grant_type: "authorization_code",
redirect_uri: "http://localhost/login_oidc",
client_id: process.env.OIDC_CLIENT_ID,
code_verifier: localStorage.getItem( 'code_verifier' ),
code
} );
@dcaponi
dcaponi / pkce_first_step.js
Created January 1, 2021 19:56
Builts the auth url to an IdP using PKCE flow
const PKCEAuthCodeFirstStep = () => {
let oidcURL = `${process.env.OIDC_IDP_URL}/auth`;
let queryParams = [`client_id=${process.env.OIDC_CLIENT_ID}`];
let codeVerifier = createCodeVerifier( 50 );
localStorage.setItem( 'code_verifier', codeVerifier );
return createCodeChallenge( codeVerifier ).then( codeChallenge => {
queryParams.push(`code_challenge=${codeChallenge}`);
queryParams.push(`redirect_uri=http://localhost/login_oidc`);
queryParams.push(`code_challenge_method=S256`);
@dcaponi
dcaponi / code_verifier.js
Created January 1, 2021 19:56
Creates a legal code_verifier based on the OAuth Spec
const createCodeVerifier = ( size ) => {
const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~';
const charsetIndexBuffer = new Uint8Array( size );
for ( let i = 0; i < size; i += 1 ) {
charsetIndexBuffer[i] = ( Math.random() * charset.length ) | 0;
}
let randomChars = [];
for ( let i = 0; i < charsetIndexBuffer.byteLength; i += 1 ) {
@dcaponi
dcaponi / pkce_code_challenge.js
Created January 1, 2021 19:55
Takes a code_verifier string and makes a legal code_challenge out of it
const createCodeChallenge = ( codeVerifier ) => {
if ( typeof window !== 'undefined' && !!( window.crypto ) && !!( window.crypto.subtle ) ) {
return new Promise( ( resolve, reject ) => {
let codeVerifierCharCodes = textEncodeLite( codeVerifier );
crypto.subtle
.digest( 'SHA-256', codeVerifierCharCodes )
.then(
hashedCharCodes => resolve( urlSafe( new Uint8Array(hashedCharCodes) ) ),
error => reject( error )
);
@dcaponi
dcaponi / PKCE_login_page.js
Last active June 1, 2023 13:37
Prototype of OIDC PKCE Flow in React
import React, { Component } from 'react';
import axios from 'axios';
import qs from "qs";
import * as base64 from 'base64-js'
import SubmitButton from '../../ui_components/buttons/submit_button';
import AppWrapper from '../../ui_components/app_wrapper/app_wrapper'
import Popup from '../../ui_components/popup/popup';
class LoginOIDCPage extends Component {
@dcaponi
dcaponi / ship.sh
Created June 7, 2020 21:35
Builds go binaries, adds some literature, and compresses the folder for Mac, Linux, and Windows
#!/usr/bin/env bash
package=$1
if [[ -z "$package" ]]; then
echo "usage: $0 <package-name>"
exit 1
fi
package_split=(${package//\// })
package_name=${package_split[${#package_split[@]}-1]}
@dcaponi
dcaponi / release.yml
Created June 7, 2020 21:34
Multi-Platform Go Ship with GH Action
on:
push:
tags:
- '*'
name: Release
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
@dcaponi
dcaponi / linux_commands.md
Created May 15, 2020 18:28
Linux Commands

#Linux Commands

Simple Stuff

grep - search for a string

search for word "stuff" in a file called filename and returns all lines with the word "stuff"

grep "stuff" filename.ext