Stormz

Developer


Examples

Get token via Resource Owner Password Credentials Grant flow and return the current user

Install packages stormz and simple-oauth2.

npm install --save stormz simple-oauth2

The following code will create a token via the user credentials (email and password) and fetch the user infos.

const Stormz = require('stormz');
// Set the configuration settings
const credentials = {
  client: {
    id: '',
    secret: ''
  },
  auth: {
    tokenHost: 'https://stormz.me'
  }
};
const oauth2 = require('simple-oauth2').create(credentials);
// Get the access token object.
const tokenConfig = {
  username: '',
  password: ''
};

oauth2.ownerPassword.getToken(tokenConfig, (error, result) => {
  if (error) {
    return console.log('Access Token Error', error.message);
  }

  const token = oauth2.accessToken.create(result);
  var stormz = new Stormz(token.token.access_token);
  
  stormz.get('/v1/user/me').on('complete', function(data, response) {
    console.log('complete', response.statusCode, data);
  });
});