This is a public Forum  publicRSS

Topic

    Pramod Vasudeva Murthy
    Agent Authentication in Custom scriptAnswered
    Topic posted February 10, 2018 by Pramod Vasudeva MurthyElite 
    100 Views, 3 Comments
    Title:
    Agent Authentication in Custom script
    Content:

    Hi Folks,

    I have a requirement to upload Contact and Incident at once. Hence, I am developing a custom script. Let me define how I am doing it:

    • I have a login page where User enters username and password(Staff Account).
    • Once submitted, I am capturing those credentials as $_POST variable and passing them to initConnectAPI() as initConnectAPI($username, $password).
    • In the authenticated page, I have another form where an agent can upload CSV.

    The problem here is after the agent has uploaded the form and clicked submit, $_POST is expiring and hence the initConnectAPI() also.

    So, in summary, my question is:

    • Is there a way to authenticate an Agent in a script by accepting username/password?
    • Is there a way to make a part of page stable w/o refreshed?

    TIA,

    ~VIP

     

    Version:
    17D
    Code Block:

    Best Answer

    Gursimran Singh Saini

    We did it with two custom scripts. Urgent requirement, so couldn't really optimise.

    Script 1: upload_login.php
    $account = AgentAuthenticator::authenticateCredentials('<API Account Username>','<API Account password>');
    <form method = "POST" action = "https://<interface-name>.custhelp.com/cgi-bin/<site-name>.cfg/php/custom/upload_page.php">
    Username and password input fields in the Form.

     

    Script 2: upload_page.php
    $username = $_REQUEST['username_field'];
    $password = $_REQUEST['password_field'];
    $account = AgentAuthenticator::authenticateCredentials($username, $password, "scripts/custom/upload_login.php", INCLUDE_REDIRECT_PAGE);

    Answer

     

    • Gursimran Singh Saini

      We did it with two custom scripts. Urgent requirement, so couldn't really optimise.

      Script 1: upload_login.php
      $account = AgentAuthenticator::authenticateCredentials('<API Account Username>','<API Account password>');
      <form method = "POST" action = "https://<interface-name>.custhelp.com/cgi-bin/<site-name>.cfg/php/custom/upload_page.php">
      Username and password input fields in the Form.

       

      Script 2: upload_page.php
      $username = $_REQUEST['username_field'];
      $password = $_REQUEST['password_field'];
      $account = AgentAuthenticator::authenticateCredentials($username, $password, "scripts/custom/upload_login.php", INCLUDE_REDIRECT_PAGE);

    • Pramod Vasudeva Murthy

      Thanks for sharing this,

      Suppose after login I have another form and upon submit $_POST variables change and hence this gets invalidated. In that case what to do?

      Let me illustrate in this document:

      My ultimate question is how to retain the values of $_POST after form is submitted.

      ~VIP

      Test.docx (52KB)
    • Pramod Vasudeva Murthy

      I achieved this requirement using all the form elements in a single page.

      Marking Gurusimran's post as Correct one as he pointed me in the right direction!
      ~VIP