Note:

Integrate Oracle APEX with Oracle Cloud Infrastructure Identity and Access Management Identity Domains

Introduction

Oracle Cloud Infrastructure Identity and Access Management (OCI IAM) provides identity and access management features such as authentication, single sign-on (SSO), and identity lifecycle management for Oracle Cloud Infrastructure as well as Oracle and non-Oracle applications, whether SaaS, cloud-hosted, or on-premises.

Objective

Prerequisites

Task 1: Install a Sample Application in Oracle APEX

  1. Log in to your APEX workspace to create a sample application for which we will use OCI IAM as an IdP for SSO. To create an application on Oracle APEX, click App Builder.

  2. Click Create Application.

    Image 1

  3. Select From a File.

    Image 2

  4. Click Copy and Paste and select Sales as shown in the following images.

    Image 3

    Image 4

Task 2: Register a Confidential Application in OCI IAM

We will register a confidential application in the OCI IAM domain. For this tutorial, we have used the default domain.

  1. Log in to the OCI Console, navigate to Identity and Security. Under Identity, click Domains and Applications.

    Picture 4

  2. Select Confidential Application and click Launch workflow.

    Picture 5

  3. Enter a Name for your application and click Next.

    Picture 6

  4. Select Authorization code as the Allowed Grant Type and click Next.

    Picture 7

  5. Enter the Redirect URL in this format: https://guid-demodb.adb.region.oraclecloudapps.com/ords/apex_authentication.callback. For example, https://guid-demodb.adb.us-ashburn-1.oraclecloudapps.com/ords/apex_authentication.callback.

  6. Enter the Post logout redirect URL in this format: https://guid-demodb.adb.region.oraclecloudapps.com/ords/f?p=your_apex_number_here.

  7. Leave the Logout URL blank.

    Note: Note down this URL, it must match exactly when added later in the Oracle APEX authentication scheme post-logout URL.

    Picture 31

  8. Click Finish.

    Picture 8

  9. Click Edit application and select Enforce grant as Authorization under Authentication and Authorization (This will be used later to control access to the Oracle APEX application).

    Picture 10

  10. Click Activate Application.

    Picture 9

  11. Copy the Client ID and Client secret which we will use in the configuration on Oracle APEX side.

    Picture 11

Task 3: Create a new Web Credential in your Oracle APEX Workspace

  1. Open Oracle APEX workspace. In your application created in Task 1, click Shared Objects.

    Picture 12

  2. Click Credentials.

    Picture 13

  3. Click Create.

    Picture 14

  4. Enter the following information and click Create.

    Note: Use the Client ID and Client Secret from the confidential application in Task 2.

    Picture 15

  5. Assign a user to this application.

    Picture 22

Task 4: Create a new Authentication Scheme in Oracle APEX for the Sample Application

  1. Open Oracle APEX workspace and click Shared Objects. Under Security, click Authentication Schemes and Create.

    Picture 16

    Picture 17

  2. Select Based on a pre-configured scheme from the gallery and click Next.

    Picture 18

  3. Enter the following information and click Create. The Discovery URL will be https://[idcs-service-url]/.well-known/openid-configuration/.

    Picture 19

  4. Click the created Oracle Identity Cloud Service (IDCS) Authentication Scheme - Current.

  5. Click Post-Logout URL tab, select Go-To and URL. In the URL, paste the Oracle APEX application URL from Task 2.6. This URL must match the IDCS post logout redirect URL.

    Picture 30

  6. Under Security Attributes, update the information and click Apply Changes.

    Picture 27

    Picture 28

  7. (Optional) In the Source section, enter the following PL/SQL code.

    Note: This is only required if you want to control authorization, in cases where we want to change the features or behavior of an application based on the groups a user belongs to. For more information, see the Controlling Authorization section at the end of this tutorial.

    procedure load_dynamic_groups as
      l_group_names apex_t_varchar2;
    begin
      --
      -- add all group names to l_group_names
      --
      for i in 1 .. apex_json.get_count('groups') loop
          apex_string.push (
            p_table => l_group_names,
            p_value => apex_json.get_varchar2 (
                           p_path => 'groups[%d].name',
                           p0     => i ));
      end loop;
      --
      -- save group names in session
      --
      apex_authorization.enable_dynamic_groups (
          p_group_names => l_group_names );
    end;
    
    

    Picture 20

  8. (Optional used for step 7) Under Login Processing, enter the following information and save.

    Picture 29

Task 5: Test Login to the Oracle APEX Application

  1. Click Run Page.

    Picture 23

  2. Enter the credentials on the prompted login screen. For this tutorial, the account used for authentication is synced from the local active directory and the password resides in the active directory. OCI IAM will collect the username and password and get them validated against active directory.

    Picture 24

  3. Click Allow.

    Picture 25

The application landing page is displayed.

Picture 26

Controlling Authorization

You can control authorization by enabling Enforce Grant as Authorization on the confidential application configured for SSO which will only allow users or groups assigned to this application to be able to access the Oracle APEX application. This is shown in Task 2.9.

The other way to control authorization is to use a PL/SQL procedure within the authentication scheme as shown in Task 4.7 and 4.8. After successful authentication, the userinfo_endpoint will be called and the results will be made available to the post-authentication procedure. The JSON results are converted to list of groups and stored in an Oracle APEX session built-in for group management, which can later be tied up with the authorization scheme under shared components to provide access to the application based on the group membership of the users.

Acknowledgments

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.