Forio Auth

by Jay Ma

HTML

<script src="https://getfirebug.com/firebug-lite.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://forio.com/tools/js-libs/1.5.0/epicenter.min.js"></script>

JavaScript

var authMgr = new F.manager.AuthManager();     
var sessionObj;

authMgr.login({
      account: 'hangingsteel',
      project: 'well-factory', 
      groupId: 'hangingsteel-dev-oct-2015',
      userName: 'jaytest',
      password: 'test4jay'
    }).then(function(statusObj) {
          // if enduser1 belongs to exactly one group
          // (or if the login() call is modified to include the group id)
          console.log(statusObj);
          sessionObj = authMgr.getCurrentUserSessionInfo();
          console.log(sessionObj);
          // continue here
    }.bind(this)).fail(function(statusObj) {
          // if enduser1 belongs to multiple groups, 
          // the login() call fails 
          // and returns all groups of which the user is a member
          for (var i=0; i < statusObj.userGroups.length; i++) {
              console.log(statusObj.userGroups[i].name, 			statusObj.userGroups[i].groupId);
          }
      return this.setState({ error: true });
    });