A demo showing how to sell sell access to a private Github repo.
- Authenticates the buyer using Github
- Collects payment using Stripe
- Automagically adds buyers to repo when payment goes through
Also a Gatsby FuncJam โ21 Winner ๐ฅณ
ย
Are you stuck on a reef in the sharky waters around the Gatsby islands? Check out 1-on-1 Emergency Gatsby Call with Queen Raae to get friendly advice you can put into action immediately from a seasoned Gatsby developer.
Learn how to get the most out of Gatsby and stay updated on the demo by subscribing to daily emails from Queen Raae and Cap'n Ola.
Watch us do a walkthrough of the code on this unauthorized and rum-fueled treasure hunt in the sharky waters around the Gatsby islands on YouTube with Queen Raae, Pirate Paul and Cap'n Ola.
ย
To make it easier to follow there is a page for each major step in the process:
- Index page triggers a GET request to
/api/auth
that triggers a redirect to Github page for authentication- On success Github redirects back to
/auth/?code=<github auth code>
- On success Github redirects back to
- Auth page triggers a POST request to
/api/auth
to exchange the github auth code for an access token- On success navigates to
/checkout
with access token as state param
- On success navigates to
- Checkout page triggers a POST request to
/api/checkout
creating a Stripe Checkout Session- On success navigates to the Checkout Sesssion URL returned from the function when on completing redirects back to
/success/?sessionId=<Stripe Checkout Session ID>
- On success navigates to the Checkout Sesssion URL returned from the function when on completing redirects back to
- Success Page triggers a POST request to
/api/checkout
retreivng the Stripe Checkout Session- On sucess displays message returned from the function.
-
Prerequisite
- A Stripe Secret Key (get one by creating a Stripe account)
- A Stripe Price Id (get one by making a product, then a product price)
- A GitHub OAuth App (create one in your Github settings)
- A private Github repo to sell (create one on GitHub)
- A Github Personal Access Token for the owner of above repo (create one in your Github settings)
-
Develop
- To get started clone this repo locally and run
yarn install
to add all necessary packages. - Create your own
.env.development
by copying.env.example
:cp .env.example .env.development
- Login with Stripe CLI:
stripe login
and follow the directions - Forward Stripe event to the Stripe Webook:
stripe listen --forward-to http://localhost:8000/api/stripe-webhook
- Fill out
.env.development
with your own data and you are ready foryarn develop
- To get started clone this repo locally and run
-
Deploy
You can deploy this example on Gatsby Cloud by connecting your repo Gatsby Cloud.
Make sure to add all the keys needed as environment variables.
- Gatsby functions docs.
- Github Auth docs
- A great article on the auth dance for beginners
- Stripe Checkout Session API docs
- Github Users API docs
- Github Repos API docs