npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

unologin-client

v1.2.0

Published

TypeScript SDK for UnoLogin SSO integration

Readme

unologin-client

TypeScript SDK for integrating UnoLogin SSO into your applications.

Installation

npm install unologin-client

Получение clientId и clientSecret

Перед использованием SDK нужно зарегистрировать своё приложение в unologin.

1. Зарегистрируйся

POST https://unologin.ru/auth/email/register
Content-Type: application/json

{ "email": "[email protected]", "password": "YourPassword123!" }

2. Подтверди email — на почту придёт 6-значный код:

POST https://unologin.ru/auth/email/verify
Content-Type: application/json

{ "email": "[email protected]", "code": "123456" }

3. Войди и получи accessToken:

POST https://unologin.ru/auth/email/login
Content-Type: application/json

{ "email": "[email protected]", "password": "YourPassword123!" }
{
  "accessToken": "eyJhbGci...",
  "refreshToken": "eyJhbGci..."
}

4. Создай клиентское приложение:

POST https://unologin.ru/oauth/client-apps
Authorization: Bearer <твой accessToken>
Content-Type: application/json

{
  "name": "Название твоего приложения",
  "businessModel": "b2b",
  "redirectUris": ["https://yourapp.com/callback"]
}

3. Сохрани ответ — clientSecret показывается только один раз:

{
  "clientId": "app_a3f9c1d2...",
  "clientSecret": "d8e2f4a1b3...",
  "redirectUris": ["https://yourapp.com/callback"],
  "businessModel": "b2b"
}

Теперь используй эти значения при инициализации SDK.


Quick Start

B2B Application

import { UnoLoginClient } from 'unologin-client/server';

const client = new UnoLoginClient({
  clientId: 'app_your_client_id',
  clientSecret: 'your_client_secret',
  redirectUri: 'https://yourapp.com/callback',
  unoLoginUrl: 'https://unologin.ru',
  businessModel: 'b2b',
});

// Redirect user to login
app.get('/login', (req, res) => {
  const authUrl = client.getAuthorizationUrl({
    state: generateRandomState(),
  });
  res.redirect(authUrl);
});

// Handle callback
app.get('/callback', async (req, res) => {
  const { code, state } = req.query;

  // Verify state against what you stored before redirect
  const tokens = await client.exchangeCode(code as string);

  // tokens.user contains basic profile
  // tokens.user.role, tokens.user.email, etc.
  req.session.accessToken = tokens.accessToken;
  req.session.refreshToken = tokens.refreshToken;

  // For B2B: fetch full user info including organization (INN)
  const user = await client.getUserInfo(tokens.accessToken);
  console.log(user.organization); // { inn, companyName, kpp, ogrn }

  res.redirect('/dashboard');
});

B2C Application

const client = new UnoLoginClient({
  clientId: 'app_your_client_id',
  clientSecret: 'your_client_secret',
  redirectUri: 'https://yourapp.com/callback',
  unoLoginUrl: 'https://unologin.ru',
  businessModel: 'b2c',
});

// Same flow — no organization data in userinfo

B2B2C Application (E-commerce Platform)

const client = new UnoLoginClient({
  clientId: 'app_your_client_id',
  clientSecret: 'your_client_secret',
  redirectUri: 'https://yourapp.com/callback',
  unoLoginUrl: 'https://unologin.ru',
  businessModel: 'b2b2c',
});

// Merchant login
app.get('/admin/login', (req, res) => {
  const authUrl = client.getAuthorizationUrl({
    role: 'merchant',
    state: generateRandomState(),
  });
  res.redirect(authUrl);
});

// Customer login (with tenant context)
app.get('/shop/:subdomain/login', (req, res) => {
  const authUrl = client.getAuthorizationUrl({
    role: 'customer',
    tenantId: req.params.subdomain,
    state: generateRandomState(),
  });
  res.redirect(authUrl);
});

Token Refresh

// Call when you get 401 from your API
const newTokens = await client.refreshToken(req.session.refreshToken);
req.session.accessToken = newTokens.accessToken;
req.session.refreshToken = newTokens.refreshToken;

Logout

// Logout from current session
await client.revokeToken(req.session.accessToken);

// Logout from all devices
await client.revokeAllTokens(req.session.accessToken);

VK OAuth Integration

Quick Start

<!DOCTYPE html>
<html>
<body>
  <div id="vk-login-button"></div>

  <script type="module">
    import { initVKOAuth } from 'unologin-client/browser';

    const vkAuth = initVKOAuth({
      appId: 12345678, // Your VK App ID
      redirectUrl: 'https://unologin.ru/auth/vk/callback',
      scope: 'email',
      container: '#vk-login-button',
      showAlternativeLogin: true,
      onSuccess: (data) => {
        // Send data.access_token to your backend
        fetch('/api/auth/vk', {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ accessToken: data.access_token }),
        });
      },
      onError: (error) => {
        console.error('VK Auth Error:', error);
      },
    });

    vkAuth.renderOneTap();
  </script>
</body>
</html>

React

import { useEffect, useRef } from 'react';
import { VKOAuthClient } from 'unologin-client/browser';

function VKLoginButton() {
  const containerRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const vkAuth = new VKOAuthClient({
      appId: 12345678,
      redirectUrl: 'https://unologin.ru/auth/vk/callback',
      scope: 'email',
      onSuccess: (data) => {
        fetch('/api/auth/vk', {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ accessToken: data.access_token }),
        });
      },
      onError: (error) => console.error('VK Auth failed:', error),
    });

    if (containerRef.current) {
      vkAuth.renderOneTap(containerRef.current);
    }
  }, []);

  return <div ref={containerRef} />;
}

Vue

<template>
  <div ref="vkContainer"></div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { VKOAuthClient } from 'unologin-client/browser';

const vkContainer = ref(null);

onMounted(() => {
  const vkAuth = new VKOAuthClient({
    appId: 12345678,
    redirectUrl: 'https://unologin.ru/auth/vk/callback',
    onSuccess: (data) => console.log('Authenticated:', data),
    onError: (error) => console.error('Auth failed:', error),
  });

  vkAuth.renderOneTap(vkContainer.value);
});
</script>

API Reference

UnoLoginClient

new UnoLoginClient(config: UnoLoginConfig)

Config:

| Поле | Тип | Описание | |---|---|---| | clientId | string | ID приложения (из /oauth/client-apps) | | clientSecret | string | Секрет приложения (показывается один раз) | | redirectUri | string | Callback URL, должен быть в whitelist | | unoLoginUrl | string | Базовый URL unologin (https://...) | | businessModel | 'b2b' \| 'b2c' \| 'b2b2c' | Бизнес-модель (опционально) |

Методы:

| Метод | Описание | |---|---| | getAuthorizationUrl(options?) | URL для редиректа пользователя на логин | | exchangeCode(code) | Обмен code на { accessToken, refreshToken, user } | | refreshToken(refreshToken) | Обновление токенов | | getUserInfo(accessToken) | Полные данные пользователя (включая organization) | | introspectToken(token) | Проверка валидности токена → boolean | | revokeToken(accessToken, sessionId?) | Выход из текущей сессии | | revokeAllTokens(accessToken) | Выход со всех устройств |

getAuthorizationUrl options:

| Поле | Тип | Описание | |---|---|---| | state | string | CSRF-защита, проверяй на callback | | role | string | merchant / customer (для B2B2C) | | tenantId | string | Subdomain тенанта (для B2B2C) | | scope | string[] | Запрашиваемые scopes |


VKOAuthClient

new VKOAuthClient(config: VKOAuthConfig)

Config:

| Поле | Тип | Описание | |---|---|---| | appId | number | VK Application ID | | redirectUrl | string | Callback URL из настроек VK приложения | | scope? | string | Разрешения, например 'email' | | container? | HTMLElement \| string | Контейнер для кнопки One Tap | | showAlternativeLogin? | boolean | Показывать альтернативные методы входа | | onSuccess? | (data: VKAuthResult) => void | Колбэк успешной авторизации | | onError? | (error: any) => void | Колбэк ошибки |

Методы:

| Метод | Описание | |---|---| | init() | Инициализация VK ID SDK | | renderOneTap(container?) | Отрисовать кнопку VK One Tap | | openAuthPopup() | Открыть popup вручную | | getAuthorizationUrl(state?) | URL для серверного редиректа |


License

MIT