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

0.0.12 • Public • Published

@teleology/oauth2-lib

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

Usage

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
oauth2.token(req);

// Used to authorize via page redirection 
oauth2.authorize(req);

// Allow a request to provide information about a token
oauth2.introspection(req);

Library Links

External References

Readme

Keywords

none

Package Sidebar

Install

npm i @teleology/oauth2-lib

Weekly Downloads

0

Version

0.0.12

License

MIT

Unpacked Size

100 kB

Total Files

73

Last publish

Collaborators

  • icarus-sullivan