Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simple-oauth2-ts-client

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-oauth2-ts-client

A TypeScript OAuth 2.0 client library

  • 1.0.7
  • npm
  • Socket score

Version published
Weekly downloads
7
decreased by-58.82%
Maintainers
0
Weekly downloads
 
Created
Source

OAuth 2.0 Client Library Implementation

So for the Implementation of the Library, i have followed the specs proposed by IETF OAuth Working Group.

So Basic flow of the protocol:

OAuth2.0 Abstract Flow

Diagram

Features

It is a light weight package only has axios as its dependencies, uses web crypto which are built-in since Node 18 (but it works with Polyfills on Node 14 and 16).

It is platform agnostic which can be used in both client and server javascript environment .

Following OAuth Grant, it Supports

  • Authorization Code
  • PKCE
  • Client Credentials
  • Refresh Token
  • Legacy: Implicit Flow

Installation

Install simple-oauth2-ts-client with npm

  npm i simple-oauth2-ts-client

Usage/Examples

To get started with initialize the client with the following attributes

 const client =new OAuthClient({
      auth_server: string; //authorisation  server domain endpoint 
      client_id: string;  // provided by auth server for public client 
      client_secret?: string; // provided by auth server for confidential client 
      redirect_uri: string; // redirection uri for Authorization Code && implicit grant type
      authorization_endpoint?: string; // @default /authorize
      token_endpoint?: string; // @default /token
      authenticationMethod?: "client_secret_basic" | "client_secret_post" | "none";
 })

This client Object has following method to use for various purposes

// This will return redirection uri -->

  await client.startAuthFlow(
    params: OAuthStartAuthFlow
  ): Promise<OAuthStartAuthFlowResponse> // can be used for Authorization Code or implicit grants

// to handle successful redirection uri 

    await client.handleCallback(params: {
    uri: string;  // redirection back uri
    grant_type: OAuth2GrantType;  // use authorization_code for Authorization Code grant type
    state?: string; //   // Optional string that can be sent along to the auth server. This value will
  // be sent along with the redirect back to the app verbatim.
    code_verifier?: string; // to support PKCE 
    }): Promise<OAuth2Token> 
  
// to handle refresh token 

await client.refreshToken(
    refreshToken: string,
    params?: RefreshParams
  ): Promise<OAuth2Token> 

To generate code verifier and codeChallenge , it exports uility function to do This

await generateCodeVerifier(): Promise<string>

Keywords

FAQs

Package last updated on 22 Dec 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