Skip to main content
Skip table of contents

How to authenticate REST API calls for reactions without using plaintext passwords

Authentication details can be saved, instead of (username/password), as an authentication header in the LUY properties file. This may be used in REST API calls and reactions as well.

Requirements

  • Postman or a similar tool 

  • Access to the server on which LUY is running

  • Read and write permissions for the "luy_local.properties" 

Step-by-step guide:

Generate password string: 

  • Open Postman

  • Go to the tab "authentication" 

  • Set the "type" to "basic auth" 

  • Enter the username and password, e.g., "LUY" and "P@assw0rd"

  • Change to the tab "headers"

  • Copy the value of the key "authorization"

    • e.g., Basic c3lzdGVtOnBhc3N3b3Jk

Prepare the "luy_local.properties":

  • Open the file "luy_local.properties" 

  • Add the line "plugin.luy.authorization="

  • Insert the copied value after "="

    • Here is an example of the complete entry "plugin.luy.authorization=Basic c3lzdGVtOnBhc3N3b3Jk"

  • Restart your Tomcat  

Use the authentication header in reactions:

  • Open the reactions script in LUY

  • Edit or create the script which needs an authentication via REST

  • Add the following line "api.http.addAuthenticationHeader("plugin.luy.authorization");"

  • Now, for the authentication via basic auth on REST the set authentication header is used 

Additional option

  • To use more than one "authentication header" in LUY add additional lines in the "luy_local.propterties". 
    e.g "plugin.luy.authorizationSalesforce="

Example reaction script:
JS
'use strict';
   
api.registerExecution(httpWithAuthentication);
   
function httpWithAuthentication(){
     
    // Setting parameters for the http request
    api.http.setURL("http://localhost:8080/luy/api/element/InformationSystem/25");
    api.http.setMethod("GET");
    // The variable with an authentication header value has to be saved in one of the property files
    api.http.addAuthenticationHeader("luy.auth");
 
    // Performing the request
    var result = api.http.execute();
             
    // We can get information from the response
    api.printLog("The complete response body: " + result.getBody());
}

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.