🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@avanio/auth-header

Package Overview
Dependencies
Maintainers
3
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@avanio/auth-header

Typescript/Javascript http auth header utils

0.0.5
latest
Source
npm
Version published
Maintainers
3
Created
Source

@avanio/auth-header

Typescript/Javascript http auth header class and parser.

Package includes:

  • Type: AuthHeaderLikeString - type and type guard for string that this might look like http auth header
  • Type: AuthHeaderString - type and type guard for string that is http auth header
  • Type: AuthHeaderObject - type and type guard for object that have auth type and credentials
  • Type: AuthHeaderType - type and type guard for string that is http auth header type
  • Type: AuthHeaderCredentials - type and guard for string that is http auth header credentials
  • Class: AuthHeader - class that represents http auth header and implements AuthHeaderObject
  • Class: AuthHeaderError - class that represents http auth header errors
  • Function: getAuthString - function that returns normalized auth header string
  • Function: getAuthType - function that returns normalized auth header type
  • Function: getAuthCredentials - function that returns auth header credentials
  • Function: getAuthObject - function that returns AuthHeaderObject

examples

Handle both raw jwt token string and http bearer jwt token string

import {AuthHeader, isAuthHeaderLikeString} from '@avanio/auth-header';

function handleBearerToken(rawTokenOrAuthBearer: string): void {
	const currentToken: string | AuthHeader = isAuthHeaderLikeString(rawTokenOrAuthBearer) ? AuthHeader.fromString(rawTokenOrAuthBearer) : rawTokenOrAuthBearer;
	// if this is AuthHeader we are only interested Bearer tokens
	if (currentToken instanceof AuthHeader && currentToken.type !== 'BEARER') {
		throw new Error('token header: wrong authentication header type');
	}

	const token: string = currentToken instanceof AuthHeader ? currentToken.credentials : currentToken;
	// do validate token
}

Keywords

http

FAQs

Package last updated on 29 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts