Socket
Book a DemoInstallSign in
Socket

oauth_device_flow

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oauth_device_flow

OAuth 2 Device Code Flow

latest
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

OAuth2 Device Flow Client

This is a client for using OAuth2 Device Flows in applications with limited interaction possibilities.

import { DeviceFlowClient } from "oauth_device_flow";

const app = new DeviceFlowClient({
  audience: "AUDIENCE",
  client_id: "CLIENT_ID",
  scopes: ["openid", "offline_access"],
  code_url: "DEVICE_CODE_URL",
  token_url: "TOKEN_URL",
}, {
  output: (str) => console.info(str)
});

// get token interactively
app
  .acquireToken()
  .then((token) => /* ...do stuff */);

// get token silently
app
  .acquireTokenSilently()
  .then((token) => /* ...do stuff */);

Configuration

The client requires the following parameter:

/**
 * Endpoint used to fetch tokens
 * @example https://tenant.eu.auth0.com/oauth/token
 */
token_url: string;
/**
 * Endpoint used to fetch the device and user code
 * @example https://tenant.eu.auth0.com/oauth/device/code
 */
code_url: string;
/**
 * The client ID
 * You get this from your OAuth provider
 */
client_id: string;
/**
 * The requested scopes
 * Will automatically include "offline_access" if you set the "refreshToken" option
 */
scopes: string[];
/**
 * The audience for your request
 */
audience: string;

Additionally you can provide a few other options to customize your experience and implement a cache:

/**
 * Provide a cache for the token and metadata
 */
cache?: {
  /**
   * Deerialize the cache
   */
  beforeCacheAccess: () => ClientCache;
  /**
   * Serialize the cache
   */
  afterCacheAccess: (cache: ClientCache) => void;
};
/**
 * Customize the console output
 */
output?: (str: string) => void;
/**
 * Request a refresh token?
 */
refreshToken?: boolean;

Keywords

oauth

FAQs

Package last updated on 19 Dec 2021

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