Book Image

IBM Worklight Mobile Application Development Essentials

Book Image

IBM Worklight Mobile Application Development Essentials

Overview of this book

Table of Contents (15 chapters)
IBM Worklight Mobile Application Development Essentials
Credits
About the Authors
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Index

Creating adapter-based authentication


Adapter-based authentication is the simplest form of authentication provided in Worklight. It uses the adapter procedure/function to validate and authenticate the users and create their sessions. Plus, it provides all the features of the Worklight authentication framework.

Please use the following simple steps to implement adapter-based authentication:

  1. Create a new Worklight project with the name ABADemo; for the application, use the name myAdapterBasedAuthentication.

  2. Add an adapter and give it a name: myAuthAdapter. Paste the following sample function code into the adapter.js file:

    function onAuthRequired(headers, errorMessage){
      errorMessage = errorMessage ? errorMessage : null;
      return {
        authRequired: true,
        errorMessage: errorMessage
      };
    }
    
    function submitUserAuthentication(username, password){
      if (username==="adapter" && password === "adapter"){
        var userIdentity = {
          userId: username,
          displayName: username, 
         ...