Elysia plugin for OAuth 2.0 Authorization Flow.
Powered by Arctic@2 with more than 63 oauth2 providers!
bun install elysia-oauth2 arcticif Arctic will release some new providers, you can update it with
bun install arctic@latestimport { Elysia } from "elysia";
import { oauth2 } from "elysia-oauth2";
new Elysia()
    .use(
        oauth2({
            VK: [
                "clientID",
                "clientSecret",
                "https://example.com/auth/vk/callback",
            ],
        })
    )
    .get("/auth/vk", ({ oauth2 }) => oauth2.redirect("VK"))
    .get("/auth/vk/callback", async ({ oauth2 }) => {
        const tokens = await oauth2.authorize("VK");
        const accessToken = tokens.accessToken();
        // send request to API with token
    })
    .listen(3000);Important
You should return oauth2.redirect from the handler, because it relies on elysia's redirect() which need to return Response
import { Elysia } from "elysia";
import { oauth2 } from "elysia-oauth2";
new Elysia()
    .use(
        oauth2({
            Google: [
                "clientID",
                "clientSecret",
                "https://example.com/auth/google/callback",
            ],
        })
    )
    .get("/auth/google", async ({ oauth2, redirect }) => {
        const url = oauth2.createURL("Google", ["email"]);
        url.searchParams.set("access_type", "offline");
        return redirect(url.href);
    })
    .get("/auth/google/callback", async ({ oauth2 }) => {
        const tokens = await oauth2.authorize("Google");
        const accessToken = tokens.accessToken();
        // send request to API with token
    })
    .listen(3000);You can configure plugin by providing options object in second argument.
import { Elysia } from "elysia";
import { oauth2 } from "elysia-oauth2";
new Elysia().use(
    oauth2(
        {},
        {
            cookie: {
                // defaults
                secure: true,
                sameSite: "lax",
                path: "/",
                httpOnly: true,
                maxAge: 60 * 30, // 30 min
            },
        }
    )
);- 42 School
 - Amazon Cognito
 - AniList
 - Apple
 - Atlassian
 - Auth0
 - Authentik
 - Autodesk Platform Services
 - Battle.net
 - Bitbucket
 - Box
 - Bungie
 - Coinbase
 - Discord
 - DonationAlerts
 - Dribbble
 - Dropbox
 - Epic Games
 - Etsy
 - Figma
 - Gitea
 - GitHub
 - GitLab
 - Intuit
 - Kakao
 - KeyCloak
 - Kick
 - Lichess
 - Line
 - Linear
 - Mastodon
 - MercadoLibre
 - MercadoPago
 - Microsoft Entra ID
 - MyAnimeList
 - Naver
 - Notion
 - Okta
 - osu!
 - Patreon
 - Polar
 - Roblox
 - Salesforce
 - Shikimori
 - Slack
 - Spotify
 - Start.gg
 - Strava
 - Synology
 - TikTok
 - Tiltify
 - Tumblr
 - Twitch
 - VK
 - WorkOS
 - Yahoo
 - Yandex
 - Zoom