Skip to content

Single-sign-on (SSO)

Currently, the application only allows users to sign up for an account using a local username and password.

Another way to sign up for an account is with a single-sign-on (SSO) provider. This is a great way to reduce the number of passwords a user has to remember.

In this guide, we’ll use GitHub, which is pre-installed in the Epic Stack, but it’s possible to add more SSO providers like Google if you want.

To use GitHub as an SSO provider, you need to create an OAuth application in your GitHub account. This will give you a client_id and client_secret that you can use to authenticate users. Let’s go through the steps to set this up.

  1. Log in to your GitHub account.

  2. Click your profile icon on the top right of your screen and go to Settings -> Developer settings -> OAuth Apps.

    Navigate to Github OAuth Apps

  3. Hit the “Register a new application” button.

    Github register new app

  4. Type in http://localhost:3000 for “Homepage URL” and http://localhost:3000/auth/github/callback for “Authorization callback URL”.

    As for the “Application name”, set this to something meaningful (because your users will see the app’s name), e.g. EPIC_NEWS.

    Register app form details

  5. Hit the “Register application” button.

  6. You will be redirected to the page with your newly created OAuth app’s details. You will see your app has got 0 users and no client secrets just yet, but the Client ID has already been assigned to your app.

    New OAuth Details

  7. Copy the Client ID value.

    Open the .env file in your project, and paste it as the GITHUB_CLIENT_ID.

    Copy Client ID to env file

  8. Head back to the Github OAuth settings page still open in your browser.

    Now hit the “Generate client secret” button.

    Generate new secret client button

  9. Copy over the newly generated secret to GITHUB_CLIENT_SECRET in the .env file.

    Copy Client Secret to env file

  10. Hit the Update application button at the bottom of your GitHub OAuth app page.

    Update application button

Your final .env file should now resemble this (values have been redacted):

9 collapsed lines
LITEFS_DIR="/litefs/data"
DATABASE_PATH="./prisma/data.db"
DATABASE_URL="file:./data.db?connection_limit=1"
CACHE_DATABASE_PATH="./other/cache.db"
SESSION_SECRET="super-duper-s3cret"
HONEYPOT_SECRET="super-duper-s3cret"
INTERNAL_COMMAND_TOKEN="some-made-up-token"
RESEND_API_KEY="re_blAh_blaHBlaHblahBLAhBlAh"
SENTRY_DSN="your-dsn"
# the mocks and some code rely on these two being prefixed with "MOCK_"
# if they aren't then the real github api will be attempted
GITHUB_CLIENT_ID="72fa***************a"
GITHUB_CLIENT_SECRET="b2c6d323b**************************eae016"
GITHUB_TOKEN="MOCK_GITHUB_TOKEN"

Create a website user account via Github SSO

Section titled “Create a website user account via Github SSO”
  1. Make sure you are signed out of any existing user accounts on your Epic News application by clicking the “Logout” button in the top right corner of the screen.

    Sign out

  2. Next, in the address bar of your browser, navigate to the /signup route.

    Epic News signup URL
    http://localhost:3000/signup
  3. This time, click on the “Signup with GitHub” button.

    Epic News signup screen

  4. You’ll be told that you don’t have any connections yet. Click “Connect with GitHub”:

    No connections prompt

  5. If you are not already logged in to GitHub, you will be prompted to do so. Once you are logged in, you will be asked fill in your user details.

  6. You will notice that this time, your username and avatar have been pre-filled from your GitHub account. Add your name, accept the Terms of Service, then click “Create an account”.

    Github user details

In this step, we:

  • learned how to set up a GitHub OAuth application and use it to authenticate users in your Epic News application.
  • Updated the .env file with the GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET values.
  • Created a user account using GitHub as an SSO provider.
  • Explored the different features available to authenticated users, such as managing connections, viewing active sessions, and creating, editing, reading, and deleting notes.

In the next section, you will set up the Epic News database using Prisma.