README
OAuth2Server
___________ .__ ________ .__.__
\__ ___/___ ____ | |__ \_____ \ _____ ____ |__| | ____
| |_/ __ \_/ ___\| | \ / | \ / \ / \| | | _/ __ \
| |\ ___/\ \___| Y \ / | \ Y Y \ | \ | |_\ ___/
|____| \___ >\___ >___| / \_______ /__|_| /___| /__|____/\___ >
\/ \/ \/ \/ \/ \/ \/
Techflow like the Nile RiverĀ®.
About this package?
OAuth2 Server for NodeJs. Only Password and Refresh Token grant types are available now. More grant types will come soon.
Installing this package
To install library, simply run
$ npm install omnile-oauth2
Basic Usage
Authorization Server
Generating an access token:
The repositories must implement their corresponding interfaces.
const AuthorizationServer = require('omnile-oauth2');
import { ServerOptionsI, AuthPayloadI, ClientEntityI, UserEntityI } from 'omnile-oauth2';
// Server options
const options: ServerOptionsI = {
clientRepository: clients,
userRepository: users,
tokenRepository: tokens,
privateKey: pathToPrivateKey,
tokenExpiryMins: 30,
encryptionKey: 'some-strong-encryption-key'
};
// Create the authorization server
const authServer = new AuthorizationServer(options);
// A given request payload
const payload: AuthPayloadI = {
client: ClientEntityI,
grant_type: 'password', // For password grant type
user: UserEntityI
};
try{
const accessToken = await authServer.getAccessToken(payload);
}catch(e){
console.error(e);
}
Resource Server
Authenticate access token
import { ResourceServer, AuthenticatedRequestI } from 'omnile-oauth2';
const resourceServer = new ResourceServer();
const request: AuthenticatedRequestI = {
access_token: 'access-token-generated'
};
try{
const decoded = await resourceServer.validateAuthenticatedRequest(request);
}catch (e){
console.error(e);
}
Tests
Simply run the test as follows
$ npm test
Contributing
To contribute, please send us an email at technical@omnile.com.
Security
If you discover any security related issues, please email
instead of using the issue tracker.
Send emails to technical@omnile.com
Credits
Licence
How can I thank you?
Star the github repo, Share the link for this repository on Twitter or HackerNews and Spread the word!
Thanks! The Omnile Team