@oslojs/oauth2
TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

@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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.5.011,097latest

Version History

VersionDownloads (Last 7 Days)Published
0.5.011,097
0.4.00
0.3.04
0.2.00
0.1.23,832
0.1.10
0.1.028

Package Sidebar

Install

npm i @oslojs/oauth2

Weekly Downloads

12,237

Version

0.5.0

License

MIT

Unpacked Size

8.32 kB

Total Files

5

Last publish

Collaborators

  • pilcrowonpaper