Skip to content

Instantly share code, notes, and snippets.

View pgstenberg's full-sized avatar

Per-Gustaf Stenberg pgstenberg

View GitHub Profile
@pgstenberg
pgstenberg / SignSamlAssertionExample.kt
Last active March 24, 2023 08:48
Example how to sign a SAML assertion using dsig
import org.w3c.dom.Document
import org.w3c.dom.Element
import java.io.OutputStream
import java.security.KeyFactory
import java.security.KeyPair
import java.security.cert.CertificateFactory
import java.security.cert.X509Certificate
import java.security.interfaces.RSAPrivateKey
import java.security.interfaces.RSAPublicKey
import java.security.spec.PKCS8EncodedKeySpec
@pgstenberg
pgstenberg / oauth2-code-callback-handler.py
Last active August 2, 2021 07:25
Simple python3 snippet for handling a oauth2 code callback by redeeming it and proxy back the response from the oauth2 server.
#!/usr/bin/env python
import sys, http.client, ssl, urllib.parse
from http.server import HTTPServer, BaseHTTPRequestHandler
from urllib.parse import urlparse, parse_qs
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def __init__(self, callback_url, token_url, client_id, client_secret):
self.callback_url = callback_url
@pgstenberg
pgstenberg / docker _add_host_flags
Last active July 30, 2019 12:14
Bash script with embedded python script that extract hosts entries and append them as docker --add-host flags during docker run
#!/bin/bash
#===============================================================================
# example usage:
# docker run -it --rm $(cat /etc/hosts | _add_host_flags) ubuntu /bin/bash
#
# Print content of docker hosts /etc/hosts, pipe it ./add-host.sh
# and echo all the necessary --add-host flags to the docker run command
#===============================================================================
_add_host_flags() {
@pgstenberg
pgstenberg / logstash-local.conf
Created May 15, 2016 18:28
logstash configuration example for kafka consuming logs
input {
syslog {
type => "haproxy-access"
port => 5000
}
log4j {
mode => "server"
host => "0.0.0.0"
port => 3456
type => "zookeeper"