RegisterLogin
DocsPricing
RegisterLogin
  • Getting Started
  • Introduction
  • Quick Start
  • SDKs
  • React
  • TypeScript
  • Next.js
  • Express
  • NestJS
  • Python
  • API Reference
  • Support and Resources
  • FAQ
  • Contact Support

AuthSafe

Product

HighlightFeatureIntegrationPricingFAQ

Company

AboutBlogContactSitemap

Developer

DashboardDocumentation

Legal

Terms & ConditionsPrivacyComplianceShippingCancellation

© 2026 AuthSafe. All rights reserved.

We value your privacy

This website uses cookies for anonymous analytics to help us improve your experience. No personal information is stored or shared. You can allow or reject analytics tracking at any time. See our Privacy Policy.

We use cookies for anonymous analytics. No personal info is stored. See our Privacy Policy.

HttpService

HTTP client wrapper for making authenticated API requests to AuthSafe endpoints.

Overview

The HttpService provides a convenient wrapper around Axios for HTTP requests with automatic Bearer token injection and error handling.
Use with API Clients
HttpService is designed to be used with API clients (MfaApi, UserApi, etc.) rather than directly. The API clients provide type-safe, structured access to AuthSafe endpoints.

Constructor

import { HttpService } from 'authsafe-ts';

const httpService = new HttpService(token?: string);
Parameters:
  • token (optional) - Access token for authentication. Automatically adds Authorization: Bearer <token> header

Methods

// GET request
await httpService.get<T>(path?: string, config?: AxiosRequestConfig): Promise<T>

// POST request
await httpService.post<T>(path: string, data?: any, config?: AxiosRequestConfig): Promise<T>

// PUT request
await httpService.put<T>(path: string, data?: any, config?: AxiosRequestConfig): Promise<T>

// PATCH request
await httpService.patch<T>(path: string, data?: any, config?: AxiosRequestConfig): Promise<T>

// DELETE request
await httpService.delete<T>(path: string, config?: AxiosRequestConfig): Promise<T>

Example Usage

Basic Usage

import { HttpService } from 'authsafe-ts';

const user = await oauthService.getUser();
const httpService = new HttpService(user?.access_token);

// Make authenticated requests
const userInfo = await httpService.get('/auth/userinfo');
const data = await httpService.post('/api/resource', { key: 'value' });

With API Clients

import { HttpService, MfaApi, UserApi } from 'authsafe-ts';

const user = await oauthService.getUser();
const httpService = new HttpService(user?.access_token);

// Create API clients
const mfaApi = new MfaApi(httpService);
const userApi = new UserApi(httpService);

// Use API clients
const methods = await mfaApi.listMethods();
await userApi.updateUser(userId, { name: 'John Doe' });

Public Endpoints (No Auth)

import { HttpService, BrandingApi } from 'authsafe-ts';

// No token needed for public endpoints
const httpService = new HttpService();
const brandingApi = new BrandingApi(httpService);

const branding = await brandingApi.getBranding(clientId);

Error Handling

401 Unauthorized

When a 401 status is received, HttpService throws an error with message "Login error".
try {
  const data = await httpService.get('/protected/resource');
} catch (error) {
  if (error.message === 'Login error') {
    // Redirect to login
    await oauthService.signinRedirect();
  }
}

Other Errors

try {
  await httpService.post('/api/action', data);
} catch (error) {
  console.error('Request failed:', error.message);
}

Configuration

HttpService is pre-configured with:
  • Base URL: import.meta.env.VITE_AUTHORITY
  • Default Headers:
    • Content-Type: application/json
    • Cache-Control: no-cache
    • Pragma: no-cache
    • Authorization: Bearer <token> (if provided)
  • Timeout: 10 seconds

Related

  • MfaApi - MFA management
  • UserApi - User management
  • SSOApi - SSO configuration
  • TypeScript SDK Overview