This is part of an authentication service I’ve been working on for a small app. The project is open source on my github here: oauth2-provider-resource. I decided to open source it in the hope that it may help someone trying to build a similar service.