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

@abapify/browser-auth

v0.3.6

Published

Browser-based SSO authentication core - shared logic for Playwright/Puppeteer plugins

Readme

@abapify/browser-auth

version

Core browser-based SSO authentication logic for SAP ADT systems. This package provides the shared authentication flow used by browser-specific adapters like Playwright and Puppeteer.

Note: This is a low-level package. Most users should use @abapify/adt-playwright or @abapify/adt-puppeteer instead.

Architecture

@abapify/browser-auth (this package)
├── BrowserAdapter interface
├── Event-driven auth flow
├── Cookie utilities
└── Pattern matching
    ↑
@abapify/adt-playwright ─────┐
    └── Playwright adapter   │
                             ├── Implement BrowserAdapter
@abapify/adt-puppeteer ──────┘
    └── Puppeteer adapter

Installation

npm install @abapify/browser-auth

Usage

This package is primarily used by browser adapter implementations. Direct usage:

import {
  authenticate,
  testCredentials,
  toCookieHeader,
} from '@abapify/browser-auth';
import type { BrowserAdapter } from '@abapify/browser-auth';

// Create your browser adapter (see BrowserAdapter interface)
const adapter: BrowserAdapter = createMyAdapter();

// Authenticate
const credentials = await authenticate(adapter, {
  url: 'https://sap-system.example.com',
  headless: false,
  userDataDir: true,
  requiredCookies: ['SAP_SESSIONID_*', 'sap-usercontext'],
});

// Test if credentials are still valid
const result = await testCredentials(credentials);
console.log(result.valid); // true/false

// Convert to Cookie header string
const cookieHeader = toCookieHeader(credentials);
// "SAP_SESSIONID_XXX=abc123; sap-usercontext=..."

API

authenticate(adapter, options)

Performs browser-based SSO authentication.

async function authenticate(
  adapter: BrowserAdapter,
  options: BrowserAuthOptions,
): Promise<BrowserCredentials>;

Parameters:

  • adapter - Browser adapter implementing BrowserAdapter interface
  • options - Authentication options

Options:

interface BrowserAuthOptions {
  url: string; // SAP system URL
  headless?: boolean; // Hide browser (default: false)
  timeout?: number; // Login timeout in ms (default: 300000)
  userAgent?: string; // Custom user agent
  requiredCookies?: string[]; // Cookie patterns to wait for
  userDataDir?: string | boolean; // Session persistence path
  ignoreHTTPSErrors?: boolean; // Ignore SSL errors (default: true)
}

Returns: BrowserCredentials with captured cookies

testCredentials(credentials)

Tests if credentials are still valid by making a request to the SAP system.

async function testCredentials(
  credentials: BrowserCredentials,
): Promise<TestResult>;

toCookieHeader(credentials)

Converts credentials to a Cookie header string.

function toCookieHeader(credentials: BrowserCredentials): string;

toHeaders(credentials)

Creates headers object with Cookie and User-Agent.

function toHeaders(credentials: BrowserCredentials): Record<string, string>;

BrowserAdapter Interface

To create a new browser adapter, implement this interface:

interface BrowserAdapter {
  /** Launch browser and create context */
  launch(options: {
    headless: boolean;
    userDataDir?: string;
    ignoreHTTPSErrors?: boolean;
    userAgent?: string;
  }): Promise<void>;

  /** Create a new page */
  newPage(): Promise<void>;

  /** Navigate to URL */
  goto(url: string, options?: { timeout?: number }): Promise<void>;

  /** Get all cookies */
  getCookies(): Promise<CookieData[]>;

  /** Get user agent string */
  getUserAgent(): Promise<string>;

  /** Close the page */
  closePage(): Promise<void>;

  /** Close browser context */
  close(): Promise<void>;

  /** Register response event handler */
  onResponse(handler: (event: ResponseEvent) => void): void;

  /** Register page close handler */
  onPageClose(handler: () => void): void;
}

Cookie Pattern Matching

The requiredCookies option supports wildcard patterns:

// Wait for any SAP session cookie
requiredCookies: ['SAP_SESSIONID_*'];

// Wait for specific cookies
requiredCookies: ['SAP_SESSIONID_S0D_200', 'sap-usercontext'];

// Multiple patterns
requiredCookies: ['SAP_SESSIONID_*', 'MYSAPSSO2', 'sap-usercontext'];

Utility Functions

import { matchesCookiePattern, cookieMatchesAny } from '@abapify/browser-auth';

// Check single pattern
matchesCookiePattern('SAP_SESSIONID_S0D_200', 'SAP_SESSIONID_*'); // true

// Check multiple patterns
cookieMatchesAny('SAP_SESSIONID_S0D_200', ['MYSAPSSO2', 'SAP_SESSIONID_*']); // true

Types

interface CookieData {
  name: string;
  value: string;
  domain: string;
  path: string;
  expires?: number;
  httpOnly?: boolean;
  secure?: boolean;
  sameSite?: 'Strict' | 'Lax' | 'None';
}

interface BrowserCredentials {
  baseUrl: string;
  cookies: CookieData[];
  authenticatedAt: Date;
  userAgent?: string;
}

interface TestResult {
  valid: boolean;
  error?: string;
  responseTime?: number;
}

Creating a New Adapter

Example: Creating a Selenium adapter

import type {
  BrowserAdapter,
  CookieData,
  ResponseEvent,
} from '@abapify/browser-auth';
import { Builder, Browser } from 'selenium-webdriver';

export function createSeleniumAdapter(): BrowserAdapter {
  let driver: WebDriver | null = null;
  const responseHandlers: ((event: ResponseEvent) => void)[] = [];

  return {
    async launch(options) {
      driver = await new Builder().forBrowser(Browser.CHROME).build();
    },

    async newPage() {
      // Selenium uses single page model
    },

    async goto(url, options) {
      await driver?.get(url);
    },

    async getCookies(): Promise<CookieData[]> {
      const cookies = await driver?.manage().getCookies();
      return (
        cookies?.map((c) => ({
          name: c.name,
          value: c.value,
          domain: c.domain || '',
          path: c.path || '/',
          expires: c.expiry?.getTime(),
          httpOnly: c.httpOnly,
          secure: c.secure,
        })) || []
      );
    },

    // ... implement remaining methods
  };
}

Related Packages