open-index/open-npm huggingface dataset:
npm package: @mdspl/auth-sdk
Description: Framework-agnostic authentication SDK with Hono and Express adapters
Latest version: 1.0.3

# @mdspl/auth-sdk

Framework-agnostic authentication SDK with concrete auth methods.

## Installation

```bash
npm install @mdspl/auth-sdk
```

## Example Usage

### Using Express

```ts
import express from 'express';
import bodyParser from 'body-parser';
import { AuthClient, MapStateStore } from '@mdspl/auth-sdk';

const app = express();
app.use(bodyParser.json());

const authClient = new AuthClient(
  'https://auth.example.com/authorize',
  'client-id',
  'https://app.example.com/auth/callback',
  'https://auth.example.com/verify',
  new MapStateStore()
);

app.get('/auth/login', async (req, res) => {
  const url = await authClient.loginRedirect('https://app.example.com');
  res.redirect(url);
});

app.get('/auth/callback', async (req, res) => {
  const { state, app_session_id } = req.query;
  const redirectUrl = await authClient.callbackRedirect(
    state as string,
    app_session_id as string,
    'https://app.example.com'
  );
  res.redirect(redirectUrl);
});

app.post('/auth/verify', async (req, res) => {
  const { app_session_id } = req.body;
  const data = await authClient.verifySession(app_session_id);
  res.json(data);
});

app.listen(3000, () => console.log('Express app running on port 3000'));
```

### Using Hono

```ts
import { Hono } from 'hono';
import { json } from 'hono/json';
import { AuthClient, MapStateStore } from '@mdspl/auth-sdk';

const app = new Hono();

const authClient = new AuthClient(
  'https://auth.example.com/authorize',
  'client-id',
  'https://app.example.com/auth/callback',
  'https://auth.example.com/verify',
  new MapStateStore()
);

app.get('/auth/login', async (c) => {
  const url = await authClient.loginRedirect('https://app.example.com');
  return c.redirect(url);
});

app.get('/auth/callback', async (c) => {
  const state = c.req.query('state');
  const app_session_id = c.req.query('app_session_id');
  const redirectUrl = await authClient.callbackRedirect(
    state,
    app_session_id,
    'https://app.example.com'
  );
  return c.redirect(redirectUrl);
});

app.post('/auth/verify', async (c) => {
  const body = await c.req.json();
  const data = await authClient.verifySession(body.app_session_id);
  return c.json(data);
});

app.fire();
```

---

### ✅ Key Points

- The SDK provides **only concrete methods** (`loginRedirect`, `callbackRedirect`, `verifySession`)
- You build the framework-specific routes yourself
- Works with **any Node framework** (Express, Hono, Fastify, Next.js API routes, etc.)