0.0.12 • Published 3 years ago

@teleology/oauth2-lib v0.0.12

Weekly downloads
75
License
MIT
Repository
gitlab
Last release
3 years ago

@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

0.0.12

3 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.5

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago