Skip to content

Instantly share code, notes, and snippets.

View pjeby's full-sized avatar

PJ Eby pjeby

View GitHub Profile
@pjeby
pjeby / Keycloak Email Fetcher.md
Last active April 10, 2023 18:23
Keycloak JS Authenticator: Fetch emails from Github and Twitter APIs

Keycloak One-click Registration for Github and Twitter

Unlike Google and Facebook, Twitter and Github require extra steps to obtain a user's email address: extra steps that Keycloak doesn't do! Instead, Twitter and Github users must manually enter an email that then has to be verified.

This script fixes that problem. It's a Javascript Authenticator for Keycloak that can be placed as a required step at the beginning of a copy of the "first broker login" authentication flow -- which can then be set as the first broker flow for the Github and Twitter identity providers.

Then, when a user registers with Keycloak using one of these providers, this script invokes the right APIs to get the user's email. Twitter only has one email, so it returns that. For Github, it returns the account's primary email address, if it is verified and not a users.noreply.github.com address. If there is no primary, the first public verified address is returned. If there are no public verified addresses, the first verified a

@pjeby
pjeby / shelldown-demo
Last active January 2, 2024 19:02
"You got your markdown in my shell script!" "No, you got your shell script in my markdown!"

Mixed Markdown and Shell Scripting

: By the power of this magic string: ex: set ft=markdown ;:<<'```shell' #, this file is now both a markdown document and an executable shell script. chmod +x it and try running it!

The above line does just what it says. More specifically, when placed within in the first 5 lines and preceded only by blank lines or #-prefixed markdown headers:

  1. The first part of the magic string makes github and various editors (e.g. atom with the vim-modeline packge) treat the file as having markdown syntax (even if the file doesn't have an extension)
  2. The second part (if run in a shell), makes the shell skip execution until it encounters the next ```shell block.

(The line also has to start with a : so that it's valid shell code.)

@pjeby
pjeby / pep487_demo.py
Last active June 5, 2019 15:00
Pure-Python PEP 487 Implementation, usable back to Python 3.1
"""Demonstrate the features"""
from pep487 import init_subclasses, noconflict
class Demo(init_subclasses):
def __init_subclass__(cls, ns, **kw):
print((cls, ns, kw))
super().__init_subclass__(cls, ns, **kw)
# The above doesn't print anything, since it's not a subclass of itself