JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 14359
  • Score
    100M100P100Q143349F
  • License MIT

A runtime-agnostic OAuth 2.0 library

Package Exports

  • @oslojs/oauth2
  • @oslojs/oauth2/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@oslojs/oauth2) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@oslojs/oauth2

Documentation: https://oauth2.oslojs.dev

A small JavaScript library for parsing OAuth 2.0 token, token revocation, and device authorization responses by Oslo.

This package follows RFC 6749, RFC 7009, and RFC 8628.

  • Runtime-agnostic
  • No third-party dependencies
  • Fully typed
import { TokenRequestResult } from "@oslojs/oauth2";

const response = await fetch("https://github.com/login/oauth/access_token", {
    method: "POST",
    body,
    headers
});
const data = await response.json();
if (typeof data !== "object" || data === null) {
    throw new Error("Unexpected response");
}
const result = new TokenRequestResult(data);
if (result.hasErrorCode()) {
    const error = result.errorCode();
    throw new Error(`Request failed: ${error}`);
}
const accessToken = result.accessToken();
const accessTokenExpiresAt = result.accessTokenExpiresAt();
const refreshToken = result.refreshToken();

Installation

npm i @oslojs/oauth2