A oauth2-lib

Usage no npm install needed!

<script type="module">
  import teleologyOauth2Lib from 'https://cdn.skypack.dev/@teleology/oauth2-lib';



An off-the-shelf server implementation for OAuth2 authentication.


The OAuth2 lib needs to be initialized with some configuration options before we continue, however the general shape of the result api is outlined below.

const jwt = require('jsonwebtoken');
const oauth2_lib = require('@teleology/oauth2-lib').default;

const oauth2_options = {
  codeTtl: number;
  accessTokenTtl: number;
  refreshTokenTtl: number;
  createDecisionPage(req: DecisionRequest): Promise<string>;
  createCode(req: TokenRequest): Promise<Code>;
  createAccessToken(req: TokenRequest): Promise<AccessToken>;
  createRefreshToken(req: TokenRequest): Promise<AccessToken>;
  getTokenTtl(token: Token): number;
  getCode(code: string): Promise<Code>;
  getAccessTokenWithIds(user_id: string, client_id: string): Promise<AccessToken>;
  getAccessToken(token: string): Promise<AccessToken>;
  getRefreshToken(token: string): Promise<RefreshToken>;
  introspect(token: Token): IntrospectionResponse;
  getClient(id: string): Promise<Client>;
  validGrantType(client: Client, grant_type: string): boolean;
  validSecret(client: Client, client_secret: string): boolean;
  validScope(client: Client, scope: Scope): boolean;
  validRedirectUri(client: Client, redirect_uri: string): boolean;
  getUser(id: string): Promise<User>;
  getUserByName(username: string): Promise<User>;
  validPassword(user: User, password: string): boolean;

const oauth2 = oauth2_lib(oauth2_options);

// Used to generate tokens

// Used to authorize via page redirection 

// Allow a request to provide information about a token

Library Links

External References