{"id":462,"date":"2010-02-08T08:57:29","date_gmt":"2010-02-08T08:57:29","guid":{"rendered":"http:\/\/bar-solutions.com\/weblog\/?p=462"},"modified":"2010-02-08T08:57:29","modified_gmt":"2010-02-08T07:57:29","slug":"","status":"publish","type":"post","link":"https:\/\/blog.bar-solutions.com\/?p=462","title":{"rendered":"Custom Authentication Scheme In APEX"},"content":{"rendered":"<p>I have been playing around with <a title=\"Oracle Application Express\" href=\"http:\/\/apex.oracle.com\/\" target=\"_blank\" rel=\"nofollow\">Apex<\/a> 4.0 on <a href=\"http:\/\/tryapexnow.com\">http:\/\/tryapexnow.com<\/a>.  When playing around with some ideas I have for application I decided to use the logging mechanism I created a while ago, to see what\u2019s going on in the custom code.<br \/>\nSince this is a hosted environment it is not too easy to check the records in the log. There were a couple of queries needed to check the log. I usually run these from my IDE, but the is not possible now. They can be easily run using the SQL Workshop, but I have APEX at my disposal. So why not create a simple application to display the information in the log table. But if I create an application and start using it, it becomes publicly available and everybody can see what\u2019s being logged (including the values of parameters). I need some sort of authentication here.<br \/>\n<!--more--><br \/>\nLuckily APEX provides the possibility to add your own authentication schemes. Since I am running this on a hosted environment I cannot use \u2018Database\u2019 or \u2018Database Account\u2019. So I need to create my own, custom authentication. This is described in detail in the book Pro Oracle Application Express especially in chapter 3 . So I decided to follow the steps here.<\/p>\n<p>The steps include examples of creating a user table and a custom authorization function in a package. It also includes some pointers on how to handle passwords. I did everything exactly as described in the book, changed the authorization scheme to the newly created one and tried to log in to my application. But it failed. Even with the correct credentials. What is going on here? Must be something I did wrong. Let\u2019s try to create the schema again (dispose of the \u2018old\u2019 one) and now follow all the steps in the wizard.<br \/>\nIn the book they said to create the scheme from here (with minimal information) and then change the properties later. But I want to go through the entire wizard so I decided to click the \u2018Next>\u2019 button.<br \/>\nThe 6th page of the wizard is where the real action takes place. I want to use my own custom function to authenticate the session.<br \/>\nThe function should return a boolean and take username and password as input.<br \/>\nThe function is declared in the package as follows:<\/p>\n<p>FUNCTION authenticate(p_username IN VARCHAR2<br \/>\n                     ,p_password IN VARCHAR2) RETURN BOOLEAN;Now it\u2019s time to test the new scheme. Change the current authorization scheme to the one just created.<br \/>\nThen try to run the application again.<br \/>\nLogin with some faulty credentials and notice that I am not authenticated.<br \/>\nWhen trying to login with correct credentials I am allowed access to the application.<\/p>\n<p>Now what is the difference between this authorization scheme and the one I created earlier. I think it has something to do with the session not valid part of the authentication. When I created it by filling in just the name and the description of the scheme it used the \u2013BUILTIN- \u2018Not Valid URL\u2019. In my new scheme it says here to use the login page instead. It seems that did the trick. Checking the Application Express scheme shows me roughly the same settings. I think I nailed this one. It took me a lot of time and I want to thank my friends <a title=\"Jornica\" href=\"http:\/\/jornica.blogspot.com\" rel=\"nofollow\" target=\"_blank\">Jorrit<\/a> and <a title=\"Notes on Oracle\" href=\"http:\/\/nuijten.blogspot.com\" rel=\"nofollow\" target=\"_blank\">Alex<\/a> for helping me where they could (although they had not needed this yet) especially where to look or provide me with more documentation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have been playing around with Apex 4.0 on http:\/\/tryapexnow.com. When playing around with some ideas I have for application I decided to use the logging mechanism I created a while ago, to see what\u2019s going on in the custom code. Since this is a hosted environment it is not too easy to check the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,2,5],"tags":[],"class_list":["post-462","post","type-post","status-publish","format-standard","hentry","category-apex","category-oracle","category-plsql"],"_links":{"self":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/posts\/462","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=462"}],"version-history":[{"count":1,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/posts\/462\/revisions"}],"predecessor-version":[{"id":463,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/posts\/462\/revisions\/463"}],"wp:attachment":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}