Notion Authorization Provider
Add Notion authorization provider to Aura Auth to authenticate and authorize
Notion
Set up Notion 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 Notion provider to Aura Auth.
Notion OAuth App
Creating an OAuth app
The first step is create and register a Notion Integration to grant to have access to the user's accessible resources like Retrieve the Bot User (Used by Aura Auth), Pages, Comments, Databases, etc. For more detailed information read Get Started Authorization, Notion Integrations and Get Self User.
Registering an Notion OAuth app includes:
Integration name: The application name showed when the user tries to grant to the app.Associated workspace: The workspace that the app belongs to, it can be changed later.Company name: The company name showed when the user tries to grant to the app.Website: The URL of the website, it can be changed later.Tagline: The tagline of the app, it can be changed later.Privacy Policy URL: The URL of the privacy policy, it can be changed later.Terms of Use URL: The URL of the terms of use, it can be changed later.Email: The email of the developer, it can be changed later.Authorization URL: The URL which the Notion will redirect, it should end in/auth/callback/notionfor local and production environment.- Local environment:
http://localhost:3000/auth/callback/notion - Production environment: production set the URL of the application.
- Local environment:
Notion 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 Notion 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.
# Notion Credentials
AURA_AUTH_NOTION_CLIENT_ID="notion_client_id"
AURA_AUTH_NOTION_CLIENT_SECRET="notion_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. You can use the provider name as a string to use default settings, or use the notion factory function to customize the configuration.
Default configuration
import { createAuth } from "@aura-stack/auth"
export const auth = createAuth({
oauth: ["notion"],
})
export const { handlers } = authCustom configuration
import { createAuth } from "@aura-stack/auth"
import { notion } from "@aura-stack/auth/oauth/notion"
export const auth = createAuth({
oauth: [
notion({
scope: "read:user user:email repo",
}),
],
})
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.