Github Authorization Provider
Add GitHub authorization provider to Aura Auth to authentication and authorize
GitHub
Set up GitHub authorization provider to the authentication instance to Aura Auth.
What you'll learn
Through this quick start guide you are going to learn and understand the basics and how to set up GitHub provider to Aura Auth.
GitHub OAuth App
Creating an OAuth app
The first step is create and register a GitHub OAuth App to grant to have access to the user's accessible resources like Get Authenticated User (Used by Aura Auth), Repositories, Organizations, etc. For more detailed information read Creating an OAuth app and Get authenticated user.
Registering an GitHub OAuth app includes:
Application name: The application name showed when the user tries to grant to the app.Homepage URL: The home url of the websiteAuthorization callback URL: The URL which the Github will redirect, it should end in/auth/callback/githubfor local and production environment, read Redirect URLs.- Local environment:
http://localhost:3000/auth/callback/github - Production environment: production set the URL of the application.
- Local environment:
GitHub Aura Auth
Installation
install the package using a package manager like npm, pnpm or yarn
npm install @aura-stack/authEnvironment setup
Now, it's time to create and consume the GitHub credentials required and used by Aura Auth, it include the client Id and client Secret and write them into a .env file.
Additionally set the secret used by Aura Auth to sign and encrypt the user's session.
# GitHub Credentials
AURA_AUTH_GITHUB_CLIENT_ID="github_client_id"
AURA_AUTH_GITHUB_CLIENT_SECRET="github_client_secret"
# Aura Secret
AURA_AUTH_SECRET="32-bytes-secret"The AURA_AUTH_SECRET will recommended to be random and high antropy key to avoid attackers decifer the secret used by the Aura
Auth application.
Configure the provider
Set the oauth option of the createAuth instance and writing "github" name.
import { createAuth } from "@aura-stack/auth"
export const auth = createAuth({
oauth: ["github"],
})
export const { handlers } = authGet HTTP Handlers
Use the HTTP handlers to consume the authentication logic and flow the Aura Auth library to be integrated into routers and frameworks.
import { handlers } from "@/auth"
export const { GET, POST } = handlersThe returned handlers include pre-built routes used in OAuth flows (/signIn/:oauth, /callback/:oauth, /session, /signOut
and /csrfToken). You can mount them in Express, Hono, Next.js, or any runtime that supports native Request and Response APIs.