You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@milagro.apache.org by sa...@apache.org on 2016/08/05 14:19:31 UTC

[04/37] incubator-milagro-mfa-js-lib git commit: Add examples

Add examples


Project: http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/commit/c86c030e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/tree/c86c030e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/diff/c86c030e

Branch: refs/heads/add-documentation
Commit: c86c030e8f7041e893c9067bd1fae326f28bce61
Parents: f84d8c7
Author: Boyan Bakov <bo...@certivox.com>
Authored: Fri Dec 11 14:37:10 2015 +0200
Committer: Vladislav Mitov <vl...@certivox.com>
Committed: Fri Dec 18 18:55:25 2015 +0200

----------------------------------------------------------------------
 .gitignore                   |   1 -
 LICENSE                      | 202 +++++++++++++++++++++++++++++++++
 NOTICE                       |   5 +
 README.md                    |  37 +++++-
 example/exampleJquery.html   | 232 ++++++++++++++++++++++++++++++++++++++
 example/exampleNoJquery.html |  53 +++++++++
 lib/mpin.js                  | 203 +++++++++++++++++++++------------
 test/index.html              |  41 +++++++
 test/index.js                |  51 ++++++---
 9 files changed, 731 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/blob/c86c030e/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index eb737b3..18e0abb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,5 +3,4 @@ dist/
 npm-debug.log
 bower_components/
 nbproject/
-index.html
 test/coverage.html

http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/blob/c86c030e/LICENSE
----------------------------------------------------------------------
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..2f3fee9
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright 2015 MIRACL UK Ltd.
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License. 

http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/blob/c86c030e/NOTICE
----------------------------------------------------------------------
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..111f042
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,5 @@
+Apache Open MIRACL M-Pin Clients
+Copyright 2015 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/blob/c86c030e/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index c437278..337a5ce 100644
--- a/README.md
+++ b/README.md
@@ -1,19 +1,49 @@
 # MPIN frontend library
 
 
+## Requirement for build & testing
+
+1. Nodejs
+2. Grunt
+3. Mocha
+4. bower
 
 ## Installation
 ```bash
 $ git clone
 $ cd project_folder
 $ npm install
+$ grunt build
 ```
 
-## Example
+## Example simple usage:
 
 - Registration
+
+```js
+var mpin = mpinjs({server: serverIP_port});
+
+mpin.init(callback);
+
+mpin.makeNewUser(userId);
+
+mpin.startRegistration(usrId, callback);
+
+mpin.confirmRegistration(userId, callback);
+
+mpin.finishRegistration(userId, userPin);
+
+```
 - Authentication
 
+```js
+mpin.startAuthentication(userId, callback);
+
+mpin.finishAuthentication(userId, userPin, callback);
+
+```
+
+
 ## Running Tests
 
 Install development dependencies:
@@ -35,8 +65,3 @@ Actively tested with node:
 ## Authors
 
   * MIRACL Ltd.
-
-## License 
-
-(The MIT License)
-

http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/blob/c86c030e/example/exampleJquery.html
----------------------------------------------------------------------
diff --git a/example/exampleJquery.html b/example/exampleJquery.html
new file mode 100644
index 0000000..b8826cb
--- /dev/null
+++ b/example/exampleJquery.html
@@ -0,0 +1,232 @@
+<!DOCTYPE html>
+<!--
+To change this license header, choose License Headers in Project Properties.
+To change this template file, choose Tools | Templates
+and open the template in the editor.
+-->
+<html>
+  <head>
+    <title>Mpin JS SDK</title>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+		<script src="../dist/mpinjs.js" type="text/javascript"></script>
+		<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js" type="text/javascript"></script>
+	
+		<style>
+			fieldset {
+				margin: 0 auto;
+				width: 30%;
+			}
+
+			.notActivate {
+				color: red;
+				cursor: pointer;
+			}
+
+			.smallInput {
+				width: 100px;
+			}
+		</style>
+
+		<script type="text/javascript">
+      $(document).ready(function () {
+
+        //// MPIN init
+        window.mpin = mpin = new mpinjs({
+          server: "http://192.168.10.63:8005"
+        });
+
+        mpin.init(function (err, data) {
+          if (err) {
+            console.error("Wrong setup : ", err);
+          }
+
+          listUsers();
+        });
+
+        function listUsers () {
+          var mpinUsers = mpin.listUsers(), htmlList;
+
+          htmlList = "<ul>";
+          for (var i in mpinUsers) {
+            htmlList += "<li>" + mpinUsers[i].userId + "&nbsp;&nbsp;&nbsp;";
+            htmlList += "<input type='text' placeholder='PIN' size='10'>&nbsp;&nbsp;&nbsp;";
+            if (mpinUsers[i].status === "REGISTERED") {
+              htmlList += "<span class='registered' data-userid='" + mpinUsers[i].userId + "' data-status='" + mpinUsers[i].status + "'>Authenticate</span>";
+            } else {
+              htmlList += "<span class='setup' data-userid='" + mpinUsers[i].userId + "' data-status='" + mpinUsers[i].status + "'>Setup</span>";
+            }
+            htmlList += "</span></li>";
+          }
+          htmlList += "<ul>";
+
+          $("#mpinUsers").html(htmlList);
+        }
+
+
+        $(document).on('click', ".setup", function (ev) {
+          var thisElem, userId, userPin, status;
+
+          thisElem = $(ev.currentTarget);
+          userId = thisElem.data('userid');
+          userPin = thisElem.prev("input").val();
+          status = thisElem.data('status');
+
+          mpin.startRegistration(userId, function (err3, data3) {
+            mpin.confirmRegistration(userId, function (err, data) {
+              if (err) {
+                console.error("Error :1::", err);
+                return;
+              }
+
+              var finish = mpin.finishRegistration(userId, userPin);
+              if (finish.error) {
+                console.error("Error :::", finish.error);
+                return;
+              }
+
+              thisElem.append(" :: Successful");
+            });
+
+          });
+
+        });
+
+
+        $(document).on('click', ".registered", function (ev) {
+          var userId, userPin, status;
+          userId = $(ev.currentTarget).data('userid');
+          userPin = $(ev.currentTarget).prev("input").val();
+          status = $(ev.currentTarget).data('status');
+
+          mpin.startAuthentication(userId, function (err, data) {
+            if (err) {
+              console.error("Error :::", err);
+              return;
+            }
+
+            mpin.finishAuthentication(userId, userPin, function (err2, data2) {
+              if (err2) {
+                console.error("Error :::", err2);
+                return;
+              }
+
+              $(ev.currentTarget).append(" :: Successful");
+            });
+          });
+        });
+
+
+        $("#regButton").click(function (ev) {
+          var usrId;
+          usrId = $("#mpinUsrId").val();
+
+          if (usrId) {
+            mpin.makeNewUser(usrId);
+            mpin.startRegistration(usrId, function (err, data) {
+              if (err) {
+                return console.error("startRegistration error :::", err);
+              }
+              chkUser(usrId);
+            });
+          }
+
+          ev.stopPropagation();
+        });
+
+
+
+        function chkUser (userId) {
+          var userStatus = mpin.getUser(userId, "status");
+
+          mpin.confirmRegistration(userId, function (err, data) {
+            //not Active Identity
+            var userElem = $(".usrId[data-userid='" + userId + "']");
+            if (err) {
+              if (userElem.length === 0) {
+                $("#mpinUsersList").append("<li><span class='usrId notActivate' data-userid='" + userId + "'>" + userId + "</span>&nbsp;&nbsp;&nbsp;<input class='smallInput' type='text' placeholder='user Pin'></li>");
+              }
+              return;
+            }
+
+            if (userElem.length === 0) {
+              $("#mpinUsersList").append("<li><span class='usrId notActivate' data-userid='" + userId + "'>" + userId + "</span>&nbsp;&nbsp;&nbsp;<input class='smallInput' type='text' placeholder='user Pin'></li>");
+            }
+
+            var usrPin = userElem.next("input").val();
+            console.log("usrPin :::", usrPin);
+            if (usrPin) {
+              var finish = mpin.finishRegistration(userId, usrPin);
+              if (!finish.error) {
+                userElem.removeClass("notActivate");
+
+                userElem.next("input").remove();
+                userElem.append("&nbsp;&nbsp;&nbsp;>> SETUP DONE");
+
+              } else {
+                console.error("::: OPs something goes wrong.", finish.error);
+              }
+            }
+//						var final = mpin.finishRegistration(userId, 1234);
+            console.log(".: done CONFIRM registration. NOW FINISH");
+          });
+        }
+
+        //live bind click for setup user
+        $(document).on('click', '.usrId', function (ev) {
+          var usrId;
+          usrId = $(this).data('userid');
+
+          chkUser(usrId);
+
+          ev.stopPropagation();
+        });
+
+
+        //// Mobile auth
+        $("#waitMobile").click(function () {
+          var totalTime, requestTime;
+          totalTime = $("#totalTime").val() || 30;
+          requestTime = $("#requestTime").val();
+
+          mpin.getAccessNumber(function (err, data) {
+            $("#mobileStatus").append("Access number: &nbsp;" + data.accessNumber + "<br>");
+            mpin.waitForMobileAuth(totalTime, requestTime, function (err, data) {
+              if (err) {
+                $("#mobileStatus").append(" Pending mobile authentication finish with " + err.type + "<br>");
+                return;
+              }
+              $("#mobileStatus").append(" Login successful");
+            });
+          });
+        });
+
+      });
+		</script>
+
+  </head>
+  <body>
+		<div>Mpin JS SDK </div>
+		<fieldset>
+			<legend>Mpin form:</legend>
+			<input type="text" id="mpinUsrId" placeholder="user id" >
+			<input type="submit" value="Register" id="regButton" style="float:right">
+
+			<h2>Registered users:</h2>
+
+			<div id="mpinUsers"></div>
+			<ul id="mpinUsersList"></ul>
+			<div class="mpinErrors"></div>
+		</fieldset>
+		<br><br>
+		<div style="border: 1px solid grey; margin: 0px auto; width: 50%;">
+
+			Mobile Authentication:<br>
+			<input type="text" id="totalTime" placeholder="Total time in seconds" ><br>
+			<input type="text" id="requestTime" placeholder="per request in seconds" ><br>
+
+			<input type="submit" value="Call" id="waitMobile">
+			<div id="mobileStatus"></div>
+		</div>
+  </body>
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/blob/c86c030e/example/exampleNoJquery.html
----------------------------------------------------------------------
diff --git a/example/exampleNoJquery.html b/example/exampleNoJquery.html
new file mode 100644
index 0000000..7aab9ce
--- /dev/null
+++ b/example/exampleNoJquery.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Mpinjs example</title>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+		<script src="../dist/mpinjs.js" type="text/javascript"></script>
+  </head>
+  <body>
+		<div>Mpinjs example:</div>
+
+		<span>Setup flow only</span>
+
+		<script type="text/javascript">
+      function step1 () {
+        var usrId = "test@user.de";
+        mpin.makeNewUser(usrId);
+        mpin.startRegistration(usrId, function (err, data) {
+					if (err) {
+						return ;
+					}
+          step2(usrId);
+        });
+      }
+
+      function step2 (userId) {
+        mpin.confirmRegistration(userId, function (err, data) {
+					if (err) {
+						//activate Identity error
+						return ;
+					}
+          step3(userId);
+        });
+      }
+
+      function step3 (userId) {
+        var final = mpin.finishRegistration(userId, 1234);
+				
+      }
+
+      var mpin = new mpinjs({
+        server: "http://192.168.10.63:8005"
+      });
+
+      mpin.init(function (err, data) {
+        step1();
+      });
+
+		</script>
+
+
+  </body>
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/blob/c86c030e/lib/mpin.js
----------------------------------------------------------------------
diff --git a/lib/mpin.js b/lib/mpin.js
index 879b461..39e73bf 100644
--- a/lib/mpin.js
+++ b/lib/mpin.js
@@ -1,16 +1,34 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+ 
+ http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
 var mpinjs = (function () {
-  var Mpin, Users = {}, Errors = [], Status = {};
-
-  Errors[0] = "MISSING_USERID";
-  Errors[1] = "INVALID_USERID";
-  Errors[2] = "MISSING_PARAMETERS";
-  Errors[3] = "IDENTITY_NOT_VERIFIED";
-  Errors[4] = "IDENTITY_MISSING";
-  Errors[5] = "WRONG_PIN";
-  Errors[6] = "WRONG_FLOW";
-  Errors[7] = "TIMEOUT_FINISH";
-
-  ///
+  var Mpin, Users = {}, Errors = {}, Status = {};
+
+  Errors.missingUserId = {code: 0, type: "MISSING_USERID"};
+  Errors.invalidUserId = {code: 1, type: "INVALID_USERID"};
+  Errors.missingParams = {code: 2, type: "MISSING_PARAMETERS"};
+  Errors.identityNotVerified = {code: 3, type: "IDENTITY_NOT_VERIFIED"};
+  Errors.identityMissing = {code: 4, type: "IDENTITY_MISSING"};
+  Errors.wrongPin = {code: 5, type: "WRONG_PIN"};
+  Errors.wrongFlow = {code: 6, type: "WRONG_FLOW"};
+  Errors.timeoutFinish = {code: 7, type: "TIMEOUT_FINISH"};
+
   Status.invalid = "INVALID";
   Status.start = "STARTED";
   Status.active = "ACTIVATED";
@@ -18,8 +36,8 @@ var mpinjs = (function () {
   Status.block = "BLOCKED";
 
   Mpin = function (options) {
-    if (!options || !options.settingsUrl) {
-      return new Error("Missing settings URL");
+    if (!options || !options.server) {
+      return new Error("Missing server URL");
     }
 
     this.opts = options;
@@ -30,9 +48,12 @@ var mpinjs = (function () {
   Mpin.prototype.storageKey = "mpinLib";
 
   Mpin.prototype.init = function (cb) {
-    var self = this;
+    var self = this, _initUrl;
 
-    this.request({url: this.opts.settingsUrl}, function (err, data) {
+    _initUrl = this.opts.server;
+    _initUrl += this.opts.rpsPrefix || "/rps/clientSettings";
+
+    this.request({url: _initUrl}, function (err, data) {
       if (err && cb) {
         return cb(err, null);
       }
@@ -46,7 +67,7 @@ var mpinjs = (function () {
 
   Mpin.prototype.makeNewUser = function (userId, deviceId) {
     if (!userId) {
-      return {code: 0, type: Errors[0]};
+      return Errors.missingUserId;
     }
 
     this.addToUser(userId, {userId: userId, deviceId: deviceId, status: Status.invalid});
@@ -56,12 +77,12 @@ var mpinjs = (function () {
 
   Mpin.prototype.startRegistration = function (userId, cb) {
     var _reqData = {}, self = this;
-    if (!userId || typeof userId !== "string") {
-      return cb ? cb({code: 0, type: Errors[0]}, null) : {error: 1};
+    if (!userId) {
+      return cb ? cb(Errors.missingUserId, null) : {error: 1};
     } else if (!this.checkUser(userId)) {
-      return cb({code: 1, type: Errors[1]}, null);
+      return cb(Errors.invalidUserId, null);
     } else if (!this.opts.registerURL) {
-      return cb({code: 2, type: Errors[2], message: "Missing registerURL"}, null);
+      return cb({code: Errors.missingParams.code, type: Errors.missingParams.type, message: "Missing registerURL"}, null);
     }
 
     _reqData.url = this.generateUrl("register");
@@ -90,19 +111,18 @@ var mpinjs = (function () {
   //request cs1 + cs2
   Mpin.prototype.confirmRegistration = function (userId, cb) {
     var _cs1Url = "", self = this, _userStatus;
-
-    if (!userId || typeof userId !== "string") {
-      return cb ? cb({code: 0, type: Errors[0]}, null) : {error: 0, type: Errors[0]};
+    if (!userId) {
+      return cb ? cb(Errors.missingUserId, null) : Errors.missingUserId;
     } else if (!this.checkUser(userId)) {
-      return cb({code: 1, type: Errors[1]}, null);
+      return cb(Errors.invalidUserId, null);
     } else if (!this.opts.signatureURL) {
-      return cb({code: 2, type: Errors[2], message: "Missing signatureURL option."}, null);
+      return cb({code: Errors.missingParams.code, type: Errors.missingParams.type, message: "Missing signatureURL option."}, null);
     }
 
     //started || activated
     _userStatus = this.getUser(userId, "status");
     if (_userStatus !== Status.start && _userStatus !== Status.active) {
-      return cb({code: 3, type: Errors[3]}, null);
+      return cb(Errors.wrongFlow, null);
     }
 
     //already set.
@@ -116,9 +136,9 @@ var mpinjs = (function () {
       var _cs2Url = "";
       if (err) {
         if (err.status == 401) {
-          return cb({code: 3, type: Errors[3], message: "Identity not activate."}, null);
+          return cb(Errors.identityNotVerified, null);
         } else if (err.status == 400) {
-          return cb({code: 4, type: Errors[4]}, null);
+          return cb(Errors.wrongFlow, null);
         }
       }
 
@@ -142,20 +162,20 @@ var mpinjs = (function () {
 
 
   Mpin.prototype.finishRegistration = function (userId, pin) {
-    var _user, tokenHex;
+    var _user, token;
 
-    if (!userId || typeof userId !== "string") {
-      return {error: 0, type: Errors[0]};
+    if (!userId) {
+      return Errors.missingUserId;
     }
 
     _user = this.getUser(userId);
 
     if (_user.status !== Status.active) {
-      return {code: 3, type: Errors[3]};
+      return Errors.wrongFlow;
     }
 
-    tokenHex = MPINAuth.calculateMPinToken(Users[userId].mpinId, pin, Users[userId].csHex);
-    this.addToUser(userId, {tokenHex: tokenHex, status: Status.register});
+    token = MPINAuth.calculateMPinToken(Users[userId].mpinId, pin, Users[userId].csHex);
+    this.addToUser(userId, {token: token, status: Status.register});
 
     return true;
   };
@@ -171,22 +191,22 @@ var mpinjs = (function () {
   Mpin.prototype.startAuthentication = function (userId, cb) {
     var _tp1Url, self = this, _userStatus;
 
-    if (!userId || typeof userId !== "string") {
-      return cb ? cb({code: 0, type: Errors[0]}, null) : {error: 0, type: Errors[0]};
+    if (!userId) {
+      return cb ? cb(Errors.missingUserId, null) : Errors.missingUserId;
     } else if (!this.checkUser(userId)) {
-      return cb({code: 1, type: Errors[1]}, null);
+      return cb(Errors.invalidUserId, null);
     } else if (!this.opts.timePermitsURL || !this.opts.certivoxURL) {
-      return cb({code: 2, type: Errors[2], message: "Missing timePermitsURL or/and certivoxURL option."}, null);
+      return cb({code: Errors.missingParams.code, type: Errors.missingParams.type, message: "Missing timePermitsURL or/and certivoxURL option."}, null);
     }
 
     //registered
     _userStatus = this.getUser(userId, "status");
     if (_userStatus !== Status.register) {
-      return cb({code: 3, type: Errors[3]}, null);
+      return cb(Errors.wrongFlow, null);
     }
 
     //checkUser
-    _tp1Url = this.generateUrl('permit1');
+    _tp1Url = this.generateUrl('permit1', {userId: userId});
     this.request({url: _tp1Url}, function (err, data) {
       var _signature, _tp2Url, _timePermit1, _storageUrl;
       _signature = data["signature"];
@@ -194,7 +214,7 @@ var mpinjs = (function () {
 
       self.addToUser(userId, {currentDate: data['date']});
 
-      _tp2Url = self.generateUrl('permit2');
+      _tp2Url = self.generateUrl('permit2', {userId: userId});
       _tp2Url += "&signature=" + _signature;
 
       //check cache if exist 
@@ -243,7 +263,15 @@ var mpinjs = (function () {
 
 
   Mpin.prototype.finishAuthentication = function (userId, aPin, cb) {
-    var self = this, _reqData = {};
+    var self = this, _reqData = {}, _userStatus;
+
+    //registered
+    _userStatus = this.getUser(userId, "status");
+    if (_userStatus !== Status.register) {
+      return cb(Errors.wrongFlow, null);
+    } else if (!Users[userId].timePermitHex) {
+      return cb({code: Errors.wrongFlow.code, type: Errors.wrongFlow.type, message: "Need to call startAuthentication method before this."}, null);
+    }
 
     _reqData.url = this.generateUrl("pass1");
     _reqData.type = "POST";
@@ -261,8 +289,11 @@ var mpinjs = (function () {
       // pass 2
       self.request(_req2Data, function (pass2Err, pass2Data) {
         var _req3Data = {};
+        if (pass2Err) {
+          return cb(pass2Err, null);
+        }
 
-        if (pass2Data["OTP"]) {
+        if (pass2Data && pass2Data["OTP"]) {
           delete pass2Data["OTP"];
         }
 
@@ -273,11 +304,16 @@ var mpinjs = (function () {
         self.request(_req3Data, function (authErr, authData) {
           if (authErr) {
             if (authErr.status === 401) {
-              return cb({code: 5, type: Errors[5]}, null);
+              return cb(Errors.wrongPin, null);
+            } else if (authErr.status === 410) {
+              self.addToUser(userId, {status: Status.block});
+              return cb(Errors.wrongPin, null);
+            } else {
+              return cb(Errors.wrongPin, null);
             }
           }
 
-          cb && cb(null, true);
+          cb && cb(null, authData || {});
         });
       });
     });
@@ -286,8 +322,8 @@ var mpinjs = (function () {
   Mpin.prototype.getAuthData = function (userId, aPin) {
     var _auth = {};
 
-    _auth.mpin = this.getIdentity();
-    _auth.token = Users[userId].tokenHex;
+    _auth.mpin = Users[userId].mpinId;
+    _auth.token = Users[userId].token;
     _auth.timePermit = Users[userId].timePermitHex;
     _auth.date = Users[userId].currentDate;
 
@@ -326,32 +362,36 @@ var mpinjs = (function () {
     });
   };
 
-  Mpin.prototype.waitForMobileAuth = function (timeoutSeconds, cb) {
+  Mpin.prototype.waitForMobileAuth = function (timeoutSeconds, requestSeconds, cb) {
     var self = this, _reqData = {};
     if (!this.webOTT) {
-      return cb({code: 6, type: Errors[6], message: "Need to call getAccessNumber method before this."}, null);
-    } else if (!timeoutPeriod) {
-      return cb({code: 2, type: Errors[2], message: "Missing timeout/expiration period(in seconds)."}, null);
+      return cb({code: Errors.wrongFlow.code, type: Errors.wrongFlow.type, message: "Need to call getAccessNumber method before this."}, null);
+    } else if (!timeoutSeconds) {
+      return cb({code: Errors.missingParams.code, type: Errors.missingParams.type, message: "Missing timeout/expiration period(in seconds)."}, null);
     }
 
 
-
-    this.timeoutPeriod || (this.timeoutPeriod = timeoutSeconds * 1000);
+    if (typeof this.timeoutPeriod === "undefined") {
+      this.timeoutPeriod = timeoutSeconds * 1000;
+    }
 
     _reqData.url = this.generateUrl("getaccess");
     _reqData.type = "POST";
     _reqData.data = {webOTT: this.webOTT};
 
     this.request(_reqData, function (err, data) {
+      var _requestPeriod;
       if (err) {
         if (err.status === 401 && self.timeoutPeriod > 0) {
-          self.timeoutPeriod -= 3000;
+          _requestPeriod = requestSeconds ? requestSeconds * 1000 : 3000;
+          self.timeoutPeriod -= _requestPeriod;
+
           self.intervalID2 = setTimeout(function () {
-            self.waitForMobileAuth.call(self, timeoutSeconds, cb);
-          }, 3000);
+            self.waitForMobileAuth.call(self, timeoutSeconds, requestSeconds, cb);
+          }, _requestPeriod);
           return;
         } else if (self.timeoutPeriod <= 0) {
-          cb && cb({code: 7, type: Errors[7]}, null);
+          cb && cb(Errors.timeoutFinish, null);
           return;
         }
       }
@@ -381,10 +421,10 @@ var mpinjs = (function () {
         break;
       case "permit1":
         url = this.opts.timePermitsURL + "/";
-        url += this.getIdentity();
+        url += Users[options.userId].mpinId;
         break;
       case "permit2":
-        mpData = this.fromHex(this.getIdentity());
+        mpData = this.fromHex(Users[options.userId].mpinId);
         mpin_id_bytes = MPIN.stringtobytes(mpData);
         hash_mpin_id_bytes = MPIN.HASH_ID(mpin_id_bytes);
         hash_mpin_id_hex = MPIN.bytestostring(hash_mpin_id_bytes);
@@ -437,9 +477,9 @@ var mpinjs = (function () {
   Mpin.prototype.getUser = function (userId, property) {
     var _user = {};
     if (!userId) {
-      return {code: 0, type: Errors[0]};
+      return Errors.missingUserId;
     } else if (!this.checkUser(userId)) {
-      return {code: 1, type: Errors[1]};
+      return Errors.invalidUserId;
     }
 
     _user = {
@@ -455,9 +495,31 @@ var mpinjs = (function () {
     }
   };
 
-  //remove this
-  Mpin.prototype.getUsers = function () {
-    return Users;
+
+  Mpin.prototype.deleteUser = function (userId) {
+    var mpinData = this.getData(), delMpinId;
+
+    if (!userId) {
+      return Errors.missingUserId;
+    } else if (!this.checkUser(userId)) {
+      return Errors.invalidUserId;
+    }
+
+    delMpinId = Users[userId].mpinId;
+
+    //memory
+    delete Users[userId];
+
+    //store
+    delete mpinData.accounts[delMpinId];
+
+    //change default Identity
+    for (var mpinId in mpinData.accounts) {
+      mpinData.defaultIdentity = mpinId;
+      break;
+    }
+
+    this.storeData(mpinData);
   };
 
   Mpin.prototype.addToUser = function (userId, userProps, skipSave) {
@@ -511,9 +573,9 @@ var mpinjs = (function () {
       mpinData.accounts[mpinId].MPinPermit = upData.timePermitHex;
     }
 
-    if (upData.tokenHex) {
+    if (upData.token) {
       var mpinId = Users[userId].mpinId;
-      mpinData.accounts[mpinId].token = upData.tokenHex;
+      mpinData.accounts[mpinId].token = upData.token;
     }
 
     if (upData.status && Users[userId].mpinId) {
@@ -527,12 +589,11 @@ var mpinjs = (function () {
       mpinData.accounts[mpinId].timePermitCache = upData.timePermitCache;
     }
 
-    localStorage.setItem(this.storageKey, JSON.stringify(mpinData));
+    this.storeData(mpinData);
   };
 
-  Mpin.prototype.getIdentity = function () {
-    var mpinData = this.getData();
-    return mpinData.defaultIdentity;
+  Mpin.prototype.storeData = function (mpinData) {
+    localStorage.setItem(this.storageKey, JSON.stringify(mpinData));
   };
 
   Mpin.prototype.recover = function () {

http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/blob/c86c030e/test/index.html
----------------------------------------------------------------------
diff --git a/test/index.html b/test/index.html
new file mode 100644
index 0000000..eba574f
--- /dev/null
+++ b/test/index.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<!--
+To change this license header, choose License Headers in Project Properties.
+To change this template file, choose Tools | Templates
+and open the template in the editor.
+-->
+<html>
+  <head>
+    <title>MPin js Browser tests</title>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+		<link rel="stylesheet" media="all" href="../node_modules/mocha/mocha.css">
+		<script src="../node_modules/chai/chai.js"></script>
+		<script src="../node_modules/sinon-chai/lib/sinon-chai.js"></script>
+		<script src="../node_modules/mocha/mocha.js"></script>
+		<script src="../node_modules/sinon/pkg/sinon.js"></script>
+		<script src="../dist/mpinjs.js"></script> 
+  </head>
+  <body>
+		<!-- This is where mocha inserts the test results that are styled with the css file above -->
+		<div id="mocha"></div>
+		<!-- This is where any fixtures we need for the test will be inserted into. Naturally, we won't want to cover the mocha test results so we position this bad boy off screen. -->
+		<div id="test" style="position: fixed; top: 0; left: -99999px;"></div>
+
+		<script>
+      mocha.setup('bdd');
+
+      mocha.ui('bdd');
+      mocha.reporter('html');
+      expect = chai.expect;
+
+
+		</script>
+
+		<script src="index.js"></script> 
+		<script>
+
+      mocha.run();
+		</script>
+  </body>
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/blob/c86c030e/test/index.js
----------------------------------------------------------------------
diff --git a/test/index.js b/test/index.js
index 818368f..b5e311e 100644
--- a/test/index.js
+++ b/test/index.js
@@ -1,3 +1,22 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
 //if browser
 if (typeof require !== 'undefined') {
   var expect = require('chai').expect;
@@ -13,7 +32,7 @@ Errors[1] = "INVALID_USERID";
 Errors[2] = "MISSING_PARAMETERS";
 Errors[3] = "IDENTITY_NOT_VERIFIED";
 
-describe('# Constructor initialization without settingsUrl.', function () {
+describe('# Constructor initialization without server Url.', function () {
   it('should throw Error', function () {
     var mpin = new mpinjs();
     expect(mpin).to.be.an.instanceof(Error);
@@ -22,10 +41,10 @@ describe('# Constructor initialization without settingsUrl.', function () {
 
 //spy cases
 describe('# Normal iniatilization.', function () {
-  var mpin, spy, settingsUrl = "http://192.168.10.63:8005/rps/clientSettings";
+  var mpin, spy, serverUrl = "http://192.168.10.63:8005";
 
   before(function () {
-    mpin = new mpinjs({settingsUrl: settingsUrl});
+    mpin = new mpinjs({server: serverUrl});
     spy = sinon.spy();
 
     mpin.request = spy;
@@ -38,15 +57,15 @@ describe('# Normal iniatilization.', function () {
 
   it('should call request method with settingsUrl params', function () {
     mpin.init();
-    expect(spy.calledWith({url: settingsUrl})).to.be.true;
+    expect(spy.calledWith({url: serverUrl + "/rps/clientSettings"})).to.be.true;
   });
 });
 
 describe('# Init method > clientSettings request.', function () {
-  var mpin, settingsUrl = "http://192.168.10.63:8005/rps/clientSettings";
+  var mpin, serverUrl = "http://192.168.10.63:8005";
 
   before(function () {
-    mpin = new mpinjs({settingsUrl: settingsUrl});
+    mpin = new mpinjs({server: serverUrl});
 
     this.fakeRes = {
       requestOTP: false,
@@ -80,10 +99,10 @@ describe('# Init method > clientSettings request.', function () {
 });
 
 describe('# makeNewUser checks.', function () {
-  var mpin, settingsUrl = "http://192.168.10.63:8005/rps/clientSettings";
+  var mpin, serverUrl = "http://192.168.10.63:8005";
 
   before(function () {
-    mpin = new mpinjs({settingsUrl: settingsUrl});
+    mpin = new mpinjs({server: serverUrl});
   });
 
   after(function () {
@@ -103,10 +122,10 @@ describe('# makeNewUser checks.', function () {
 });
 
 describe('# startRegistration.', function () {
-  var mpin, settingsUrl = "http://192.168.10.63:8005/rps/clientSettings";
+  var mpin, serverUrl = "http://192.168.10.63:8005";
 
   before(function () {
-    mpin = new mpinjs({settingsUrl: settingsUrl});
+    mpin = new mpinjs({server: serverUrl});
 
     this.fakeRes = {
       requestOTP: false,
@@ -166,10 +185,10 @@ describe('# startRegistration.', function () {
 
 
 describe('# confirmRegistration.', function () {
-  var mpin, settingsUrl = "http://192.168.10.63:8005/rps/clientSettings";
+  var mpin, serverUrl = "http://192.168.10.63:8005";
 
   before(function () {
-    mpin = new mpinjs({settingsUrl: settingsUrl});
+    mpin = new mpinjs({server: serverUrl});
 
     this.fakeRes = {
       requestOTP: false,
@@ -274,12 +293,12 @@ describe('# confirmRegistration.', function () {
       });
     });
   });
-  
-  
+
+
 
 });
 
 
-describe('# confirmRegistration.', function () { 
-  
+describe('# confirmRegistration.', function () {
+
 });
\ No newline at end of file