Little late to the party but have you considered using something like an authorization server?
We created Anvil Connect (based on OAuth 2.0 and OpenID Connect) to solve a bundle of auth-related problems all at once. It's a separate server instead of a library, because once you need to share user accounts between several apps (think different platforms) the complexity increases dramatically. There are (third party) client libraries available for a number of languages.
https://github.com/anvilresearch/connect