pixellaboratory-auth-js-client
v0.1.0
Published
Authentication js client
Downloads
4
Readme
Authentication JS Client
OAuth2 js client for auth-server
Usage
Into browser
<script type="text/javascript" src="dist/client.js"></script>
<script type="text/javascript">
var client = new AuthClient({
clientId: 'auth-server',
clientSecret: 'the-secret-key',
urls: {
authorize: 'https://auth.com/authorize',
validate: 'https://auth.com/validate',
refresh: 'https://auth.com/refresh'
}
});
client.authorize('foo', 'bar').then(success).catch(error);
client.validate('foo', 'bar').then(success).catch(error);
client.token; //the token
</script>
Into nodejs application
const { createApp, createServer } = require('yion');
const { authentication, authenticated, authController, authConfig } = require('./src');
const app = createApp();
const server = createServer(app);
authConfig.AUTH_URL_AUTHORIZE = 'http://auth.com/authorize';
authConfig.AUTH_URL_VALIDATE = 'http://auth.com/validate';
authConfig.AUTH_CLIENT_ID = 'auth-server';
authConfig.AUTH_CLIENT_SECRET = 'my-secret-key';
app.use(authentication); // middleware handle authentication
app.get('/login', authController.login);
app.get('/', (req, res) => {
const token = req.attributes['access_token'] || {};
res.json(token);
});
app.use(authenticated); // middleware check if user is authenticated
app.get('/admin', (req, res) => {
res.send('Hello admin');
});
server.listen(8080);
Example work with yion framework
Documentation
make doc