elysia-oauth2
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

elysia-oauth2

Elysia plugin for OAuth 2.0 Authorization Flow.

Powered by Arctic with more than 45 oauth2 providers!

Installation

bun install elysia-oauth2 arctic

Update

if Arctic will release some new providers, you can update it with

bun install arctic@latest

Example

import { 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 token = await oauth2.authorize("VK");

        // send request to API with token
    })
    .listen(3001);

CreateURL example

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", ({ oauth2, set }) => {
        const url = await oauth2.createURL("Google");
        url.searchParams.set("access_type", "offline");

        set.redirect = url.href;
    })
    .get("/auth/google/callback", async ({ oauth2 }) => {
        const token = await oauth2.authorize("Google");

        // send request to API with token
    })
    .listen(3001);

Supported providers

  • Amazon Cognito
  • AniList
  • Apple
  • Atlassian
  • Auth0
  • Bitbucket
  • Box
  • Coinbase
  • Discord
  • Dribbble
  • Dropbox
  • Facebook
  • Figma
  • Github
  • GitLab
  • Google
  • Intuit
  • Kakao
  • Keycloak
  • Lichess
  • Line
  • Linear
  • LinkedIn
  • Microsoft Entra ID
  • MyAnimeList
  • Notion
  • Okta
  • osu!
  • Patreon
  • Reddit
  • Roblox
  • Salesforce
  • Shikimori
  • Slack
  • Spotify
  • Strava
  • Tumblr
  • Twitch
  • Twitter
  • VK
  • WorkOS
  • Yahoo
  • Yandex
  • Zoom

Package Sidebar

Install

npm i elysia-oauth2

Weekly Downloads

54

Version

1.2.0

License

ISC

Unpacked Size

11 kB

Total Files

6

Last publish

Collaborators

  • skravets