New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@avanio/auth-header

Package Overview
Dependencies
Maintainers
0
Versions
4
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.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
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

FAQs

Package last updated on 28 Oct 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc