@teleology/oauth2-lib
v0.0.12
Published
A oauth2-lib
Downloads
4
Readme
@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);