Friday, June 8, 2018

APEX 18.1: Generate URL checksum outside APEX session

As a follow up to my previous blog post about APEX sessions, there's one more thing that you can do now (in APEX 18.1) by using apex_session package - generate checksum for URLs created outside APEX session - for example in some email notifications created in a DB job.

First of all you need to enable Deep Linking (go to the Application Properties > Security > Session Management and set Deep Linking to Enabled). You can learn more about deep linking in the documentation.

Also, you have to enable Session State Protection for the item that you want to set in URL (in my case P2_DEPTNO):


Before generating URL you have to create session:
begin
  apex_session.create_session(105,1,'MGORICKI');
end;
/
As I said in my previous blog post, to use any of the procedures from the apex_session package you have to run them as application parsing schema, one of schemas assigned to the workspace or one of the users with APEX_ADMINISTRATOR_ROLE role.

After that you should be able to create URL with the checksum by calling apex_page.get_url function:
MGORICKI@db12c.local> begin
  2    dbms_output.put_line(
  3      apex_page.get_url (
  4      p_application => 105,
  5      p_page        => 2,
  6      p_items       => 'P2_DEPTNO',
  7      p_values      => '10') 
  8    );
  9  end;
 10  /
f?p=105:2:::NO::P2_DEPTNO:10

MGORICKI@db12c.local> exec apex_session.create_session(105,1,'MGORICKI');
PL/SQL procedure successfully completed.

MGORICKI@db12c.local> begin
  2    dbms_output.put_line(
  3      apex_page.get_url (
  4      p_application => 105,
  5      p_page        => 2,
  6      p_items       => 'P2_DEPTNO',
  7      p_values      => '10') 
  8    );
  9  end;
 10  /
f?p=105:2:10768192845699::NO::P2_DEPTNO:10&cs=1oFPSPIwCRBbRJ-gn0limWuA1XoCpqism6d38e0-EDXXNyZ8HKLmoJjZNBY7P_rGEL94hPmaZWw1skLp84bPqlg

Enjoy!