As a dependency:
npm install ls-auth-api --save
As a standalone server:
git clone https://github.com/longshot-io/auth-api && cd auth-api
npm install
As a dependency:
var Auth = require("ls-auth-api");
// Optionally, start the web API
authApi.startWebServer(1337);
authApi.login("username", "password");
As a standalone server:
// Example: npm start [portNumber]
npm start 8181
User
interface User {
username: string;
password: string;
enabled?: number; // Optional
}
register(...): Returns a promise containing the new user ID
Auth.register(user: User): Promise<number>;
login(...): Returns a promise containing the new JWT token or gets rejected
Auth.login(username: string, password: string): Promise<string>;
verify(...): Returns a promise that resolves a boolean. True if the token is valid
Auth.verify(token: string): Promise<boolean>;
startWebServer(...): Returns void
Auth.startWebServer(portNumber: number): void;
Accepts PAYLOAD:
username: string
password: string
Accepts PAYLOAD:
username: string
password: string
Accepts PAYLOAD:
token: string
MIT