Every time I tried to build a SaaS, writing the authentication and billing code would take time. It got me wishing there was a tool that would handle it so I could launch a bit faster.
Sure, there are lots of options for authentication, and Stripe handles all the payment stuff, but it still takes some work to glue those parts together.
If you're like me, you probably end up building very minimal version for the initial launch. That means having billing/auth code that lacks the features needed for higher priced "business" plans, like multiple users-per-account (aka teams), or Single Sign On (SSO) for "enterprise" plans.
So I decided to try and create a tool that would make this easier.
I ended up building an Identity Provider (like Netlify's GoTrue or Auth0) but specialized for SaaS. It runs on a subdomain right next the main app. ie, if the main app is at myapp.co, the IDP would be on the subdomainid.myapp.co
What makes it special is that it integrates with Stripe Subscription API. So all accounts get a Stripe Customer and Subscription associated with them during the signup flow.
To signup, it's just a link https://id.myapp.co/signup. That handles the OAuth/password/magic-link login and redirects the user to pay via Stripe Checkout.
Once paid, the account is activated and they are redirected back to the main site with a JWT token. The JWT token is tamper-proof and contains info about the account and even their Stripe Subscription & Customer IDs.
You can see an example JWT here: https://res.cloudinary.com/dzwnkx0mk/image/upload/v1654937082/1000experiments.dev/JSON-Web-Tokens-jwt-io_ycqfen.png
It also integrates with Stripe's billing portal, just add a link to https://id.myapp.co/account/portal.
A few more things about it:
I'm not really sure where this is headed, or if it will all work out, but I figured I'd share my progress so far.
Here's is the experimental code: (not production ready)
https://github.com/joshnuss/idp-experiment
This is actually a really interesting approach.
One thing I’ve noticed when building SaaS projects is that auth and billing always look simple at the beginning, but once you start adding teams, subscriptions, plan upgrades, SSO, etc., the complexity grows really fast.
Having an identity provider that sits on a subdomain and handles signup + Stripe + token issuance sounds like a clean separation of concerns.
I also like the idea of including subscription information directly in the JWT so services can make decisions without constantly querying the billing system.
Curious — did you design this mostly for single-app SaaS projects or do you see it working well in microservice setups too?