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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@telicent-oss/fe-auth-lib

v1.0.0

Published

OAuth2 client library for Telicent Authentication Server

Readme

@telicent-oss/fe-auth-lib

License Node Version

OAuth2 client library for Telicent Authentication Server

Browser-based OAuth2 Authorization Code + PKCE client. Supports both same-domain (cookie-based) and cross-domain (header-based) authentication.

Background

This library implements OAuth2 Authorization Code flow with PKCE for browser applications. It handles login redirects, callback processing, session management, and authenticated API requests.

The library detects whether the application and auth server share a domain (e.g., app.telicent.localhost and auth.telicent.localhost) or operate cross-domain (e.g., localhost:3000 and auth.telicent.localhost). Based on this detection, it uses cookies or Authorization headers for authentication.

Architecture Overview

┌─────────────────────────────────────────────────────────────────────────┐
│                              Browser Environment                         │
├─────────────────────────────────────────────────────────────────────────┤
│  ┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐     │
│  │   Application   │    │   fe-auth-lib   │    │  Redirect Page  │     │
│  │                 │◄──►│                 │◄──►│                 │     │
│  │  - Business     │    │  - OAuth Client │    │  - Callback     │     │
│  │    Logic        │    │  - Session Mgmt │    │    Handler      │     │
│  │  - UI/UX        │    │  - API Wrapper  │    │  - Token Proc   │     │
│  └─────────────────┘    └─────────────────┘    └─────────────────┘     │
└─────────────────────────────────────────────────────────────────────────┘
           │                       │                       │
           │ ┌─────────────────────┼───────────────────────┼─────────┐
           │ │               OAuth Flow                    │         │
           ▼ ▼                     ▼                       ▼         ▼
┌─────────────────────────────┐              ┌─────────────────┐
│        Auth Server          │◄────────────►│   API Server    │
│                             │              │                 │
│  - Login UI                 │              │  - Protected    │
│  - OAuth Engine             │              │    Endpoints    │
│  - Session Creation         │              │  - Session      │
│  - Token Management         │              │    Check        │
│                             │              │                 │
│  ┌─────────────────────────┐ │              └─────────────────┘
│  │      Database           │ │
│  │                         │ │
│  │  ┌─────────────────┐    │ │
│  │  │   Client Config │    │ │
│  │  │   - clientId    │    │ │
│  │  │   - scopes      │    │ │
│  │  │   - redirects   │    │ │
│  │  └─────────────────┘    │ │
│  │  ┌─────────────────┐    │ │
│  │  │   User Sessions │    │ │
│  │  │   - session_id  │    │ │
│  │  │   - user_data   │    │ │
│  │  │   - expiry      │    │ │
│  │  └─────────────────┘    │ │
│  └─────────────────────────┘ │
└─────────────────────────────┘

Flow

  1. Application initializes client with configuration
  2. Client checks for existing session
  3. User redirects to auth server for login
  4. Auth server authenticates user
  5. Auth server redirects back with authorization code
  6. Client exchanges code for tokens and creates session
  7. API requests include session credentials automatically
  8. Client validates and refreshes session as needed

Authentication Modes

Same-Domain: Applications on the same domain (*.telicent.localhost) use secure cookies. Sessions are included in requests automatically.

Cross-Domain: Applications on different domains use Authorization headers with session tokens. The library stores tokens and includes them in cross-domain requests.

Install

npm install @telicent-oss/fe-auth-lib

or

yarn add @telicent-oss/fe-auth-lib

Usage

Setup

import AuthServerOAuth2Client from '@telicent-oss/fe-auth-lib';

const authClient = new AuthServerOAuth2Client({
  authServerUrl: 'http://auth.telicent.localhost',
  clientId: 'spa-client',
  redirectUri: window.location.origin + '/callback.html',
  scope: 'openid email profile offline_access'
});

Login

// Redirect to auth server
await authClient.login();

Handle Callback

// In callback page
try {
  const sessionData = await authClient.handleCallback();
  window.location.href = '/dashboard';
} catch (error) {
  console.error('Callback failed:', error);
}

Check Authentication

const isAuthenticated = await authClient.isAuthenticated();
if (isAuthenticated) {
  const userInfo = authClient.getUserInfo();
  console.log('User:', userInfo.email);
}

Authenticated Requests

const response = await authClient.makeAuthenticatedRequest(
  'http://api.telicent.localhost/data'
);
const data = await response.json();

Logout

await authClient.logout();

Popup Login

await authClient.loginWithPopup();

window.addEventListener('oauth-success', (event) => {
  console.log('Authenticated:', event.detail);
});

Schema Validation

import { GetUserInfoSchema } from '@telicent-oss/fe-auth-lib/schemas';

const validatedUserInfo = GetUserInfoSchema.parse(userData);

API

See API_REFERENCE.md and INTEGRATION_GUIDE.md.

Methods

  • login(redirectUri?) - Redirect to auth server
  • loginWithPopup(redirectUri?, features?) - Open auth in popup
  • handleCallback(callbackParams?) - Process OAuth callback
  • isAuthenticated() - Check session validity
  • getUserInfo() - Get user info from ID token (validated with Zod schema)
  • getUserInfoFromAPI() - Fetch fresh user info from auth server
  • makeAuthenticatedRequest(url, options?) - Make authenticated request
  • logout() - Destroy session

Configuration

interface AuthServerOAuth2ClientConfig {
  clientId?: string;              // OAuth2 client ID
  authServerUrl?: string;         // Auth server base URL
  redirectUri?: string;           // OAuth callback URI
  popupRedirectUri?: string;      // Popup callback URI
  scope?: string;                 // OAuth2 scopes
  onLogout?: () => void;          // Logout callback function
}

Related Repositories

Definitions

  • PKCE - Proof Key for Code Exchange, OAuth2 security extension for public clients
  • Same-domain - Client and auth server share parent domain (e.g., *.telicent.localhost)
  • Cross-domain - Client and auth server on different domains
  • ID Token - JWT containing user identity claims, cached locally
  • Session Token - Opaque token for cross-domain authentication via Authorization header