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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ito-frontend/oneauth

v0.0.1-beta.3

Published

API for OneAD SSO

Downloads

15

Readme

OneAuthClient API Documentation

Overview

OneAuthClient is a JavaScript client for interacting with the OneAuth API. It provides methods for obtaining access tokens, redirecting users for authentication, and signing out users by invalidating their refresh tokens. The class is configured with an Axios instance, a base URL for the API, and a client ID.

Class: OneAuthClient

Constructor

constructor(config: OneAuthClientConfig)
  • Parameters:
    • config (OneAuthClientConfig): Configuration object for the client.
      • axiosInstance (AxiosInstance): Axios instance for making HTTP requests.
      • baseUrl (string): The base URL for the OneAuth API.
      • clientId (string): Client identifier for authentication.

Methods

| Method | Description | Parameters | Returns | |-------------------------|----------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------| | getOneAuthToken | Requests an access token using the authorization code. | args (object): - redirect_uri (string): Redirect URI after authorization. - grant_type ('authorization_code'): Must be 'authorization_code'. - code (string): Authorization code received. | Promise<AxiosResponse<GetOneAuthTokenResponse>> containing token data. | | redirectToOneAuth | Redirects the user to the OneAuth authentication page. | None | void | | mutateOneAuthSignOut | Signs out the user by invalidating the provided refresh token. | refreshToken (string): The refresh token to invalidate. | Promise<AxiosResponse<void>> indicating sign-out success. |

Type Definitions

GetOneAuthTokenArgs

  • redirect_uri (string): URI to redirect to after authorization.
  • grant_type ('authorization_code'): Grant type for obtaining the token.
  • code (string): Authorization code received after user login.

GetOneAuthTokenResponse

  • access_token (string): The access token for accessing resources.
  • expires_in (number): The lifetime of the access token in seconds.
  • refresh_expires_in (number): The lifetime of the refresh token in seconds.
  • refresh_token (string): The token used for refreshing the access token.
  • token_type ('Bearer'): The type of token issued.
  • id_token (string): The ID token representing the authenticated user.
  • 'not-before-policy' (number): Time before which the token is not valid.
  • session_state (string): State of the user's session.
  • scope (string): Scopes associated with the token.

OneAuthClientConfig

  • axiosInstance (AxiosInstance): Axios instance used for HTTP requests.
  • baseUrl (string): Base URL for the OneAuth API.
  • clientId (string): Client identifier for authentication.

Example Usage

import axios from 'axios';
import { OneAuthClient } from './OneAuthClient';

const axiosInstance = axios.create();
const config = {
  axiosInstance,
  baseUrl: 'https://auth.example.com',
  clientId: 'your_client_id',
};
const oneAuthClient = new OneAuthClient(config);

// Obtain an access token
oneAuthClient.getOneAuthToken({
  redirect_uri: 'https://your.redirect.uri',
  grant_type: 'authorization_code',
  code: 'received_authorization_code'
}).then(response => {
  console.log('Access Token:', response.data.access_token);
}).catch(error => {
  console.error('Failed to get access token:', error);
});

// Redirect for user authentication
oneAuthClient.redirectToOneAuth();

// Sign out the user
oneAuthClient.mutateOneAuthSignOut('user_refresh_token')
  .then(() => {
    console.log('User signed out successfully.');
  })
  .catch(error => {
    console.error('Failed to sign out:', error);
  });

Notes

  • Ensure the baseUrl parameter points to the correct OneAuth API base URL.
  • When redirecting with redirectToOneAuth, the clientId and other parameters must be configured correctly to obtain the authorization code.
  • Use secure storage mechanisms for handling sensitive data such as access tokens and refresh tokens.