Integrating a Login Macro

Top  Previous  Next

Let's suppose you need to authenticate a user into a connection host. To do that you need a macro that positions the cursor in the username and password fields and enters the right credentials. Let's suppose our username is "peter" and his password is "peterPass".

You can send these values in the z/Scope Anywhere URL query string by adding them like this:

 

 

http://127.0.0.1:8023/asp/?_userid=....&_apikey=...&start=MyConnection&_asuser=peter&_aspass=peterPass

 

The _asuser and _aspass values will be available inside the z/Scope Anywhere macros. That way you can use them to authenticate against the connection  host. Follow the next steps to learn how to use these values to perform the host authentication:

 

1. Record the Macro:

 

You can start by recording a macro that performs the host login.

Find out on the Programming Reference for Macros how to edit the macro after you've created it.

You will see that the macro code will look like this:

 

(function() {

   var display = getDisplay();

   step1 = function() {

        display.type("peter");

        display.setField("R4C47","YEgY8gNCpoKU2zX-fky...");

         display.cursorPos = 295;

         display.pressAndWait("ENTER");

   }

   display.addNavigationPath(this, null, null, step1);

})();

 

 

2. Modify the Macro to Work with All Users:

 

You know that this macro is now running for the user "peter" only, but you need it to be generalized for all users.

The way to modify this macro to use the variables "_asuser" and "_aspass" is by replacing the methods type and setField, as follows:

 

1) display.type("peter") => display.typeV("_asuser")

 

2) display.setField("R4C47","YEgY8gNCpoKU2zX-tfky...") => display.setFieldV("R4C47","_aspass")

 

 

The "v" methods will use the query string variable values. You can check further documentation regarding the typeV and setFieldV methods.

The updated macro should look like this:

 

(function() {

   var display = getDisplay();

   step1 = function() {

        display.typeV("_asuser");

        display.setFieldV("R4C47","_aspass");

         display.cursorPos = 295;

         display.pressAndWait("ENTER");

   }

   display.addNavigationPath(this, null, null, step1);

})();

 

 

3. Take the Macro to the Public Directory

 

All the macros are created by default on the user directory. In order to make the macro available to all users, you have to move it from the user directory to one directory level above. Copy the login macro you have just created:

 

from C:\ProgramData\Cybele Software\zScope7\[UserName] to C:\ProgramData\Cybele Software\zScope7\

 

 

4. Configure the Connection to Auto Start the Macro:

 

If you want the connection to automatically perform the authentication every time it is started, you should set this macro to be autostarted on the Connection Preferences tab.

 

 

Read More:

Apikey
Diffie Hellman Key Exchange
Building the Query String
Using z/Scope Anywhere In-Memory Dictionary
C# External Authentiation Demo
Web Authentication Provider
Macro Script File Structure
Macro Programming Reference